summaryrefslogtreecommitdiff
path: root/libinstall/ensure.sh
blob: f703087b54c31996c2f9e3d6b0cb8a94b2a9bcff (plain)
    1 #!/usr/bin/env bash
    2 export ERRNO_ENSURE=0
    3 
    4 # ensures::set:
    5 # @ref Reference to the variable to be checked
    6 # @msg Message to print if variable is unset
    7 #
    8 # Ensures that the specified variable is set. If varible is unset, the
    9 # specified variable description is printed out.
   10 #
   11 # Note: An empty variable will return as 'set'.
   12 #
   13 # Returns 0 when set and 1 when unset
   14 ensure::set() {
   15   local _ref="${1:-}"
   16   local _msg="${2:-}"
   17   if [ -z "${!_ref+x}" ]; then
   18     printf -- "Error: Required variable '%s' unset.\n" "${_ref}" >&2
   19     printf -- "       %s: %s\n" "${_ref}" "${_msg}" >&2
   20     ERRNO_ENSURE=1
   21     return 1
   22   fi
   23   return 0
   24 }

Generated by cgit