2024-01-24 23:43:58 -06:00
|
|
|
#!/bin/bash
|
|
|
|
|
2024-04-24 16:54:52 -05:00
|
|
|
set -e
|
|
|
|
if [ "$DEBUG" ]; then
|
|
|
|
set -x
|
|
|
|
export DEBUG=1
|
|
|
|
fi
|
|
|
|
|
2024-01-24 23:43:58 -06:00
|
|
|
check_deps() {
|
|
|
|
local needed_commands="$1"
|
|
|
|
for command in $needed_commands; do
|
|
|
|
if ! command -v $command &> /dev/null; then
|
2024-04-24 16:54:52 -05:00
|
|
|
echo " - $command"
|
2024-01-24 23:43:58 -06:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_deps() {
|
|
|
|
local needed_commands="$1"
|
|
|
|
local missing_commands=$(check_deps "$needed_commands")
|
|
|
|
if [ "${missing_commands}" ]; then
|
|
|
|
echo "You are missing dependencies needed for this script."
|
|
|
|
echo "Commands needed:"
|
|
|
|
echo "${missing_commands}"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
parse_args() {
|
|
|
|
declare -g -A args
|
|
|
|
for argument in "$@"; do
|
|
|
|
local key=$(echo $argument | cut -f1 -d=)
|
|
|
|
local key_length=${#key}
|
|
|
|
local value="${argument:$key_length+1}"
|
|
|
|
args["$key"]="$value"
|
|
|
|
done
|
2024-04-24 16:54:52 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
assert_root() {
|
|
|
|
if [ "$EUID" -ne 0 ]; then
|
|
|
|
echo "this needs to be run as root."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_args() {
|
|
|
|
if [ -z "$1" ]; then
|
|
|
|
print_help
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
}
|