diff options
author | Lyndon Brown <jnqnfe@gmail.com> | 2020-03-12 18:34:36 +0000 |
---|---|---|
committer | Raphaƫl Hertzog <hertzog@debian.org> | 2020-03-13 15:10:29 +0000 |
commit | 5a1c875cb828c96a08411208bbc0d90d940416f8 (patch) | |
tree | 459d193d1e8636470b403b3857ca7c1223855b0c | |
parent | 5e423d0851f0c42cd2c23274a8207006c69dfb0f (diff) | |
download | vyos-live-build-5a1c875cb828c96a08411208bbc0d90d940416f8.tar.gz vyos-live-build-5a1c875cb828c96a08411208bbc0d90d940416f8.zip |
exit: ensure an appropriate message is printed on unexpected exit
if a script exits due to a failure and `set -e`, we should ensure that an
error message is printed to be clear to the user that something actually
went wrong.
similarly it would be good to print a suitable message should the user
cancel with ctrl+c for instance.
Gbp-Dch: Short
-rwxr-xr-x | functions/exit.sh | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/functions/exit.sh b/functions/exit.sh index 737af29bc..9264f5db7 100755 --- a/functions/exit.sh +++ b/functions/exit.sh @@ -11,7 +11,7 @@ Exit () { - VALUE=$? + local VALUE=$1 if [ "${_DEBUG}" = "true" ] then @@ -63,8 +63,25 @@ Exit () return ${VALUE} } +Exit_exit () +{ + local VALUE=$? + if [ "${VALUE}" -ne 0 ]; then + Echo_error "An unexpected failure occurred, exiting..." + fi + Exit "${VALUE}" +} + +Exit_other () +{ + local VALUE=$? + Echo_warning "Unexpected early exit caught, attempting cleanup..." + Exit "${VALUE}" +} + Setup_clean_exit () { Echo_message "Setting up clean exit handler" - trap 'Exit' EXIT HUP INT QUIT TERM + trap 'Exit_other' HUP INT QUIT TERM + trap 'Exit_exit' EXIT } |