diff --git a/install.sh b/install.sh index dba2ef3..bd23c8d 100644 --- a/install.sh +++ b/install.sh @@ -11,16 +11,16 @@ trap die ERR trap cleanup EXIT function error_exit() { - REASON=$1 - MSG="\e[91mERROR: \e[93m$EXIT@" - if [ -z "$REASON" ]; then - MSG="$MSG$LINE:" - REASON="Unknown failure occured." - else - MSG="$MSG`echo $(( $LINE - 1 ))`:" - fi - echo -e "$MSG \e[97m$REASON\e[39m\e[49m" - exit $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" + exit $EXIT +} +function msg() { + local TEXT="$1" + echo -e "$TEXT" } function cleanup() { popd >/dev/null @@ -46,10 +46,10 @@ else: print(int(last_vm)+1) EOF ) -echo -e "\n\n\n" \ - "********************************\n" \ - "* Getting latest HassOS Info *\n" \ - "********************************\n" +msg " + ******************************** + * Getting latest HassOS Info * + ********************************" RELEASE_EXT=vmdk.gz URL=$(cat<&/dev/null qm importdisk $VMID ${FILE%".gz"} $STORAGE ${IMPORT_OPT:-} 1>&/dev/null qm set $VMID -bootdisk sata0 -efidisk0 ${DISK0_REF},size=128K \ -sata0 ${DISK1_REF},size=6G > /dev/null -echo -e "\n\n\n" \ - "********************************\n" \ - "* Completed Successfully *\n" \ - "* New VM ID is \e[1m$VMID\e[0m *\n" \ - "********************************\n" +msg "\n\n\n + ******************************** + * Completed Successfully * + * New VM ID is \e[1m$VMID\e[0m * + ********************************"