lib/common.sh: Adjust to work properly with `set -u`.
This commit is contained in:
parent
fb40b58772
commit
747e8ffc8d
|
@ -1,4 +1,5 @@
|
||||||
#!/hint/bash
|
#!/hint/bash
|
||||||
|
# This may be included with or without `set -euE`
|
||||||
|
|
||||||
# License: Unspecified
|
# License: Unspecified
|
||||||
|
|
||||||
|
@ -8,7 +9,7 @@ export LANG=C
|
||||||
shopt -s extglob
|
shopt -s extglob
|
||||||
|
|
||||||
# check if messages are to be printed using color
|
# check if messages are to be printed using color
|
||||||
unset ALL_OFF BOLD BLUE GREEN RED YELLOW
|
declare ALL_OFF='' BOLD='' BLUE='' GREEN='' RED='' YELLOW=''
|
||||||
if [[ -t 2 ]]; then
|
if [[ -t 2 ]]; then
|
||||||
# prefer terminal safe colored and bold text when tput is supported
|
# prefer terminal safe colored and bold text when tput is supported
|
||||||
if tput setaf 0 &>/dev/null; then
|
if tput setaf 0 &>/dev/null; then
|
||||||
|
@ -65,14 +66,14 @@ stat_done() {
|
||||||
|
|
||||||
_setup_workdir=false
|
_setup_workdir=false
|
||||||
setup_workdir() {
|
setup_workdir() {
|
||||||
[[ -z $WORKDIR ]] && WORKDIR=$(mktemp -d --tmpdir "${0##*/}.XXXXXXXXXX")
|
[[ -z ${WORKDIR:-} ]] && WORKDIR=$(mktemp -d --tmpdir "${0##*/}.XXXXXXXXXX")
|
||||||
_setup_workdir=true
|
_setup_workdir=true
|
||||||
trap 'trap_abort' INT QUIT TERM HUP
|
trap 'trap_abort' INT QUIT TERM HUP
|
||||||
trap 'trap_exit' EXIT
|
trap 'trap_exit' EXIT
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
if [[ -n $WORKDIR ]] && $_setup_workdir; then
|
if [[ -n ${WORKDIR:-} ]] && $_setup_workdir; then
|
||||||
rm -rf "$WORKDIR"
|
rm -rf "$WORKDIR"
|
||||||
fi
|
fi
|
||||||
exit ${1:-0}
|
exit ${1:-0}
|
||||||
|
|
Loading…
Reference in New Issue