From 1e27d8ed79cf72dbb999e7fb51ff0bf92a4c3383 Mon Sep 17 00:00:00 2001 From: Patrick Schleizer Date: Sat, 21 Oct 2023 14:44:02 -0400 Subject: [PATCH] improve error handling Enable `set -e` if environment variables `REPORT_TRAP_ERR` or `FAIL_TRAP_ERR` are set to `yes`. related to https://github.com/grml/grml-debootstrap/issues/224 --- chroot-script | 1 + grml-debootstrap | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/chroot-script b/chroot-script index 5cff484..6655cb3 100755 --- a/chroot-script +++ b/chroot-script @@ -11,6 +11,7 @@ # error_handler {{{ if [ "$REPORT_TRAP_ERR" = "yes" ] || [ "$FAIL_TRAP_ERR" = "yes" ]; then + set -e set -E set -o pipefail trap "error_handler" ERR diff --git a/grml-debootstrap b/grml-debootstrap index 72bc703..6ed8511 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -31,6 +31,7 @@ last bash command: $last_bash_command" } if [ "$REPORT_TRAP_ERR" = "yes" ] || [ "$FAIL_TRAP_ERR" = "yes" ]; then + set -e set -E set -o pipefail trap "error_handler" ERR @@ -2177,7 +2178,8 @@ for i in format_efi_partition prepare_vm mkfs tunefs \ preparechroot execute_pre_scripts chrootscript execute_post_scripts \ remove_configs umount_chroot grub_install umount_target fscktool ; do if stage "${i}" ; then - if "$i" ; then + "$i" + if [ $? -eq 0 ]; then stage "${i}" 'done' && rm -f "${STAGES}/${i}" else bailout 2 "$i" -- 2.1.4