From 6b03c3add554f290612bcd1f52a6ee46721a6df5 Mon Sep 17 00:00:00 2001 From: Georg Lauterbach <44545919+aendeavor@users.noreply.github.com> Date: Tue, 22 Dec 2020 18:09:03 +0100 Subject: [PATCH] adjusting Bash failure-construct & SCRIPT variable usage --- CONTRIBUTING.md | 4 ++-- setup.sh | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e6375b92..ef1b6252 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -125,12 +125,12 @@ A construct to trace error in your scripts looks like this. Remember: Remove `se set -xeuEo pipefail trap '__log_err ${FUNCNAME[0]:-"?"} ${_:-"?"} ${LINENO:-"?"} ${?:-"?"}' ERR -SCRIPT='NAME OF THIS SCRIPT' +SCRIPT='name_of_this_script.sh' function __log_err { printf "\n––– \e[1m\e[31mUNCHECKED ERROR\e[0m\n%s\n%s\n%s\n%s\n\n" \ - " – script = ${SCRIPT:-'unknown'}" \ + " – script = ${SCRIPT:-${0}}" \ " – function = ${1} / ${2}" \ " – line = ${3}" \ " – exit code = ${4}" 1>&2 diff --git a/setup.sh b/setup.sh index 74ce1a7d..a12659d2 100755 --- a/setup.sh +++ b/setup.sh @@ -3,7 +3,7 @@ # Wrapper for various setup scripts # included in docker-mailserver -SCRIPT='SETUP' +SCRIPT='setup.sh' set -euEo pipefail trap '__log_err ${FUNCNAME[0]:-"?"} ${_:-"?"} ${LINENO:-"?"} ${?:-"?"}' ERR @@ -17,10 +17,10 @@ function __log_err EXIT_CODE="${4}" printf "\n––– \e[1m\e[31mUNCHECKED ERROR\e[0m\n%s\n%s\n%s\n%s\n\n" \ - " – script = ${SCRIPT,,}.sh" \ + " – script = ${SCRIPT:-${0}}" \ " – function = ${FUNC_NAME}" \ " – line = ${LINE}" \ - " – exit code = ${EXIT_CODE}" + " – exit code = ${EXIT_CODE}" 1>&2 } function _unset_vars @@ -34,7 +34,7 @@ function _get_current_directory { if dirname "$(readlink -f "${0}")" &>/dev/null then - CDIR="$(cd "$(dirname "$(readlink -f "${0}")")" && pwd)" + CDIR="$(dirname "$(readlink -f "${0}")")" elif realpath -e -L "${0}" &>/dev/null then CDIR="$(realpath -e -L "${0}")" @@ -101,7 +101,7 @@ function _inspect function _usage { - echo "${SCRIPT,,}.sh Bootstrapping Script + echo "${SCRIPT:-${0}} Bootstrapping Script Usage: ${0} [-i IMAGE_NAME] [-c CONTAINER_NAME] [args]