-
Eric Vidal authoredEric Vidal authored
customizeChroot 5.96 KiB
#!@BINDIR@/bash
# Copyright (c) 2015-2021 Eric Vidal <eric@obarun.org>
# All rights reserved.
#
# This file is part of Obarun. It is subject to the license terms in
# the LICENSE file found in the top-level directory of this
# distribution.
# This file may not be copied, modified, propagated, or distributed
# except according to the terms contained in the LICENSE file.
out_progress() {
oblog "[ $1 ]"
oblog " "
}
sourcing(){
local list
for list in /tmp/obarun-install-tmp/install.conf /usr/lib/obarun/util.sh; do
if [[ -f "${list}" ]]; then
source "${list}"
else
oblog -f "Missing file : ${list}"
exit
fi
done
unset list
}
sourcing
custo_once() {
local _tmp cmd
cmd="${1}"
_tmp="/tmp/obarun-install-tmp"
if [[ ! -d $_tmp ]]; then
mkdir -p -m0755 $_tmp || die "Impossible to create $_tmp"
fi
if [[ ! -e $_tmp/customize.${cmd} ]]; then
"${cmd}" || die "Cannot execute $_"
touch $_tmp/customize.${cmd}
else
return
fi
unset _tmp
}
############################## only modifie this script after this line ############################
check_tree(){
local tree="${1}"
if ! [[ -d /var/lib/66/system/"${tree}" ]]; then
return 1 ;
else
oblog "Tree ${tree} already exists"
return 0 ;
fi
}
create_log_user(){
oblog "add ${NEWUSER} to log group"
gpasswd -a "$NEWUSER" log
}
config_tree_boot(){
if ! check_tree "boot"; then
oblog "Create [boot] tree"
out_progress "Starting ..."
66-tree -zv3 -n boot || die "unable to create [boot] tree"
out_progress "Done"
fi
}
config_enable_boot(){
oblog "Enable (boot@system) service to [boot] tree"
out_progress "Starting ..."
#sleep 2
66-enable -zv3 -t boot -F boot@system || die "unable to enable boot@system to [boot] tree"
out_progress "Done"
#sleep 1
oblog "Configure (boot@system) service"
out_progress "Starting ..."
66-env -t boot -r "HOSTNAME=!${HOSTNAME}" -r "KEYMAP=!${KEYMAP}" -r "TZ=${ZONE}/${SUBZONE}" boot@system || die "unable to configure boot@system service"
oblog "Apply change to the (boot@system) service"
out_progress "Starting ..."
66-enable -zv3 -t boot -F boot@system || die "unable to apply boot changes"
out_progress "Done"
}
config_tree_root(){
if ! check_tree "root"; then
oblog "Create and enable [root] tree"
out_progress "Starting ..."
66-tree -zv3 -En root || die "unable to create [root] tree"
out_progress "Done"
fi
}
config_enable_root(){
oblog "Enable (dbus) (networkmanager) (sddm) (consolekit) services to [root] tree"
out_progress "Starting ..."
#sleep 2
66-enable -zv3 -t root dbus networkmanager sddm consolekit || die "unable to enable (dbus) (networkmanager) (sddm) (consolekit) to [root] tree"
out_progress "Done"
}
config_tree_boot_user(){
if ! check_tree "${NEWUSER}-session"; then
oblog "Create and enable [${NEWUSER}-session] tree"
out_progress "Starting ..."
66-tree -zv3 -nE ${NEWUSER}-session || die "unable to create [${NEWUSER}-session] tree"
out_progress "Done"
fi
}
config_enable_boot_user(){
oblog "Configure and enable (boot-user@${NEWUSER}) service to [${NEWUSER}-session] tree"
out_progress "Starting ..."
#sleep 2
66-enable -zv3 -t ${NEWUSER}-session -F boot-user@${NEWUSER} || die "unable to enable (boot-user@${NEWUSER}) service to [${NEWUSER}-session] tree"
out_progress "Done"
#sleep 1
oblog "Configure (boot-user@${NEWUSER}) service"
out_progress "Starting ..."
66-env -t ${NEWUSER}-session -r "DESKTOP_CMDLINE=!startplasma-x11" boot-user@${NEWUSER} || die "unable to set DESKTOP_CMDLINE"
out_progress "Done"
oblog "Apply change to the (boot-user@{NEWUSER}) service"
out_progress "Starting ..."
66-enable -zv3 -t ${NEWUSER}-session -F boot-user@${NEWUSER} || die "unable to apply (${NEWUSER}-session) changes"
out_progress "Done"
}
config_tree_system(){
if ! check_tree "system"; then
oblog "Create and enable [system] tree"
out_progress "Starting ..."
66-tree -zv3 -ncE system || die "unable to create [system] tree"
out_progress "Done"
fi
}
config_enable_system(){
oblog "Enable (sshd) service to [system] tree"
out_progress "Starting ..."
#sleep 2
66-enable -zv3 -t system sshd || die "unable to enable (sshd) to [root] tree"
out_progress "Done"
}
config_tree_base_user(){
oblog "For ${NEWUSER}: Create and enable [${NEWUSER}] tree. Set it as the current user tree"
out_progress "Starting ..."
su "${NEWUSER}" -c "if ! s6-test -d /home/${NEWUSER}/.66/system/${NEWUSER}; then \
66-tree -zv3 -Ecn ${NEWUSER} ; \
fi" || die "unable to create base tree"
out_progress "Done"
}
config_enable_base_user(){
oblog "Enable (xdg-user-dirs) (dbus-session@${NEWUSER}) services to [${NEWUSER}] tree"
out_progress "Starting ..."
#sleep 2
su "${NEWUSER}" -c "66-enable -zv3 xdg-user-dirs dbus-session@${NEWUSER}"
out_progress "Done"
}
config_xsession(){
cat << EOF > /home/${NEWUSER}/.xsession
list=( \$(ls -A1 /home/${NEWUSER}/.66/conf/svscan@${NEWUSER}) )
for i in \${list[@]};do
var=( \$(</home/${NEWUSER}/.66/conf/svscan@${NEWUSER}/\${i}) )
for j in \${var[@]}; do
export \${j}
done
done
66-all up
EOF
chown ${NEWUSER}:users /home/${NEWUSER}/.xsession
chmod +x /home/${NEWUSER}/.xsession
}
custo_once create_log_user
custo_once config_tree_boot
custo_once config_enable_boot
custo_once config_tree_root
custo_once config_enable_root
custo_once config_tree_boot_user
custo_once config_enable_boot_user
custo_once config_tree_system
custo_once config_enable_system
custo_once config_tree_base_user
custo_once config_enable_base_user
custo_once config_xsession
oblog "Configuration completed"