Files
rustproxy-opnsense-repo/scripts/check.sh
T

104 lines
4.6 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
while IFS= read -r file; do
first_line="$(head -n 1 "$file")"
if [[ "$first_line" == *bash* ]]; then
bash -n "$file"
else
sh -n "$file"
fi
done < <(find "$ROOT" -type f \( -name '*.sh' -o -path '*/src/etc/rc.d/rustproxy' -o -path '*/src/etc/rc.syshook.d/*.start' \))
python3 - "$ROOT" <<'PY'
import pathlib
import sys
import xml.etree.ElementTree as ET
root = pathlib.Path(sys.argv[1])
for path in root.glob('opnsense-plugin/**/*.xml'):
ET.parse(path)
print('xml ok:', path.relative_to(root))
PY
if command -v php >/dev/null 2>&1; then
while IFS= read -r file; do php -l "$file" >/dev/null; done < <(find "$ROOT/opnsense-plugin" -type f -name '*.php')
fi
if [[ -n "${RUSTPROXY_SOURCE_DIR:-}" ]] && [[ -f "$RUSTPROXY_SOURCE_DIR/Cargo.toml" ]] && command -v cargo >/dev/null 2>&1; then
cargo metadata --locked --no-deps --format-version 1 --manifest-path "$RUSTPROXY_SOURCE_DIR/Cargo.toml" >/dev/null
fi
if [[ -d "$ROOT/app" ]]; then
echo "RustProxy source must not be vendored in this packaging repository: $ROOT/app" >&2
exit 1
fi
if [[ -e "$ROOT/opnsense-plugin/www/rustproxy/src/sbin/rust-proxy" ]]; then
echo "Generated binary must not be committed in plugin source." >&2
exit 1
fi
[[ -f "$ROOT/builder/docker/Dockerfile" ]]
grep -q '15.1-RELEASE' "$ROOT/builder/docker/Dockerfile"
grep -q 'rust:1.88-' "$ROOT/builder/docker/Dockerfile"
grep -q 'x86_64-unknown-freebsd' "$ROOT/builder/docker/Dockerfile"
grep -q 'BUILD_MODE=docker-freebsd' "$ROOT/builder.env.example"
grep -q 'PACKAGING_WORKDIR=/opt/opn-rustproxy/packaging' "$ROOT/builder.env.example"
[[ -x "$ROOT/builder/freebsd/apply-patches.sh" ]]
[[ -f "$ROOT/builder/freebsd/patches/0.20.0/0001-opnsense-build.patch" ]]
grep -q 'APPLY_FREEBSD_PATCHES=1' "$ROOT/builder.env.example"
grep -q 'builder/freebsd/apply-patches.sh' "$ROOT/builder/debian/build-docker-release.sh"
rc_script="$ROOT/opnsense-plugin/www/rustproxy/src/etc/rc.d/rustproxy"
model="$ROOT/opnsense-plugin/www/rustproxy/src/opnsense/mvc/app/models/OPNsense/RustProxy/RustProxy.xml"
template="$ROOT/opnsense-plugin/www/rustproxy/src/opnsense/service/templates/OPNsense/RustProxy/rustproxy.conf"
post_install="$ROOT/opnsense-plugin/www/rustproxy/+POST_INSTALL.pre"
pre_deinstall="$ROOT/opnsense-plugin/www/rustproxy/+PRE_DEINSTALL.pre"
grep -q 'rustproxy_run_dir:="/var/run/rustproxy"' "$rc_script"
grep -q 'rustproxy_user:="root"' "$rc_script"
grep -q 'rustproxy_group:="wheel"' "$rc_script"
grep -q 'rustproxy_resolve_listener' "$rc_script"
grep -q 'rustproxy_valid_port' "$rc_script"
grep -q 'pidfile="${rustproxy_run_dir}/daemon.pid"' "$rc_script"
grep -q 'child_pidfile="${rustproxy_run_dir}/rustproxy.pid"' "$rc_script"
grep -q '<version>1.4.0</version>' "$model"
grep -q '<Default>0.0.0.0</Default>' "$model"
grep -q '<Default>8080</Default>' "$model"
grep -q '<Default>8181</Default>' "$model"
grep -q '<Default>9090</Default>' "$model"
grep -q 'class M1_4_0 extends BaseModelMigration' "$ROOT/opnsense-plugin/www/rustproxy/src/opnsense/mvc/app/models/OPNsense/RustProxy/Migrations/M1_4_0.php"
grep -q 'start_postcmd="rustproxy_poststart"' "$rc_script"
grep -q 'status_cmd="rustproxy_status"' "$rc_script"
grep -q 'RustProxy exec:' "$rc_script"
grep -q 'return 1;' "$ROOT/opnsense-plugin/www/rustproxy/src/opnsense/mvc/app/controllers/OPNsense/RustProxy/Api/ServiceController.php"
grep -q '<proxyPort type="PortField">' "$model"
grep -q '<tlsPort type="PortField">' "$model"
grep -q '<adminPort type="PortField">' "$model"
grep -q 'rustproxy_tls_port=' "$template"
grep -q 'rustproxy_tls_listen_legacy=' "$template"
grep -q 'root -g wheel' "$post_install"
grep -q '/var/run/rustproxy' "$post_install"
grep -q 'rustproxy_malloc_conf="${MALLOC_CONF:-narenas:2}"' "$rc_script"
grep -q 'export MALLOC_CONF' "$rc_script"
if grep -q 'MALLOC_ARENA_MAX' "$rc_script"; then
# It may only appear in the explanatory FreeBSD comment, never as an export.
! grep -Eq '(^|[[:space:]])(export[[:space:]]+)?MALLOC_ARENA_MAX=' "$rc_script"
fi
grep -q 'service.sh restart' "$post_install"
grep -q 'onestop' "$pre_deinstall"
grep -q 'service.sh status' "$ROOT/ci/build-release.sh"
# The generated command must never contain a literal listener ending in a colon
# from model defaults/templates. rc.d rejects/falls back from malformed legacy
# values before assembling runtime_args.
if grep -R --exclude='*.md' --exclude='check.sh' -nE 'tls_listen.*0\.0\.0\.0:"|--tls-listen 0\.0\.0\.0:' "$ROOT/opnsense-plugin"; then
echo "Malformed empty-port TLS listener found in plugin source" >&2
exit 1
fi
echo "Repository checks passed."