Set additional bash options and group together

This commit is contained in:
whiskerz007 2020-03-20 13:16:38 +01:00
parent 3563e39bdc
commit 099dd66488
No known key found for this signature in database
GPG Key ID: A7EEAB6E1F1A6805

View File

@ -1,8 +1,15 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -o pipefail
# Setup script environment
set -o errexit #Exit immediately if a pipeline returns a non-zero status
set -o errtrace #Trap ERR from shell functions, command substitutions, and commands from subshell
set -o nounset #Treat unset variables as an error
set -o pipefail #Pipe will exit with last non-zero status if applicable
shopt -s expand_aliases shopt -s expand_aliases
alias die='EXIT=$? LINE=$LINENO error_exit' alias die='EXIT=$? LINE=$LINENO error_exit'
trap die ERR trap die ERR
trap cleanup EXIT
function error_exit() { function error_exit() {
REASON=$1 REASON=$1
MSG="\e[91mERROR: \e[93m$EXIT@" MSG="\e[91mERROR: \e[93m$EXIT@"
@ -19,7 +26,6 @@ function cleanup() {
popd >/dev/null popd >/dev/null
rm -rf $TMP rm -rf $TMP
} }
trap cleanup EXIT
TMP=`mktemp -d` TMP=`mktemp -d`
pushd $TMP >/dev/null pushd $TMP >/dev/null