corrected KEEPGOING support, corrected noerror behaviour
This commit is contained in:
@@ -20,6 +20,8 @@ function die()
|
||||
|
||||
if [[ "$KEEPGOING" != "true" ]] || [[ "$2" == "--force" ]]; then
|
||||
prnt E "Sortie prématuré avec erreur (code #$errorcode)."
|
||||
# We remove KEEPGOING in case of --force so error() behave correctly
|
||||
export KEEPGOING=false
|
||||
exit $errorcode
|
||||
else
|
||||
prnt W "On continue malgrés l'erreur #$errorcode."
|
||||
@@ -61,7 +63,17 @@ function error()
|
||||
fi
|
||||
}
|
||||
# Trigger error function on error
|
||||
trap "error ${LINENO}; backtrace; exit 255" ERR
|
||||
trap "error ${LINENO}; backtrace; err_exit" ERR
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# Exit program in case of error unless keepgoing is set to true
|
||||
function err_exit
|
||||
{
|
||||
if [[ $KEEPGOING != true ]]; then
|
||||
exit 255
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
@@ -90,7 +102,7 @@ noerror()
|
||||
local noout=true
|
||||
shift
|
||||
fi
|
||||
|
||||
|
||||
set +o errexit
|
||||
trap - ERR
|
||||
|
||||
@@ -100,12 +112,12 @@ noerror()
|
||||
$@
|
||||
fi
|
||||
local code=$?
|
||||
echo $code
|
||||
|
||||
trap "error ${LINENO}" ERR
|
||||
set -o errexit
|
||||
|
||||
echo $code
|
||||
}
|
||||
export -f noerror
|
||||
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
@@ -120,5 +132,6 @@ check_root()
|
||||
die 4 --force
|
||||
fi
|
||||
}
|
||||
export -f check_root
|
||||
|
||||
# EOF
|
||||
|
||||
Reference in New Issue
Block a user