function for checking dependencies added, log functions condensed into a single function
This commit is contained in:
parent
085b8ea8bb
commit
3c1060a84f
1 changed files with 27 additions and 11 deletions
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue