mirror of
https://github.com/tteck/Proxmox.git
synced 2024-12-25 14:31:56 +00:00
Update haos-vm-v5.sh
add new error_handler
This commit is contained in:
parent
959cd5800e
commit
0432ea1558
@ -37,22 +37,16 @@ HOLD="-"
|
|||||||
CM="${GN}✓${CL}"
|
CM="${GN}✓${CL}"
|
||||||
CROSS="${RD}✗${CL}"
|
CROSS="${RD}✗${CL}"
|
||||||
THIN="discard=on,ssd=1,"
|
THIN="discard=on,ssd=1,"
|
||||||
set -o errexit
|
set -Eeuo pipefail
|
||||||
set -o errtrace
|
trap 'error_handler $LINENO "$BASH_COMMAND"' ERR
|
||||||
set -o nounset
|
|
||||||
set -o pipefail
|
|
||||||
shopt -s expand_aliases
|
|
||||||
alias die='EXIT=$? LINE=$LINENO error_exit'
|
|
||||||
trap die ERR
|
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
function error_exit() {
|
function error_handler() {
|
||||||
trap - ERR
|
local exit_code="$?"
|
||||||
local reason="Unknown failure occurred."
|
local line_number="$1"
|
||||||
local msg="${1:-$reason}"
|
local command="$2"
|
||||||
local flag="${RD}‼ ERROR ${CL}$EXIT@$LINE"
|
local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}"
|
||||||
echo -e "$flag $msg" 1>&2
|
echo -e "\n$error_message\n"
|
||||||
[ ! -z ${VMID-} ] && cleanup_vmid
|
cleanup_vmid
|
||||||
exit $EXIT
|
|
||||||
}
|
}
|
||||||
function cleanup_vmid() {
|
function cleanup_vmid() {
|
||||||
if qm status $VMID &>/dev/null; then
|
if qm status $VMID &>/dev/null; then
|
||||||
|
Loading…
Reference in New Issue
Block a user