function for checking dependencies added, log functions condensed into a single function

This commit is contained in:
sometimesuseful 2024-11-12 14:43:48 +00:00
parent 085b8ea8bb
commit 3c1060a84f

View file

@ -3,20 +3,36 @@
source colors.sh source colors.sh
check_dependencies() { 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##*/}" local caller="${0##*/}"
echo -e "$caller: INFO: $*" >&2 local level="$1"; shift
} local color
log_notice() { case "$level" in
local caller="${0##*/}" NOTICE) color="$GREEN" ;;
echo -e "$caller: ${GREEN}NOTICE: $*${RESET}" >&2 WARN) color="$YELLOW" ;;
} ERROR) color="$RED" ;;
log_err() { # No color for these levels.
local caller="${0##*/}" INFO) color="" ;;
echo -e "$caller: ${RED}ERROR: $*${RESET}" >&2 *) color="" ;;
esac
echo -e "$caller: ${color}[$level]: $*${RESET}" >&2
} }