Serenity Operating System
1# shellcheck shell=bash
2# shellcheck disable=SC2034
3# SC2034: "Variable appears unused. Verify it or export it."
4# Those are intentional here, as the file is meant to be included elsewhere.
5
6# NOTE: If using another privilege escalation binary make sure it is configured or has the appropiate flag
7# to keep the current environment variables in the launched process (in sudo's case this is achieved
8# through the -E flag described in sudo(8).
9SUDO="sudo -E"
10
11if [ "$(uname -s)" = "SerenityOS" ]; then
12 SUDO="pls -E"
13fi
14
15die() {
16 echo "die: $*"
17 exit 1
18}
19
20find_executable() {
21 paths=("/usr/sbin" "/sbin")
22
23 if [ "$(uname -s)" = "Darwin" ]; then
24 if [ -n "${HOMEBREW_PREFIX}" ]; then
25 paths+=("${HOMEBREW_PREFIX}/opt/e2fsprogs/bin" "${HOMEBREW_PREFIX}/opt/e2fsprogs/sbin")
26 elif command -v brew > /dev/null 2>&1; then
27 if prefix=$(brew --prefix e2fsprogs 2>/dev/null); then
28 paths+=("${prefix}/bin" "${prefix}/sbin")
29 fi
30 fi
31 fi
32
33 executable="${1}"
34
35 # Prefer tools from PATH over fallback paths
36 if command -v "${executable}"; then
37 return 0
38 fi
39
40 for path in "${paths[@]}"; do
41 if command -v "${path}/${executable}"; then
42 return 0
43 fi
44 done
45
46 # We return the executable's name back to provide meaningful messages on future failure
47 echo "${executable}"
48}
49
50FUSE2FS_PATH="$(find_executable fuse2fs)"
51RESIZE2FS_PATH="$(find_executable resize2fs)"
52E2FSCK_PATH="$(find_executable e2fsck)"
53MKE2FS_PATH="$(find_executable mke2fs)"