notes/scripts/dependencycheck
2022-09-04 02:02:50 -07:00

37 lines
835 B
Bash
Executable file

#!/bin/bash
# Error handling
set -e
# For styling/colorizing output
txtbld=$(tput bold)
# txtblue=${txtbld}$(tput setaf 4)
# txtgreen=${txtbld}$(tput setaf 2)
txtred=${txtbld}$(tput setaf 1)
# txtyellow=${txtbld}$(tput setaf 3)
txtwhite=${txtbld}$(tput setaf 7)
# Dependency check
function dependencycheck()
{
numdependencies="$#"
dependencies=("$@")
missingdependencies=0
for ((i = 0; i < numdependencies; i++)) ;
do
if ! command -v "${dependencies[$i]}" &> /dev/null
then
echo "${txtred}dependency not met: ${dependencies[$i]}${txtwhite}"
missingdependencies=$((missingdependencies+1))
fi
done
}
#invoke function
dependencycheck "$@"
if [ $missingdependencies -gt 0 ] ; then
echo "${txtred}Please install needed dependencies${txtwhite}"
exit 1
fi