2022-04-28 22:09:23 +00:00
|
|
|
__CHECK_DEPENDENCIES() {
|
2024-02-06 21:06:44 +00:00
|
|
|
local DEP ERRORS=0
|
|
|
|
local SCWRYPTS_LOG_LEVEL=1
|
2023-08-24 23:09:30 +00:00
|
|
|
[ ! $E ] && E=ERROR
|
2022-04-28 22:09:23 +00:00
|
|
|
|
2023-02-22 01:44:27 +00:00
|
|
|
DEPENDENCIES=($(echo $DEPENDENCIES | sed 's/ \+/\n/g' | sort -u))
|
|
|
|
|
2024-02-06 21:06:44 +00:00
|
|
|
for DEP in ${DEPENDENCIES[@]}; do __CHECK_DEPENDENCY $DEP || ((ERRORS+=1)); done
|
|
|
|
__CHECK_COREUTILS || ((ERRORS+=$?))
|
2022-04-28 22:09:23 +00:00
|
|
|
|
2024-02-06 21:06:44 +00:00
|
|
|
return $ERRORS
|
2022-04-28 22:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
__CHECK_DEPENDENCY() {
|
|
|
|
local DEPENDENCY="$1"
|
|
|
|
[ ! $DEPENDENCY ] && return 1
|
|
|
|
command -v $DEPENDENCY >/dev/null 2>&1 || {
|
2023-08-24 23:09:30 +00:00
|
|
|
$E "application '$1' "$([[ $OPTIONAL -eq 1 ]] && echo preferred || echo required)" but not available on PATH $(__CREDITS $1)"
|
2022-04-28 22:09:23 +00:00
|
|
|
return 1
|
|
|
|
}
|
2023-11-22 22:54:16 +00:00
|
|
|
|
|
|
|
[[ $DEPENDENCY =~ ^yq$ ]] && {
|
|
|
|
yq --version | grep -q mikefarah \
|
|
|
|
|| WARNING 'detected kislyuk/yq but mikefarah/yq is preferred (compatibility may vary)'
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0
|
2022-04-28 22:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
__CHECK_COREUTILS() {
|
2022-08-09 23:42:31 +00:00
|
|
|
local COREUTILS=(awk find grep sed readlink)
|
2022-04-28 22:09:23 +00:00
|
|
|
local MISSING_DEPENDENCY_COUNT=0
|
|
|
|
local NON_GNU_DEPENDENCY_COUNT=0
|
|
|
|
|
|
|
|
local UTIL
|
|
|
|
for UTIL in $(echo $COREUTILS)
|
|
|
|
do
|
|
|
|
__CHECK_DEPENDENCY $UTIL || { ((MISSING_DEPENDENCY_COUNT+=1)); continue; }
|
|
|
|
|
2024-03-12 02:12:56 +00:00
|
|
|
$UTIL --version 2>&1 | grep 'GNU' | grep -qv 'BSD' || {
|
2023-02-22 01:44:27 +00:00
|
|
|
WARNING "non-GNU version of $UTIL detected"
|
2022-04-28 22:09:23 +00:00
|
|
|
((NON_GNU_DEPENDENCY_COUNT+=1))
|
|
|
|
}
|
|
|
|
done
|
|
|
|
|
|
|
|
[[ $NON_GNU_DEPENDENCY_COUNT -gt 0 ]] && {
|
2023-11-22 22:54:16 +00:00
|
|
|
WARNING 'scripts rely on GNU coreutils; compatibility may vary'
|
2023-02-22 01:44:27 +00:00
|
|
|
IS_MACOS && REMINDER 'GNU coreutils can be installed and linked through Homebrew'
|
2022-04-28 22:09:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $MISSING_DEPENDENCY_COUNT
|
|
|
|
}
|