From 099dd6648832318c714470932d84c1b368d8a616 Mon Sep 17 00:00:00 2001 From: whiskerz007 <2713522+whiskerz007@users.noreply.github.com> Date: Fri, 20 Mar 2020 13:16:38 +0100 Subject: [PATCH] Set additional bash options and group together --- install.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index 2d7c12e..912340c 100644 --- a/install.sh +++ b/install.sh @@ -1,8 +1,15 @@ #!/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 alias die='EXIT=$? LINE=$LINENO error_exit' trap die ERR +trap cleanup EXIT + function error_exit() { REASON=$1 MSG="\e[91mERROR: \e[93m$EXIT@" @@ -19,7 +26,6 @@ function cleanup() { popd >/dev/null rm -rf $TMP } -trap cleanup EXIT TMP=`mktemp -d` pushd $TMP >/dev/null