summaryrefslogtreecommitdiffstats
path: root/scripts/libptxdist.sh
diff options
context:
space:
mode:
authorMichael Olbrich <m.olbrich@pengutronix.de>2018-09-20 09:16:31 +0200
committerMichael Olbrich <m.olbrich@pengutronix.de>2018-09-20 11:03:54 +0200
commitaeac3df64eb0624560b4ef49e08ef222f9a13b19 (patch)
tree1c3e59e3c44f83be0b88c6c0ac20c2b26917704b /scripts/libptxdist.sh
parente4fbf806e48a288e98485070036e0f4e09d03317 (diff)
downloadptxdist-aeac3df64eb0624560b4ef49e08ef222f9a13b19.tar.gz
ptxdist-aeac3df64eb0624560b4ef49e08ef222f9a13b19.tar.xz
ptxd_bailout: support multi-line error messages
Each argument is printed as one line. If the last argument is a number, then it is uses as exit code. Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
Diffstat (limited to 'scripts/libptxdist.sh')
-rw-r--r--scripts/libptxdist.sh26
1 files changed, 21 insertions, 5 deletions
diff --git a/scripts/libptxdist.sh b/scripts/libptxdist.sh
index 6ece4ab48..f28439961 100644
--- a/scripts/libptxdist.sh
+++ b/scripts/libptxdist.sh
@@ -740,20 +740,36 @@ ptxd_debug(){
ptxd_debug "Debugging is enabled - Turn off with PTX_DEBUG=false"
+ptxd_bailout_impl() {
+ echo
+ while [ $# -gt 0 ]; do
+ if [[ $# -eq 1 && "$1" =~ ^[0-9]+$ ]]; then
+ break
+ fi
+ echo -e "${PTXDIST_LOG_PROMPT}error: ${1}"
+ shift
+ done
+ echo
+ return ${1:-1}
+}
+export -f ptxd_bailout_impl
+
#
# print out error message and exit with status 1
#
-# $1: error message
-# $2: optional exit value (1 is default)
+# $*: error messages, one line per argument
+#
+# If the last argument is a number, then it is used as exit value
+# (1 is default)
#
# ${PTXDIST_LOG_PROMPT}: to be printed before message
#
ptxd_bailout() {
- echo -e "\n${PTXDIST_LOG_PROMPT}error: $1\n" >&2
if [ -n "${PTXDIST_FD_STDERR}" -a -n "${PTXDIST_QUIET}" ]; then
- echo -e "\n${PTXDIST_LOG_PROMPT}error: $1\n" >&${PTXDIST_FD_STDERR}
+ ptxd_bailout_impl "${@}" >&${PTXDIST_FD_STDERR}
fi
- exit ${2:-1}
+ ptxd_bailout_impl "${@}" >&2
+ exit
}
export -f ptxd_bailout