diff --git a/packer/qemu/start-vm.sh b/packer/qemu/start-vm.sh index 2be6917..926b12d 100755 --- a/packer/qemu/start-vm.sh +++ b/packer/qemu/start-vm.sh @@ -3,7 +3,7 @@ set -eu export LC_ALL=C -SRC_DIR=$(dirname "$(dirname "$(readlink -f "$0")")") +SRC_DIR=$(CDPATH='' cd -- "$(dirname -- "${0:?}")" && pwd -P) TMP_DIR=$(mktemp -d) ORIGINAL_DISK=${SRC_DIR:?}/dist/qemu/wireguard.qcow2 @@ -13,7 +13,8 @@ USERDATA_YAML=${SRC_DIR:?}/qemu/http/seed/user-data USERDATA_DISK=${TMP_DIR:?}/seed.img # Remove temporary files on exit -trap 'rm -rf "${TMP_DIR:?}"; trap - EXIT; exit 0' EXIT TERM INT HUP +# shellcheck disable=SC2154 +trap 'ret="$?"; rm -rf -- "${TMP_DIR:?}"; trap - EXIT; exit "${ret:?}"' EXIT TERM INT HUP # Create a snapshot image to preserve the original image qemu-img create -b "${ORIGINAL_DISK:?}" -f qcow2 "${SNAPSHOT_DISK:?}"