init.sh: protect environment of the script through module isolation, show what modules need reboots if any

This commit is contained in:
levasseur
2022-02-21 15:39:28 +01:00
parent 0f7acc72ec
commit 7f2f30844a

45
init.sh
View File

@@ -24,10 +24,10 @@ set -o pipefail
set -o errtrace set -o errtrace
# set -e : exit the script if any statement returns a non-true return value # set -e : exit the script if any statement returns a non-true return value
# exeption to that will need a special function call # This is overloaded by aaa_error.sh lib (but usefull for initialisation)
set -o errexit set -o errexit
# set +u: allow undeclared variables because configuration files don't need # set +u: allow undeclared variables because our configuration files don't need
# to be complete (even if it's bad practice) # to be complete (even if it's bad practice)
set +o nounset set +o nounset
@@ -36,7 +36,7 @@ export LC_ALL=C
export LANG=C export LANG=C
# Version of init # Version of init
export VERSION="0.99.16" export VERSION="0.99.17"
# Store script's path (realpath -s resolve symlinks if init.sh is a symlink) # Store script's path (realpath -s resolve symlinks if init.sh is a symlink)
export MYPATH=$(dirname $(realpath -s $0)) export MYPATH=$(dirname $(realpath -s $0))
@@ -54,6 +54,7 @@ unset lib
# ==== Basic sanity checks ==== # ==== Basic sanity checks ====
# ============================= # =============================
# We only test prnt which is not optimal, we should do deeper tests
function_exists prnt || ( function_exists prnt || (
echo "*** FATAL ERROR!" echo "*** FATAL ERROR!"
echo "*** Some vital functions comming from libraries are missing." echo "*** Some vital functions comming from libraries are missing."
@@ -64,7 +65,7 @@ function_exists prnt || (
# ==== Main Program ==== # ==== Main Program ====
# ====================== # ======================
# Set system dependent vars # Set system dependent vars (OS, distro and version)
set_sys_vars $(uname -m) $(get_os_version) set_sys_vars $(uname -m) $(get_os_version)
# Initializing global variables # Initializing global variables
@@ -129,11 +130,11 @@ process_commandline_and_vars
set_system_proxy set_system_proxy
# Reinit stage file if no resuming # Reinit stage file if no resuming
if [[ $RESUME != true ]]; then if [[ $RESUME != true ]] && [[ -f $STAGE_FILE ]]; then
[[ -f $STAGE_FILE ]] && rm -f $STAGE_FILE rm -f $STAGE_FILE
fi fi
# Loading modules # Loading activated modules
for mod in $MODULE_LIST; do for mod in $MODULE_LIST; do
. modules/$mod.sh . modules/$mod.sh
done done
@@ -198,7 +199,10 @@ if [[ JUMP != true ]]; then
done done
unset deps unset deps
fi fi
precheck_$mod # We run in a subshell to protect main environment
(
precheck_$mod
)
echo $mod >> $tmpfile echo $mod >> $tmpfile
done done
rm -f $tmpfile rm -f $tmpfile
@@ -241,8 +245,16 @@ if [[ $key == "C" || $key == 'c' ]]; then
# We need this only if JUMP is set but doesn't matter if it's done again # We need this only if JUMP is set but doesn't matter if it's done again
version=VER_$mod version=VER_$mod
prnt I "Applying changes for $mod version ${!version}..." prnt I "Applying changes for $mod version ${!version}..."
$mod # Yet again, executed in a subshell
echo $mod >> $STAGE_FILE # Mark as done for resuming function (
export REBOOT_NEEDED=false
$mod
if [[ $REBOOT_NEEDED == true ]]; then
echo "$mod reboot" >> $STAGE_FILE # Mark as done for resuming
else
echo $mod >> $STAGE_FILE # Mark as done for resuming function
fi
)
separator separator
done done
unset mod unset mod
@@ -253,12 +265,15 @@ fi
prnt I "That's all folks !" prnt I "That's all folks !"
echo echo
rm -f $STAGEFILE if [[ -s $STAGE_FILE && $(grep " reboot" $STAGE_FILE) ]]; then
prnt W "A reboot is required to apply some changes by the following packages:"
if [[ $REBOOT_NEEDED==true ]]; then prnt m " * $(grep ' reboot' $STAGE_FILE | \
prnt W "A reboot is required to apply some changes." sed 's/ reboot//' | \
prnt i "Please reboot now or as soon as possible !" sed ':a' -e 'N' -e '$!ba' -e 's/\n/ /g')"
prnt I "Please reboot now or as soon as possible!"
echo echo
fi fi
rm -f $STAGEFILE
exit 0 exit 0
# EOF # EOF