armbian-build/lib/functions/logging/traps.sh

36 lines
981 B
Bash
Raw Normal View History

#!/usr/bin/env bash
2022-10-03 02:52:43 +00:00
# exit_with_error <message> <highlight>
#
# a way to terminate build process
# with verbose error message
#
2022-10-08 11:17:30 +00:00
exit_with_error() {
2022-10-03 02:52:43 +00:00
local _file
local _line=${BASH_LINENO[0]}
local _function=${FUNCNAME[1]}
local _description=$1
local _highlight=$2
_file=$(basename "${BASH_SOURCE[1]}")
local stacktrace="$(get_extension_hook_stracktrace "${BASH_SOURCE[*]}" "${BASH_LINENO[*]}")"
display_alert "ERROR in function $_function" "$stacktrace" "err"
display_alert "$_description" "$_highlight" "err"
display_alert "Process terminated" "" "info"
if [[ "${ERROR_DEBUG_SHELL}" == "yes" ]]; then
display_alert "MOUNT" "${MOUNT}" "err"
display_alert "SDCARD" "${SDCARD}" "err"
display_alert "Here's a shell." "debug it" "err"
bash < /dev/tty || true
fi
# TODO: execute run_after_build here?
overlayfs_wrapper "cleanup"
# unlock loop device access in case of starvation
2022-10-08 11:17:30 +00:00
exec {FD}> /var/lock/armbian-debootstrap-losetup
2022-10-03 02:52:43 +00:00
flock -u "${FD}"
exit 255
}