51 lines
2.0 KiB
Bash
Executable File
51 lines
2.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
source /opt/rust-package-builder/scripts/lib.sh
|
|
|
|
SOURCE_DIR=${1:?usage: apply-freebsd-patches.sh /path/to/source}
|
|
PATCH_ROOT=/opt/rust-package-builder/opnsense/patches
|
|
|
|
[[ -f "$SOURCE_DIR/Cargo.toml" ]] || fatal "missing Cargo.toml in FreeBSD build source: $SOURCE_DIR"
|
|
|
|
# build-release.sh already resolves the Cargo package version and exports VERSION.
|
|
# Reuse it here so the FreeBSD branch does not need to parse Cargo.toml again.
|
|
SOURCE_VERSION=${VERSION:-}
|
|
if [[ -z "$SOURCE_VERSION" ]]; then
|
|
# Fallback for standalone/manual use of this helper. Rocky Linux 9 exposes
|
|
# python3 as Python 3.9, while tomllib is part of the stdlib from Python 3.11.
|
|
PYTHON_BIN=${RUST_PROXY_PYTHON:-/usr/bin/python3.11}
|
|
[[ -x "$PYTHON_BIN" ]] || fatal "Python 3.11 not found: $PYTHON_BIN"
|
|
SOURCE_VERSION=$("$PYTHON_BIN" - "$SOURCE_DIR/Cargo.toml" <<'PY'
|
|
import sys
|
|
import tomllib
|
|
from pathlib import Path
|
|
with Path(sys.argv[1]).open('rb') as f:
|
|
print(tomllib.load(f)['package']['version'])
|
|
PY
|
|
)
|
|
fi
|
|
|
|
[[ -n "$SOURCE_VERSION" ]] || fatal "cannot determine RustProxy version for FreeBSD patch selection"
|
|
PATCH_DIR="$PATCH_ROOT/$SOURCE_VERSION"
|
|
if [[ ! -d "$PATCH_DIR" ]]; then
|
|
log "no FreeBSD/OPNsense patch set for RustProxy $SOURCE_VERSION; using upstream source"
|
|
exit 0
|
|
fi
|
|
|
|
shopt -s nullglob
|
|
patches=("$PATCH_DIR"/*.patch)
|
|
(( ${#patches[@]} > 0 )) || fatal "FreeBSD patch directory is empty: $PATCH_DIR"
|
|
|
|
log "applying FreeBSD/OPNsense patches for RustProxy $SOURCE_VERSION"
|
|
for patch_file in "${patches[@]}"; do
|
|
patch_name=$(basename "$patch_file")
|
|
if git -C "$SOURCE_DIR" apply --check "$patch_file" 2>/dev/null; then
|
|
git -C "$SOURCE_DIR" apply "$patch_file"
|
|
log "applied patch: $patch_name"
|
|
elif git -C "$SOURCE_DIR" apply --reverse --check "$patch_file" 2>/dev/null; then
|
|
log "patch already present: $patch_name"
|
|
else
|
|
fatal "patch does not apply cleanly: $patch_name (RustProxy $SOURCE_VERSION)"
|
|
fi
|
|
done
|