opensnitch/utils/packaging/arch/prepare.sh
trvon 60cd4311a8
build: daemon-only fork build + Arch packaging, kernel-matched eBPF
Add a daemon-only build path (no Python GUI) that builds the eBPF objects
against the running kernel's headers, deriving the BPF DataLayout from
clang and finalizing with opt; a structural unprivileged check target; an
install path that never clobbers existing units/config/rules; an Arch
PKGBUILD.in + prepare.sh and a test_install.sh harness. Document the
workflow and the event-loss diagnostics in README.md and ebpf_prog/README.
Gitignore the compiled ebpf_prog/*.o artifacts.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-05 16:58:22 -07:00

62 lines
3.2 KiB
Bash

#!/bin/sh
# Export only committed native sources + reviewed build overlays. No UI, host
# configuration, generated binaries, source mutation, install or service calls.
set -eu
export LC_ALL=C TZ=UTC
unset GZIP
root=$(CDPATH= cd -- "$(dirname -- "$0")/../../.." && pwd)
out=${1:?Usage: sh utils/packaging/arch/prepare.sh /absolute/new/output-directory}
case "$out" in /*) ;; *) echo 'Output must be absolute' >&2; exit 2 ;; esac
# Refuse runtime-source omissions rather than silently exporting stale code.
for path in $(git -C "$root" diff HEAD --name-only -- daemon proto ebpf_prog); do
case "$path" in daemon/Makefile|ebpf_prog/Makefile|ebpf_prog/README) ;;
*) echo "Commit/review native source changes before exporting: $path" >&2; exit 2 ;;
esac
done
untracked=$(git -C "$root" ls-files --others --exclude-standard -- daemon proto ebpf_prog)
if test -n "$untracked"; then
printf '%s\n' "$untracked" | while IFS= read -r path; do
case "$path" in ebpf_prog/opensnitch.o|ebpf_prog/opensnitch-dns.o|ebpf_prog/opensnitch-procs.o) ;;
*) echo "Untracked native source requires review: $path" >&2; exit 2 ;;
esac
done
fi
# These are the generator pins already used by this checkout's Go CI.
test "$(protoc-gen-go --version)" = 'protoc-gen-go v1.34.1'
test "$(protoc-gen-go-grpc --version)" = 'protoc-gen-go-grpc 1.3.0'
mkdir -m700 -- "$out"
src="$out/source"
mkdir "$src"
git -C "$root" archive --format=tar -o "$out/committed.tar" HEAD \
daemon proto ebpf_prog Makefile README.md LICENSE
tar -xf "$out/committed.tar" -C "$src"
# Only these build/docs overlays can differ from the recorded base revision.
for path in Makefile README.md daemon/Makefile ebpf_prog/Makefile ebpf_prog/README; do
cp "$root/$path" "$src/$path"
done
mkdir -p "$src/utils/packaging"
cp "$root/utils/packaging/test_install.sh" "$src/utils/packaging/test_install.sh"
make -C "$src" protocol-go
# Fail rather than produce a falsely versioned package after a version bump.
grep -Eq 'Version = "1[.]9[.]0"' "$src/daemon/core/version.go"
{
printf 'Base revision: '
git -C "$root" rev-parse HEAD
printf 'Working-tree build overlays are included; this is not a clean-commit claim.\n'
protoc --version
protoc-gen-go --version
protoc-gen-go-grpc --version
cd "$src"
sha256sum Makefile README.md daemon/Makefile ebpf_prog/Makefile ebpf_prog/README \
utils/packaging/test_install.sh daemon/ui/protocol/ui.pb.go daemon/ui/protocol/ui_grpc.pb.go
} > "$src/BUILD_SOURCE.txt"
epoch=${SOURCE_DATE_EPOCH:-$(git -C "$root" show -s --format=%ct HEAD)}
case "$epoch" in ''|*[!0-9]*) echo 'Invalid SOURCE_DATE_EPOCH' >&2; exit 2 ;; esac
tar --sort=name --mtime="@$epoch" --owner=0 --group=0 --numeric-owner \
--transform='flags=rh;s,^,opensnitch-native/,' -cf "$out/opensnitch-native-1.9.0.tar" -C "$src" .
gzip -n "$out/opensnitch-native-1.9.0.tar"
sum=$(sha256sum "$out/opensnitch-native-1.9.0.tar.gz")
sum=${sum%% *}
sed "s/@SOURCE_SHA256@/$sum/" "$root/utils/packaging/arch/PKGBUILD.in" > "$out/PKGBUILD"
printf 'Prepared checksum-pinned local source and PKGBUILD in %s\n' "$out"
printf 'Review PKGBUILD, then run makepkg there without -i or -s. No installation performed.\n'