diff --git a/modules/functions.sh b/modules/functions.sh index 8ce2fc9..8931232 100644 --- a/modules/functions.sh +++ b/modules/functions.sh @@ -3,20 +3,36 @@ source colors.sh check_dependencies() { - return 0 + # Usage: check_dependencies 7z unrar curl ... + local dependencies=() + + for dependency in "$@"; do + if ! command -v "$dependency" >/dev/null; then + dependencies+=("$dependency") + fi + done + + if (( "${#dependencies[@]}" > 0 )); then + log_err "Missing dependencies" "${dependencies[@]}" + return 1 + fi } -log_info() { +log() { + # Usage: log "NOTICE|ERROR|WARN" this is a log message ... local caller="${0##*/}" - echo -e "$caller: INFO: $*" >&2 -} + local level="$1"; shift + local color -log_notice() { - local caller="${0##*/}" - echo -e "$caller: ${GREEN}NOTICE: $*${RESET}" >&2 -} + case "$level" in + NOTICE) color="$GREEN" ;; + WARN) color="$YELLOW" ;; + ERROR) color="$RED" ;; -log_err() { - local caller="${0##*/}" - echo -e "$caller: ${RED}ERROR: $*${RESET}" >&2 + # No color for these levels. + INFO) color="" ;; + *) color="" ;; + esac + + echo -e "$caller: ${color}[$level]: $*${RESET}" >&2 }