mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:38:11 +00:00
Meta: Factorize path resolution
This patch adds the `find_executable()` function that will hopefully find executables in a distro-agnostic way and that is (hopefully as well) easily upgradable. The function uses some bash functionalities. So, we now require bash for each script that includes `.shell_include.sh`.
This commit is contained in:
parent
b409d3cf88
commit
0fde7fe3c5
6 changed files with 35 additions and 39 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/usr/bin/env bash
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
# SC2034: "Variable appears unused. Verify it or export it."
|
# SC2034: "Variable appears unused. Verify it or export it."
|
||||||
# Those are intentional here, as the file is meant to be included elsewhere.
|
# Those are intentional here, as the file is meant to be included elsewhere.
|
||||||
|
@ -16,3 +16,32 @@ die() {
|
||||||
echo "die: $*"
|
echo "die: $*"
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
find_executable() {
|
||||||
|
paths=("/usr/sbin" "/sbin")
|
||||||
|
|
||||||
|
if [ "$(uname -s)" = "Darwin" ]; then
|
||||||
|
paths+=("/usr/local/opt/e2fsprogs/bin" "/usr/local/opt/e2fsprogs/sbin")
|
||||||
|
paths+=("/opt/homebrew/opt/e2fsprogs/bin" "/opt/homebrew/opt/e2fsprogs/sbin")
|
||||||
|
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)"
|
||||||
|
E2FSCK="$(find_executable e2fsck)"
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
|
|
@ -1,17 +1,4 @@
|
||||||
#!/bin/sh
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Note: This is done before `set -e` to let `command` fail if needed
|
|
||||||
FUSE2FS_PATH=$(command -v fuse2fs)
|
|
||||||
RESIZE2FS_PATH=$(command -v resize2fs)
|
|
||||||
|
|
||||||
if [ -z "$FUSE2FS_PATH" ]; then
|
|
||||||
FUSE2FS_PATH=/usr/sbin/fuse2fs
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "$RESIZE2FS_PATH" ]; then
|
|
||||||
RESIZE2FS_PATH=/usr/sbin/resize2fs
|
|
||||||
fi
|
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
SCRIPT_DIR="$(dirname "${0}")"
|
SCRIPT_DIR="$(dirname "${0}")"
|
||||||
|
@ -42,26 +29,6 @@ else
|
||||||
: "${SUDO_UID:=0}" "${SUDO_GID:=0}"
|
: "${SUDO_UID:=0}" "${SUDO_GID:=0}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$(uname -s)" = "Darwin" ]; then
|
|
||||||
export PATH="/usr/local/opt/e2fsprogs/bin:$PATH"
|
|
||||||
export PATH="/usr/local/opt/e2fsprogs/sbin:$PATH"
|
|
||||||
export PATH="/opt/homebrew/opt/e2fsprogs/bin:$PATH"
|
|
||||||
export PATH="/opt/homebrew/opt/e2fsprogs/sbin:$PATH"
|
|
||||||
|
|
||||||
E2FSCK="e2fsck"
|
|
||||||
RESIZE2FS_PATH="resize2fs"
|
|
||||||
elif [ ! -f "$E2FSCK" ]; then
|
|
||||||
E2FSCK="$(command -v e2fsck)"
|
|
||||||
|
|
||||||
if [ ! -f "$E2FSCK" ]; then
|
|
||||||
E2FSCK="/usr/sbin/e2fsck"
|
|
||||||
if [ ! -f "$E2FSCK" ]; then
|
|
||||||
E2FSCK="/sbin/e2fsck"
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Prepend the toolchain qemu directory so we pick up QEMU from there
|
# Prepend the toolchain qemu directory so we pick up QEMU from there
|
||||||
PATH="$SCRIPT_DIR/../Toolchain/Local/qemu/bin:$PATH"
|
PATH="$SCRIPT_DIR/../Toolchain/Local/qemu/bin:$PATH"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#!/bin/sh
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue