#! /bin/sh
# preinst script for s6-66-init

set -e
_PATH_="/tmp/build"
SERVICE_SYSADM="/etc/66/service"
SEED_SYSADM="/etc/66/seed"
oblibs_tag="0.2.1.0"
ss_tag="0.7.0.0-preprod"
ss_tools_tag="0.1.0.1"
boot_66serv_tag="3.0.0"

if [ "$(id -u)" -gt 0 ]; then
    echo "Please run as root"
    exit 1
fi
auto_dir(){
    p="${1}"
    mkdir -p ${p} 1>/dev/null 2>&1 || exit 1
    unset p
}

echo "updating 66 init.conf"
echo "## Updated by package s6-66-init
VERBOSITY=0
LIVE=/run/66
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/lib/execline/bin:/usr/lib/execline/bin:/usr/libexec
TREE=boot
RCINIT=/etc/66/rc.init
RCSHUTDOWN=/etc/66/rc.shutdown
RCSHUTDOWNFINAL=/etc/66/rc.shutdown.final
UMASK=0022
RESCAN=0
CONTAINER=0
RCINIT_CONTAINER=/etc/66/rc.init.container
CATCHLOG=1
" > /etc/66/init.conf

echo "making good environment path file"
auto_dir "/etc/66/environment/"
echo "PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/lib/execline/bin:/usr/lib/execline/bin:/usr/libexec" > /etc/66/environment/path

echo "make a seed file for tree boot"
auto_dir "${SEED_SYSADM}"
echo "allow = root
groups = boot
" > ${SEED_SYSADM}/boot

echo "Associating service boot@system to tree called boot"
66 -t boot enable boot@system

echo "Associating tree boot to group boot"
66 tree admin -o groups=boot boot

echo "Applying OOTB configurartion to service boot@system"
66 reconfigure boot@system

