aboutsummaryrefslogtreecommitdiff
path: root/files
diff options
context:
space:
mode:
authorAndré Erdmann <dywi@mailerd.de>2014-03-31 17:35:48 +0200
committerAndré Erdmann <dywi@mailerd.de>2014-03-31 17:35:48 +0200
commitadeb72581e0b6030af14441129059241e009a58a (patch)
tree1a8e03b68dfafa8a0c5bb9d97cc4c8197a759616 /files
parentroverlay: --log-level, --verbose (-v) args (diff)
downloadR_overlay-adeb72581e0b6030af14441129059241e009a58a.tar.gz
R_overlay-adeb72581e0b6030af14441129059241e009a58a.tar.bz2
R_overlay-adeb72581e0b6030af14441129059241e009a58a.zip
hook functions: die_cannot_run()
+ qwhich(): use "hash" instead of "which"
Diffstat (limited to 'files')
-rw-r--r--files/shlib/functions.sh16
1 files changed, 14 insertions, 2 deletions
diff --git a/files/shlib/functions.sh b/files/shlib/functions.sh
index 1603376..fb616dc 100644
--- a/files/shlib/functions.sh
+++ b/files/shlib/functions.sh
@@ -20,6 +20,7 @@
#
# core:
# @noreturn die ( [message], [exit_code] ), raises exit()
+# @noreturn die_cannot_run ( [reason] ), raises die()
# @noreturn OUT_OF_BOUNDS(), raises die()
# int run_command ( *cmdv )
# int run_command_logged ( *cmdv )
@@ -133,8 +134,11 @@ readonly IFS_NEWLINE='
: ${DEVNULL:=/dev/null}
readonly DEVNULL
+readonly EX_OK=0
readonly EX_ERR=2
readonly EX_ARG_ERR=5
+# EX_CANNOT_RUN: configurable
+EX_CANNOT_RUN=${EX_OK}
readonly EX_GIT_ERR=30
readonly EX_GIT_ADD_ERR=35
@@ -193,6 +197,14 @@ die() {
exit "${2:-${EX_ERR?}}"
}
+# @noreturn die_cannot_run ( [reason] ), raises die (**EX_CANNOT_RUN)
+#
+# Lets the script die due to missing preconditions.
+#
+die_cannot_run() {
+ die "${1:-cannot run.}" "${EX_CANNOT_RUN}"
+}
+
# @noreturn OUT_OF_BOUNDS(), raises die (**EX_ARG_ERR)
#
# Catches non-zero shift return and calls die().
@@ -302,11 +314,11 @@ list_has() {
# int qwhich ( *command )
#
-# Returns true if 'which' finds all listed commands, else false.
+# Returns true if all listed commands could be found, else false.
#
qwhich() {
while [ $# -gt 0 ]; do
- which "${1}" 1>>${DEVNULL} 2>>${DEVNULL} || return 1
+ hash "${1}" 1>>${DEVNULL} 2>>${DEVNULL} || return 1
shift
done
return 0