scripts, build, just: POSIX Compliance

Enforce POSIX shell syntax with ShellCheck using `--shell sh`.
This commit is contained in:
Lorenz Leutgeb
2026-10-30 12:45:40 +01:00
parent 9e80d2d4b9
commit c7d71df4ab
26 changed files with 94 additions and 92 deletions
+15 -15
View File
@@ -1,35 +1,35 @@
#! /usr/bin/env bash
#! /usr/bin/env sh
set -euo pipefail
readonly HOOK="${HOOK:-$(basename "$0")}"
if ! [[ "$HOOK" =~ ^(pre-(commit|push)|post-checkout|commit-msg)$ ]]
then
echo "Unknown hook '${HOOK}'."
exit 1
fi
case "$HOOK" in
pre-commit|pre-push|post-checkout|commit-msg) ;;
*)
echo "Unknown hook '${HOOK}'."
exit 1
;;
esac
readonly SENSITIVE_FILES=("justfile" "build.rs" "rust-toolchain.toml")
readonly BASE_BRANCH="main"
# Check which files were modified compared to the base branch.
mapfile -t CHANGED_FILES < <(comm -12 \
<(git diff --name-only "${BASE_BRANCH}" | sort) \
<(IFS=$'\n'; echo "${SENSITIVE_FILES[*]}" | sort) \
)
# Check which sensitive files were modified compared to the base branch.
CHANGED_FILES=$(git diff --name-only "$BASE_BRANCH" -- \
justfile build.rs rust-toolchain.toml)
if [ ${#CHANGED_FILES[@]} -gt 0 ]
if [ -n "$CHANGED_FILES" ]
then
echo "⚠️ WARNING: Sensitive files have been modified relative to $BASE_BRANCH."
echo "Executing this hook may run arbitrary code from the modified files."
echo ""
git --no-pager diff "$BASE_BRANCH" -- "${SENSITIVE_FILES[@]}"
git --no-pager diff "$BASE_BRANCH" -- justfile build.rs rust-toolchain.toml
# Read from /dev/tty because stdin is not attached to the terminal in Git hooks.
exec < /dev/tty
read -r -p "⚠️ Do you want to continue executing the '${HOOK}' hook? [y/N] " response
printf "⚠️ Do you want to continue executing the '%s' hook? [y/N] " "$HOOK"
read -r response
case "$response" in
[yY][eE][sS]|[yY])
echo "Continuing with '${HOOK}' hook…"