84 lines
3.1 KiB
Bash
Executable File
84 lines
3.1 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
CONFIG_FILE="${RUSTPROXY_BUILDER_CONFIG:-/etc/rustproxy-opnsense-builder.env}"
|
|
if [[ -r "$CONFIG_FILE" ]]; then
|
|
# Export all builder configuration to child build scripts.
|
|
set -a
|
|
# shellcheck disable=SC1090
|
|
source "$CONFIG_FILE"
|
|
set +a
|
|
fi
|
|
|
|
: "${BUILD_MODE:=docker-freebsd}"
|
|
: "${OPNSENSE_ABI:=26.7}"
|
|
: "${FREEBSD_RELEASE:=15.1-RELEASE}"
|
|
: "${FREEBSD_ABI:=FreeBSD:15:amd64}"
|
|
: "${FREEBSD_ARCH:=freebsd:15:x86:64}"
|
|
: "${RUSTPROXY_SOURCE_DIR:?RUSTPROXY_SOURCE_DIR must point to a checked-out RustProxy repository}"
|
|
: "${RUSTPROXY_SOURCE_URL:=https://git.linuxiarz.pl/gru/RustProxy}"
|
|
: "${RUSTPROXY_SOURCE_REF:=HEAD}"
|
|
: "${RUSTPROXY_SOURCE_COMMIT:=$(git -C "$RUSTPROXY_SOURCE_DIR" rev-parse HEAD)}"
|
|
: "${RUSTPROXY_SOURCE_REVISION:=$(git -C "$RUSTPROXY_SOURCE_DIR" rev-list --count "$RUSTPROXY_SOURCE_COMMIT")}"
|
|
|
|
publish_dist()
|
|
{
|
|
if [[ -z "${PUBLISH_TARGET:-}" ]]; then
|
|
echo "PUBLISH_TARGET is empty; artifacts remain in $ROOT/dist"
|
|
return 0
|
|
fi
|
|
local ssh_cmd=(ssh -o BatchMode=yes)
|
|
if [[ -n "${PUBLISH_SSH_KEY:-}" ]]; then
|
|
ssh_cmd+=( -i "$PUBLISH_SSH_KEY" )
|
|
fi
|
|
rsync -az --delete-delay -e "${ssh_cmd[*]}" "$ROOT/dist/" "$PUBLISH_TARGET"
|
|
}
|
|
|
|
auto_deploy_tests()
|
|
{
|
|
[[ -n "${AUTO_DEPLOY_HOSTS:-}" ]] || return 0
|
|
local package="$ROOT/dist/os-rustproxy-latest.pkg"
|
|
[[ -f "$package" ]] || { echo "Missing package for deployment: $package" >&2; exit 1; }
|
|
|
|
for host in $AUTO_DEPLOY_HOSTS; do
|
|
echo "Deploying RustProxy to test firewall: $host"
|
|
local ssh_args=( -o BatchMode=yes )
|
|
if [[ -n "${AUTO_DEPLOY_SSH_KEY:-}" ]]; then
|
|
ssh_args+=( -i "$AUTO_DEPLOY_SSH_KEY" )
|
|
fi
|
|
scp "${ssh_args[@]}" "$package" "$host:/tmp/os-rustproxy-latest.pkg"
|
|
ssh "${ssh_args[@]}" "$host" '
|
|
set -e
|
|
pkg add -f /tmp/os-rustproxy-latest.pkg
|
|
rm -f /tmp/os-rustproxy-latest.pkg
|
|
service configd restart
|
|
/usr/local/sbin/pluginctl -cq cache_flush >/dev/null 2>&1 || true
|
|
/usr/local/sbin/configctl template reload OPNsense/RustProxy >/dev/null 2>&1 || true
|
|
if [ -r /usr/local/etc/rustproxy/opnsense.conf ] && \
|
|
grep -q "^enabled=\"1\"" /usr/local/etc/rustproxy/opnsense.conf; then
|
|
if ! /usr/local/opnsense/scripts/rustproxy/service.sh status >/dev/null 2>&1; then
|
|
/usr/local/opnsense/scripts/rustproxy/service.sh start
|
|
fi
|
|
/usr/local/opnsense/scripts/rustproxy/service.sh status
|
|
fi
|
|
'
|
|
done
|
|
}
|
|
|
|
case "$BUILD_MODE" in
|
|
docker-freebsd)
|
|
export OPNSENSE_ABI FREEBSD_RELEASE FREEBSD_ABI FREEBSD_ARCH
|
|
export RUSTPROXY_SOURCE_DIR RUSTPROXY_SOURCE_URL RUSTPROXY_SOURCE_REF
|
|
export RUSTPROXY_SOURCE_COMMIT RUSTPROXY_SOURCE_REVISION
|
|
"$ROOT/builder/debian/build-docker-release.sh"
|
|
;;
|
|
*)
|
|
echo "Unsupported BUILD_MODE: $BUILD_MODE. Use docker-freebsd." >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
publish_dist
|
|
auto_deploy_tests
|