♻️ Refactored dependencychecks in scripts
This commit is contained in:
parent
eee4b7ba43
commit
5ae285d176
3 changed files with 68 additions and 71 deletions
|
|
@ -6,7 +6,6 @@ set -e
|
|||
# For styling/colorizing output
|
||||
txtbld=$(tput bold)
|
||||
txtred=${txtbld}$(tput setaf 1)
|
||||
txtgreen=${txtbld}$(tput setaf 2)
|
||||
txtwhite=${txtbld}$(tput setaf 7)
|
||||
|
||||
# Dependency check
|
||||
|
|
@ -17,8 +16,7 @@ function dependencycheck()
|
|||
missingdependencies=0
|
||||
|
||||
for ((i = 0; i < numdependencies; i++)) ; do
|
||||
if ! command -v "${dependencies[$i]}" &> /dev/null
|
||||
then
|
||||
if ! command -v "${dependencies[$i]}" &> /dev/null ; then
|
||||
echo "${txtred}dependency not met: ${dependencies[$i]}${txtwhite}"
|
||||
missingdependencies=$((missingdependencies+1))
|
||||
fi
|
||||
|
|
@ -27,11 +25,28 @@ function dependencycheck()
|
|||
if [ $missingdependencies -gt 0 ] ; then
|
||||
echo "${txtred}Please install needed dependencies${txtwhite}"
|
||||
exit 1
|
||||
#comment out if sourced
|
||||
else
|
||||
echo "${txtgreen}All dependencies are met!${txtwhite}"
|
||||
fi
|
||||
}
|
||||
|
||||
# invoke function comment out if sourced
|
||||
dependencycheck "$@"
|
||||
|
||||
# Barebones version without tput (for being sourced):
|
||||
# function dependencycheck()
|
||||
# {
|
||||
# numdependencies="$#"
|
||||
# dependencies=("$@")
|
||||
# missingdependencies=0
|
||||
|
||||
# for ((i = 0; i < numdependencies; i++)) ; do
|
||||
# if ! command -v "${dependencies[$i]}" &> /dev/null ; then
|
||||
# echo "dependency not met: ${dependencies[$i]}"
|
||||
# missingdependencies=$((missingdependencies+1))
|
||||
# fi
|
||||
# done
|
||||
|
||||
# if [ $missingdependencies -gt 0 ] ; then
|
||||
# echo "Please install needed dependencies"
|
||||
# exit 1
|
||||
# fi
|
||||
# }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue