From 97dd52a47c9ab84485b5bf54d115e22c8658758b Mon Sep 17 00:00:00 2001 From: tteckster Date: Tue, 22 Feb 2022 19:21:14 -0500 Subject: [PATCH] Update node-red-install.sh --- unpriv/node-red-install.sh | 46 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/unpriv/node-red-install.sh b/unpriv/node-red-install.sh index 18193e2a..f9794196 100644 --- a/unpriv/node-red-install.sh +++ b/unpriv/node-red-install.sh @@ -1,4 +1,50 @@ #!/usr/bin/env bash +set -o errexit +set -o errtrace +set -o nounset +set -o pipefail +shopt -s expand_aliases +alias die='EXIT=$? LINE=$LINENO error_exit' +trap die ERR +trap cleanup EXIT + +function error_exit() { + trap - ERR + local DEFAULT='Unknown failure occured.' + local REASON="\e[97m${1:-$DEFAULT}\e[39m" + local FLAG="\e[91m[ERROR] \e[93m$EXIT@$LINE" + msg "$FLAG $REASON" + [ ! -z ${CTID-} ] && cleanup_ctid + exit $EXIT +} +function warn() { + local REASON="\e[97m$1\e[39m" + local FLAG="\e[93m[WARNING]\e[39m" + msg "$FLAG $REASON" +} +function info() { + local REASON="$1" + local FLAG="\e[36m[INFO]\e[39m" + msg "$FLAG $REASON" +} +function msg() { + local TEXT="$1" + echo -e "$TEXT" +} +function cleanup_ctid() { + if $(pct status $CTID &>/dev/null); then + if [ "$(pct status $CTID | awk '{print $2}')" == "running" ]; then + pct stop $CTID + fi + pct destroy $CTID + elif [ "$(pvesm list $STORAGE --vmid $CTID)" != "" ]; then + pvesm free $ROOTFS + fi +} +function cleanup() { + popd >/dev/null + rm -rf $TEMP_DIR +} CROSS='\033[1;31m\xE2\x9D\x8C\033[0m' RD=`echo "\033[01;31m"` BL=`echo "\033[36m"`