2022-12-19 17:19:26 +03:00
|
|
|
# shellcheck shell=bash
|
2022-10-16 22:46:42 +03: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.
|
|
|
|
|
2022-11-23 23:01:11 +03:00
|
|
|
# NOTE: If using another privilege escalation binary make sure it is configured or has the appropiate flag
|
|
|
|
# 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 22:46:42 +03:00
|
|
|
die() {
|
|
|
|
echo "die: $*"
|
|
|
|
exit 1
|
|
|
|
}
|
2022-12-06 20:17:41 +03:00
|
|
|
|
2023-07-08 07:31:05 +03:00
|
|
|
if [ "$(uname -s)" = "SerenityOS" ]; then
|
|
|
|
SUDO="pls -E"
|
|
|
|
elif command -v sudo >/dev/null; then
|
|
|
|
SUDO="sudo -E"
|
|
|
|
elif command -v doas >/dev/null; then
|
|
|
|
if [ "$SUDO_UID" = '' ]; then
|
|
|
|
SUDO_UID=$(id -u)
|
|
|
|
SUDO_GID=$(id -g)
|
|
|
|
export SUDO_UID SUDO_GID
|
|
|
|
fi
|
|
|
|
# To make doas work, you have to make sure you use the "keepenv" flag in doas.conf
|
|
|
|
SUDO="doas"
|
|
|
|
else
|
|
|
|
die "You need sudo, doas or pls to build Serenity..."
|
|
|
|
fi
|
|
|
|
|
2023-04-24 22:09:23 +03:00
|
|
|
exit_if_running_as_root() {
|
|
|
|
if [ "$(id -u)" -eq 0 ]; then
|
|
|
|
die "$*"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2022-12-06 20:17:41 +03:00
|
|
|
find_executable() {
|
|
|
|
paths=("/usr/sbin" "/sbin")
|
|
|
|
|
2022-12-19 02:56:47 +03:00
|
|
|
if [ "$(uname -s)" = "Darwin" ]; then
|
|
|
|
if [ -n "${HOMEBREW_PREFIX}" ]; then
|
|
|
|
paths+=("${HOMEBREW_PREFIX}/opt/e2fsprogs/bin" "${HOMEBREW_PREFIX}/opt/e2fsprogs/sbin")
|
|
|
|
elif command -v brew > /dev/null 2>&1; then
|
|
|
|
if prefix=$(brew --prefix e2fsprogs 2>/dev/null); then
|
|
|
|
paths+=("${prefix}/bin" "${prefix}/sbin")
|
|
|
|
fi
|
|
|
|
fi
|
2022-12-06 20:17:41 +03:00
|
|
|
fi
|
|
|
|
|
|
|
|
executable="${1}"
|
|
|
|
|
|
|
|
# Prefer tools from PATH over fallback paths
|
|
|
|
if command -v "${executable}"; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
for path in "${paths[@]}"; do
|
|
|
|
if command -v "${path}/${executable}"; then
|
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
# We return the executable's name back to provide meaningful messages on future failure
|
|
|
|
echo "${executable}"
|
|
|
|
}
|
|
|
|
|
|
|
|
FUSE2FS_PATH="$(find_executable fuse2fs)"
|
|
|
|
RESIZE2FS_PATH="$(find_executable resize2fs)"
|
2022-12-10 21:11:59 +03:00
|
|
|
E2FSCK_PATH="$(find_executable e2fsck)"
|
2022-12-15 18:25:44 +03:00
|
|
|
MKE2FS_PATH="$(find_executable mke2fs)"
|
2023-05-02 22:04:35 +03: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)
|
|
|
|
}
|