# Common error handling setup # set -euo pipefail SCRIPT="${BASH_SOURCE[-1]}" # last sourced = the actual script file ERROR_FILE="$SCRIPT.error" DONE_FILE="$SCRIPT.done" # Reset markers rm -f "$ERROR_FILE" "$DONE_FILE" error_handler() { local exit_code=$? local line_no=$1 local cmd="$2" { echo "EXIT_CODE=$exit_code" echo "LINE=$line_no" echo "COMMAND=$cmd" } > "$ERROR_FILE" # If we are inside a sourced script, don't kill the shell if [[ "${BASH_SOURCE[0]}" != "$0" ]]; then return $exit_code else exit $exit_code fi } trap 'error_handler ${LINENO} "$BASH_COMMAND"' ERR mark_done() { touch "$DONE_FILE" }