From ec4474220e4d22ce0b77b55f5f7e012ce141b9d3 Mon Sep 17 00:00:00 2001
From: tteckster <tteckster@gmail.com>
Date: Mon, 25 Apr 2022 10:42:28 -0400
Subject: [PATCH] Update meshcentral-v3.sh

---
 ct/meshcentral-v3.sh | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)

diff --git a/ct/meshcentral-v3.sh b/ct/meshcentral-v3.sh
index e813645bc..6eb9b4f22 100644
--- a/ct/meshcentral-v3.sh
+++ b/ct/meshcentral-v3.sh
@@ -1,7 +1,4 @@
-#!/usr/bin/env bash -ex
-set -euo pipefail
-shopt -s inherit_errexit nullglob
-
+#!/usr/bin/env bash
 NEXTID=$(pvesh get /cluster/nextid)
 INTEGER='^[0-9]+$'
 YW=`echo "\033[33m"`
@@ -16,6 +13,23 @@ HOLD="-"
 CM="${GN}✓${CL}"
 APP="MeshCentral"
 NSAPP=$(echo ${APP,,} | tr -d ' ')
+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
+
+function error_exit() {
+  trap - ERR
+  local reason="Unknown failure occured."
+  local msg="${1:-$reason}"
+  local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
+  echo -e "$flag $msg" 1>&2
+  exit $EXIT
+}
+
 while true; do
     read -p "This will create a New ${APP} LXC. Proceed(y/n)?" yn
     case $yn in