2022-12-19 14:19:26 +00:00
|
|
|
# shellcheck shell=bash
|
2022-10-16 19:46:42 +00:00
|
|
|
# shellcheck disable=SC2034
|
|
|
|
# SC2034: "Variable appears unused. Verify it or export it."
|
|
|
|
# Those are intentional here, as the file is meant to be included elsewhere.
|
|
|
|
|
2023-10-02 14:26:32 +00:00
|
|
|
# NOTE: If using another privilege escalation binary make sure it is configured or has the appropriate flag
|
2022-11-23 20:01:11 +00:00
|
|
|
# to keep the current environment variables in the launched process (in sudo's case this is achieved
|
|
|
|
# through the -E flag described in sudo(8).
|
2022-10-16 19:46:42 +00:00
|
|
|
die() {
|
|
|
|
echo "die: $*"
|
|
|
|
exit 1
|
|
|
|
}
|
2022-12-06 17:17:41 +00:00
|
|
|
|
2023-04-24 19:09:23 +00:00
|
|
|
exit_if_running_as_root() {
|
|
|
|
if [ "$(id -u)" -eq 0 ]; then
|
|
|
|
die "$*"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-08-18 12:42:38 +00:00
|
|
|
# Usage: check_program_version_at_least <Display Name> <Program Name> <Version String>
|
|
|
|
check_program_version_at_least()
|
|
|
|
{
|
|
|
|
echo -n "Checking for $1 version at least $3... "
|
|
|
|
if ! command -v "$2" > /dev/null 2>&1; then
|
|
|
|
echo "ERROR: Cannot find $2 ($1)"
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
v=$("$2" --version 2>&1 | grep -E -o '[0-9]+\.[0-9\.]+[a-z]*' | head -n1)
|
|
|
|
if printf '%s\n' "$3" "$v" | sort --version-sort --check &>/dev/null; then
|
|
|
|
echo "ok, found $v"
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
echo "ERROR: found version $v, too old!"
|
|
|
|
return 1;
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2023-05-02 19:04:35 +00:00
|
|
|
get_number_of_processing_units() {
|
|
|
|
number_of_processing_units="nproc"
|
|
|
|
SYSTEM_NAME="$(uname -s)"
|
|
|
|
|
|
|
|
if [ "$SYSTEM_NAME" = "OpenBSD" ]; then
|
|
|
|
number_of_processing_units="sysctl -n hw.ncpuonline"
|
|
|
|
elif [ "$SYSTEM_NAME" = "FreeBSD" ]; then
|
|
|
|
number_of_processing_units="sysctl -n hw.ncpu"
|
|
|
|
elif [ "$SYSTEM_NAME" = "Darwin" ]; then
|
|
|
|
number_of_processing_units="sysctl -n hw.ncpu"
|
|
|
|
fi
|
|
|
|
|
|
|
|
($number_of_processing_units)
|
|
|
|
}
|