diff --git a/init.sh b/init.sh index 5fd117c..3cc70f1 100755 --- a/init.sh +++ b/init.sh @@ -24,10 +24,10 @@ set -o pipefail set -o errtrace # 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 +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) set +o nounset @@ -36,7 +36,7 @@ export LC_ALL=C export LANG=C # 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) export MYPATH=$(dirname $(realpath -s $0)) @@ -54,6 +54,7 @@ unset lib # ==== Basic sanity checks ==== # ============================= +# We only test prnt which is not optimal, we should do deeper tests function_exists prnt || ( echo "*** FATAL ERROR!" echo "*** Some vital functions comming from libraries are missing." @@ -64,7 +65,7 @@ function_exists prnt || ( # ==== Main Program ==== # ====================== -# Set system dependent vars +# Set system dependent vars (OS, distro and version) set_sys_vars $(uname -m) $(get_os_version) # Initializing global variables @@ -129,11 +130,11 @@ process_commandline_and_vars set_system_proxy # Reinit stage file if no resuming -if [[ $RESUME != true ]]; then - [[ -f $STAGE_FILE ]] && rm -f $STAGE_FILE +if [[ $RESUME != true ]] && [[ -f $STAGE_FILE ]]; then + rm -f $STAGE_FILE fi -# Loading modules +# Loading activated modules for mod in $MODULE_LIST; do . modules/$mod.sh done @@ -198,7 +199,10 @@ if [[ JUMP != true ]]; then done unset deps fi - precheck_$mod + # We run in a subshell to protect main environment + ( + precheck_$mod + ) echo $mod >> $tmpfile done 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 version=VER_$mod prnt I "Applying changes for $mod version ${!version}..." - $mod - echo $mod >> $STAGE_FILE # Mark as done for resuming function + # Yet again, executed in a subshell + ( + 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 done unset mod @@ -253,12 +265,15 @@ fi prnt I "That's all folks !" echo -rm -f $STAGEFILE - -if [[ $REBOOT_NEEDED==true ]]; then - prnt W "A reboot is required to apply some changes." - prnt i "Please reboot now or as soon as possible !" +if [[ -s $STAGE_FILE && $(grep " reboot" $STAGE_FILE) ]]; then + prnt W "A reboot is required to apply some changes by the following packages:" + prnt m " * $(grep ' reboot' $STAGE_FILE | \ + sed 's/ reboot//' | \ + sed ':a' -e 'N' -e '$!ba' -e 's/\n/ /g')" + prnt I "Please reboot now or as soon as possible!" echo fi + +rm -f $STAGEFILE exit 0 # EOF