X-Git-Url: https://git.grml.org/?p=grml-debootstrap.git;a=blobdiff_plain;f=grml-debootstrap;h=9b8c47d62f7a2544f2530644149614433422f25f;hp=622a693c452337be48bbd546ed3b012137e70138;hb=cb7144264f65932963e9d2968e91b466eab62be2;hpb=c7c6cfd5ea3dcdfe0c2b627f8e1d698f819a79e4 diff --git a/grml-debootstrap b/grml-debootstrap index 622a693..9b8c47d 100755 --- a/grml-debootstrap +++ b/grml-debootstrap @@ -6,6 +6,38 @@ # License: This file is licensed under the GPL v2+ ################################################################################ +# error_handler {{{ +[ -n "$REPORT_TRAP_ERR" ] || REPORT_TRAP_ERR='no' +[ -n "$FAIL_TRAP_ERR" ] || FAIL_TRAP_ERR='no' + +error_handler() { + last_exit_code="$?" + last_bash_command="$BASH_COMMAND" + if [ "$REPORT_TRAP_ERR" = "yes" ]; then + echo "Unexpected non-zero exit code $last_exit_code in $BASH_SOURCE at line $BASH_LINENO detected! +last bash command: $last_bash_command" + fi + if [ ! "$FAIL_TRAP_ERR" = "yes" ]; then + return + fi + ## Check if "bailout" function is available. + ## This is not the case in chroot-script. + if command -v bailout >/dev/null 2>&1; then + bailout 1 + else + echo 'FAIL_TRAP_ERR is set to "yes", exit 1.' + exit 1 + fi +} + +if [ "$REPORT_TRAP_ERR" = "yes" ] || [ "$FAIL_TRAP_ERR" = "yes" ]; then + set -E + set -o pipefail + trap "error_handler" ERR + export -f "error_handler" +fi +# }}} + # variables {{{ PN="$(basename "$0")" if [[ -d "$(dirname "$(which "$0")")"/.git ]]; then @@ -1403,7 +1435,7 @@ chrootscript() { mount --bind /dev "$MNTPOINT"/dev mount --bind /dev/pts "$MNTPOINT"/dev/pts if [ "$DEBUG" = "true" ] ; then - chroot "$MNTPOINT" /bin/sh -x /bin/chroot-script ; RC=$? + chroot "$MNTPOINT" /bin/bash -x /bin/chroot-script ; RC=$? else chroot "$MNTPOINT" /bin/chroot-script ; RC=$? fi