From d7e0646875ca9191bcefe278a17867a4fc80825b Mon Sep 17 00:00:00 2001 From: root Date: Fri, 25 Jun 2021 12:17:55 +0200 Subject: [PATCH] fixed some issue on error treatment, some typo --- init.sh | 34 +++++++++++++++++++++------------- lib/aaa_errors.sh | 11 ++++++++--- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/init.sh b/init.sh index c6a0f9d..cac4ad0 100755 --- a/init.sh +++ b/init.sh @@ -108,6 +108,12 @@ get_mod_name() # ==== Main Program ==== # ====================== +# Initializing global variables +export CHECK_ONLY=false +export JUMP=false +export KEEPGOING=false +export RESUME=false + # Processing command line options want_module=false for opt in $@; do @@ -123,9 +129,10 @@ for opt in $@; do ;; "-m"|"--module") want_module=true + prnt W "Une liste de modules manuelle sera utilisé. $want_module" ;; "-c"|"--check-only") - export CHECKONLY=true + export CHECK_ONLY=true ;; "-j"|"--jump") export JUMP=true @@ -176,7 +183,8 @@ prnt I "Création du répertoire d'accueil du fichier log..." # Log toutes les sortie dans le fichier de log exec 3>&1 4>&2 trap 'exec 2>&4 1>&3' 0 1 2 3 -exec 1>$LOGFILE 2>&1 +exec > >(tee -a $LOGFILE) +exec 2> >(tee -a $LOGFILE >&2) # Récupère la configuration prnt I "Chargement de la configuration..." @@ -199,26 +207,26 @@ if [[ $want_module == true ]]; then fi # Check unconsistant parameters -[[ $CHECK_ONLY == true ]] && [[ $JUMP == true ]] && ( - prnt E "Les options --check-only et --jump s'excluent mutuellement !" - die 1 --force -) -[[ $KEEPGOING == true ]] && [[ $CHECKONLY == true ]] && ( - prnt E "Les options --keep-going et --check-only sont incompatible !" - die 1 --force -) +if [[ $CHECK_ONLY == true ]]; then + [[ $JUMP == true ]] && ( + prnt E "Les options --check-only et --jump s'excluent mutuellement !" + die 1 --force + ) + [[ $KEEPGOING == true ]] && ( + prnt E "Les options --keep-going et --check-only sont incompatible !" + die 1 --force + ) +fi if [[ $RESUME == true ]]; then [[ $CHECK_ONLY == true ]] && ( prnt E "La reprise n'a pas de sens avec --check-only." die 1 --force ) [[ $MANUAL_MODULE_LIST ]] && ( - prnt E "Le mode reprise ne fonctionne pas avec une liste de \ - modules passé manuellement." + prnt E "Le mode reprise ne fonctionne pas avec une liste de modules passé manuellement." die 1 --force ) fi - prnt I "That's all folks !" echo "Après vérification des logs, vous devriez redémarrer la machine..." diff --git a/lib/aaa_errors.sh b/lib/aaa_errors.sh index 8c2a80d..59aabb3 100644 --- a/lib/aaa_errors.sh +++ b/lib/aaa_errors.sh @@ -4,14 +4,19 @@ function die() { local errorcode=$1 - [[ $2 == "--force" ]] && unset KEEPGOING - if [[ $KEEPGOING ]]; then + # Don't trigger the ERR signal as we already managed the error + trap - ERR + + if [[ "$KEEPGOING" != "true" || "$2" == "--force" ]]; then prnt E "Sortie prématuré avec erreur (code #$errorcode)." exit $errorcode else prnt W "On continue malgrés l'erreur #$errorcode." fi + + # Put the trigger back (only executed with --keepgoing) + trap "error ${LINENO}" ERR } export -f die @@ -40,7 +45,7 @@ function error() # Print error header prnt E "${BIWhite}*** ${BIRed}Une erreur fatale est intervenue, \ - le script va s'arrêter immédiatement !$DEFAULTCOL" +le script va s'arrêter immédiatement !$DEFAULTCOL" # Print backtrace backtrace 2