87 lines
4.0 KiB
Bash
Executable File
87 lines
4.0 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -Eeuo pipefail
|
|
ROOT=$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)
|
|
|
|
# The bundled Linux rules must match the expected user-provided settings.
|
|
diff -u "$ROOT/packaging/rustproxy.logrotate" - <<'CONFIG'
|
|
/var/log/rustproxy/*.jsonl /var/log/rustproxy/*.log /var/log/rustproxy/vhosts/*.jsonl {
|
|
daily
|
|
maxsize 512M
|
|
rotate 14
|
|
missingok
|
|
notifempty
|
|
compress
|
|
delaycompress
|
|
copytruncate
|
|
su rustproxy rustproxy
|
|
}
|
|
CONFIG
|
|
|
|
# All three log groups must also be tracked by native FreeBSD newsyslog.
|
|
OPNSENSE_CONF="$ROOT/opnsense/plugin/src/etc/newsyslog.conf.d/rustproxy.conf"
|
|
for pattern in '/var/log/rustproxy/*.jsonl' '/var/log/rustproxy/*.log' '/var/log/rustproxy/vhosts/*.jsonl'; do
|
|
grep -Fq "$pattern " "$OPNSENSE_CONF"
|
|
done
|
|
[[ $(grep -c '^/var/log/rustproxy/' "$OPNSENSE_CONF") == 3 ]]
|
|
grep -Fq '14 100M $D0 GBEZPN' "$OPNSENSE_CONF"
|
|
grep -Fq '14 100M $D0 GBEZP /var/run/rustproxy/daemon.pid SIGHUP' "$OPNSENSE_CONF"
|
|
grep -Fq ' -H -P ${pidfile}' "$ROOT/opnsense/plugin/src/etc/rc.d/rustproxy"
|
|
grep -Fq 'COPY packaging/ /opt/rust-package-builder/packaging/' "$ROOT/Dockerfile"
|
|
grep -Fq 'packaging_revision=$PACKAGING_REVISION' "$ROOT/scripts/build-linux-release.sh"
|
|
grep -Fq 'packaging_revision=$OPNSENSE_PACKAGING_REVISION' "$ROOT/scripts/build-opnsense-release.sh"
|
|
|
|
# Test staging and native PKG manifest without compiling Rust or signing RPM/DEB.
|
|
for tool in file zstd tar sha256sum python3; do
|
|
command -v "$tool" >/dev/null 2>&1 || { echo "SKIP packaging integration: missing $tool"; exit 0; }
|
|
done
|
|
WORK=$(mktemp -d)
|
|
trap 'rm -rf "$WORK"' EXIT
|
|
mkdir -p "$WORK/source" "$WORK/linux"
|
|
|
|
if command -v logrotate >/dev/null 2>&1; then
|
|
# Test parser compatibility even if the local test machine has no rustproxy user.
|
|
sed 's/su rustproxy rustproxy/su root root/' "$ROOT/packaging/rustproxy.logrotate" > "$WORK/logrotate-test.conf"
|
|
logrotate -d -s "$WORK/logrotate.state" "$WORK/logrotate-test.conf" > "$WORK/logrotate-output" 2>&1
|
|
grep -Fq 'reading config file' "$WORK/logrotate-output"
|
|
fi
|
|
printf '[package]\nname = "rust-proxy"\nversion = "1.0.0"\n' > "$WORK/source/Cargo.toml"
|
|
python3 - "$WORK/bin" <<'PY'
|
|
from pathlib import Path
|
|
import struct, sys
|
|
p = Path(sys.argv[1])
|
|
# ELF header with FreeBSD OSABI is enough to check the OPNsense packaging path.
|
|
e_ident = b'\x7fELF\x02\x01\x01\x09' + bytes(8)
|
|
header = struct.pack('<HHIQQQIHHHHHH', 2, 62, 1, 0, 0, 0, 0, 64, 56, 0, 64, 0, 0)
|
|
p.write_bytes(e_ident + header)
|
|
p.chmod(0o755)
|
|
PY
|
|
|
|
export BUILDER_ROOT="$ROOT" PACKAGE_NAME=rustproxy BINARY_NAME=rust-proxy
|
|
export VERSION=1.0.0 PACKAGE_RELEASE=2 DESCRIPTION=RustProxy LICENSE=UNKNOWN
|
|
export MAINTAINER=test@example.invalid HOMEPAGE=https://example.invalid
|
|
export GPG_PRIVATE_KEY_FILE=/nonexistent/test.gpg
|
|
"$ROOT/scripts/prepare-package.sh" "$WORK/source" "$WORK/linux" "$WORK/bin"
|
|
cmp "$ROOT/packaging/rustproxy.logrotate" "$WORK/linux/payload/etc/logrotate.d/rustproxy"
|
|
for metadata in nfpm-deb.yaml nfpm-rpm.yaml; do
|
|
grep -Fq '/etc/logrotate.d/rustproxy' "$WORK/linux/$metadata"
|
|
grep -Fq 'config|noreplace' "$WORK/linux/$metadata"
|
|
grep -Fq ' - logrotate' "$WORK/linux/$metadata"
|
|
done
|
|
|
|
"$ROOT/scripts/package-opnsense.sh" "$WORK/source" "$WORK/bin" "$WORK/os-rustproxy.pkg" '1.0.0_20'
|
|
zstd -dc "$WORK/os-rustproxy.pkg" | tar -xOf - +MANIFEST > "$WORK/manifest.json"
|
|
python3 - "$WORK/manifest.json" <<'PY'
|
|
import json, sys
|
|
with open(sys.argv[1]) as f:
|
|
manifest=json.load(f)
|
|
path='/usr/local/etc/newsyslog.conf.d/rustproxy.conf'
|
|
assert path in manifest['files'], f'{path} missing from PKG manifest'
|
|
assert path in manifest['files'] and len(manifest['files'][path]) == 64
|
|
assert '/usr/local/etc/rc.d/rustproxy' in manifest['files']
|
|
assert '/usr/local/etc/rc.syshook.d/start/50-rustproxy.start' in manifest['files']
|
|
assert '/usr/local/etc/rc.syshook.d/10-rustproxy.start' not in manifest['files']
|
|
PY
|
|
zstd -dc "$WORK/os-rustproxy.pkg" | tar -xOf - /usr/local/etc/newsyslog.conf.d/rustproxy.conf > "$WORK/packaged-newsyslog.conf"
|
|
cmp "$OPNSENSE_CONF" "$WORK/packaged-newsyslog.conf"
|
|
echo 'log rotation package integration: OK'
|