diff options
author | Aaron Ball <nullspoon@oper.io> | 2018-03-05 08:28:02 -0700 |
---|---|---|
committer | Aaron Ball <nullspoon@oper.io> | 2018-03-05 08:28:02 -0700 |
commit | 2486eebf22552688d6eb796df73a69724f5c49f0 (patch) | |
tree | 0a51af8067e01cc161d6a7a0b478534ce9e60167 | |
parent | e2d16d96663de4b22a61da8ad3e70ee540d4fc57 (diff) | |
parent | b676abb0f0faf699f83146e423cb49ec87146196 (diff) | |
download | pkgself-2486eebf22552688d6eb796df73a69724f5c49f0.tar.gz pkgself-2486eebf22552688d6eb796df73a69724f5c49f0.tar.xz |
Merge branch 'libensure'
-rw-r--r-- | libinstall/ensure.sh | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/libinstall/ensure.sh b/libinstall/ensure.sh new file mode 100644 index 0000000..f703087 --- /dev/null +++ b/libinstall/ensure.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +export ERRNO_ENSURE=0 + +# ensures::set: +# @ref Reference to the variable to be checked +# @msg Message to print if variable is unset +# +# Ensures that the specified variable is set. If varible is unset, the +# specified variable description is printed out. +# +# Note: An empty variable will return as 'set'. +# +# Returns 0 when set and 1 when unset +ensure::set() { + local _ref="${1:-}" + local _msg="${2:-}" + if [ -z "${!_ref+x}" ]; then + printf -- "Error: Required variable '%s' unset.\n" "${_ref}" >&2 + printf -- " %s: %s\n" "${_ref}" "${_msg}" >&2 + ERRNO_ENSURE=1 + return 1 + fi + return 0 +} |