From 8e7de734f4a4667ff28f96d4f6518ef3b9c13c0a Mon Sep 17 00:00:00 2001 From: whiskerz007 <2713522+whiskerz007@users.noreply.github.com> Date: Fri, 10 Apr 2020 12:38:29 +0200 Subject: [PATCH] Add function to remove new VM on failure --- install.sh | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/install.sh b/install.sh index f07ee91..be2454b 100644 --- a/install.sh +++ b/install.sh @@ -16,6 +16,7 @@ function error_exit() { local REASON="\e[97m${1:-$DEFAULT}\e[39m" local FLAG="\e[91m[ERROR] \e[93m$EXIT@$LINE" msg "$FLAG $REASON" + [ ! -z ${VMID-} ] && cleanup_vmid exit $EXIT } function info() { @@ -27,6 +28,14 @@ function msg() { local TEXT="$1" echo -e "$TEXT" } +function cleanup_vmid() { + if $(qm status $VMID &>/dev/null); then + if [ "$(qm status $VMID | awk '{print $2}')" == "running" ]; then + qm stop $VMID + fi + qm destroy $VMID + fi +} function cleanup() { popd >/dev/null rm -rf $TEMP_DIR