#!/bin/sh # Boot a root with target vpac installed and netbase available only in the embedded feed. set -eu export PATH=/bin:/usr/bin:/sbin:/usr/sbin LC_ALL=C HOME=/root phase=identity tls_server= finish() { status=$? if [ -n "$tls_server" ]; then kill "$tls_server" 2>/dev/null || true; fi if [ "$status" -ne 0 ]; then echo "VPAC TRANSACTION FAIL at $phase with status $status"; fi /sbin/poweroff -f } trap finish EXIT test "$(uname -o)" = Vinix mkdir -p /tmp vpac q -F name,validation local/musl >/tmp/musl grep -Eq '^validation[[:space:]]+signature$' /tmp/musl vpac o /bin/busybox | grep -q busybox arch=$(uname -m) package_command=${VPAC_TEST_PACKAGE_COMMAND:-vpac} case "$package_command" in vpac) ;; pkg) vpac o /usr/bin/pkg | grep -q vinix-pkg ;; *) echo "unknown test package command $package_command" >&2; exit 2 ;; esac install_netbase() { if [ "$package_command" = pkg ]; then pkg install netbase else vpac i --noconfirm netbase fi } install_test() { test ! -e /etc/services set -- /var/lib/vinix/repository/"$arch"/netbase-[0-9]*.pkg.tar.zst test "$#" -eq 1 && test -s "$1" archive=$1 phase=reject cp "$archive" /tmp/netbase-original # Change the Zstd magic without changing the signed archive's byte count. printf '\000' | dd of="$archive" bs=1 count=1 conv=notrunc 2>/dev/null test "$(wc -c <"$archive")" = "$(wc -c /tmp/reject.log 2>&1 || status=$? cat /tmp/reject.log test "$status" -ne 0 grep -Fiq 'invalid or corrupted package (PGP signature)' /tmp/reject.log test ! -e /etc/services for record in /var/lib/vpac/local/netbase-*; do test ! -d "$record"; done mv /tmp/netbase-original "$archive" phase=install install_netbase echo 'VPAC transaction installed authentic netbase' phase=installed-ownership vpac o /etc/services | grep -q netbase phase=installed-record vpac q -F name,validation local/netbase >/tmp/netbase grep -Eq '^name[[:space:]]+netbase$' /tmp/netbase grep -Eq '^validation[[:space:]]+signature$' /tmp/netbase grep -Eq '^ssh[[:space:]]+22/tcp' /etc/services echo 'VPAC transaction verified installed owner and signature' phase=remote-record vpac q --noconfirm -F name,version vinix/netbase >/tmp/exact grep -Eq '^name[[:space:]]+netbase$' /tmp/exact echo 'VPAC transaction resolved the exact repository record' phase=local-search vpac s --noconfirm --local --quiet netbase >/tmp/local-names grep -Fxq netbase /tmp/local-names echo 'VPAC transaction searched installed packages' phase=remote-search vpac s --noconfirm --remote --quiet netbase >/tmp/remote-names grep -Fxq netbase /tmp/remote-names vpac s --noconfirm --remote --quiet vinix-fixture-absent-port >/tmp/unknown test ! -s /tmp/unknown echo 'VPAC transaction verified package lookup' } mode=${VPAC_TEST_SCENARIO:-all} case "$mode" in install) install_test; echo 'VPAC FIXTURE GUEST PASS'; exit 0 ;; all) install_test ;; upgrade) ;; *) echo "unknown test scenario $mode" >&2; exit 2 ;; esac phase=upgrade reference=/var/lib/vinix/test-update test ! -e /etc/ssl1.1/cert.pem vpac q -F version local/ca-certificates-bundle >/tmp/bundle grep -Eq '^version[[:space:]]+20261020-2$' /tmp/bundle if [ "${VPAC_TEST_UPGRADE_HTTPS:-0}" = 1 ]; then phase=upgrade-https-setup unset http_proxy https_proxy HTTP_PROXY HTTPS_PROXY ALL_PROXY SSL_CERT_FILE SSL_CERT_DIR tls=$(mktemp -d /tmp/vpac-fixture-tls.XXXXXX) openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:P-256 -nodes -days 1 \ -subj /CN=127.0.0.1 -addext subjectAltName=IP:127.0.0.1 \ -keyout "$tls/key.pem" -out "$tls/cert.pem" ( cd "$reference" exec openssl s_server -accept 127.0.0.1:28443 -cert "$tls/cert.pem" -key "$tls/key.pem" -WWW ) >"$tls/server.log" 2>&1 & tls_server=$! url=https://127.0.0.1:28443 tries=0 until curl --disable --noproxy '*' --fail --silent --show-error --max-time 5 \ --cacert "$tls/cert.pem" "$url/vinix.db" -o "$tls/remote.db" >"$tls/client.log" 2>&1; do tries=$((tries + 1)) if [ "$tries" -ge 5 ]; then cat "$tls/client.log" "$tls/server.log"; exit 1; fi sleep 1 done cmp "$reference/vinix.db" "$tls/remote.db" trust_hash=$(openssl x509 -in "$tls/cert.pem" -noout -subject_hash) cp "$tls/cert.pem" "/etc/ssl/certs/$trust_hash.0" sed -i "s|file:///var/lib/vinix/repository/$arch|$url|" /etc/vpac.d/config.vile grep -Fq "$url" /etc/vpac.d/config.vile else cp "$reference/"* "/var/lib/vinix/repository/$arch/" fi phase=upgrade if [ "$package_command" = pkg ]; then pkg upgrade else vpac u --sync --noconfirm fi phase=upgraded-record vpac q -F version,validation local/ca-certificates-bundle >/tmp/upgraded grep -Eq '^version[[:space:]]+20261020-3$' /tmp/upgraded grep -Eq '^validation[[:space:]]+signature$' /tmp/upgraded test ! -d /var/lib/vpac/local/ca-certificates-bundle-20261020-2 phase=upgraded-files test "$(readlink /etc/ssl1.1/cert.pem)" = ../ssl/cert.pem cmp /etc/ssl1.1/cert.pem /etc/ssl/certs/ca-certificates.crt vpac o /etc/ssl1.1/cert.pem | grep -q ca-certificates-bundle if [ "${VPAC_TEST_UPGRADE_HTTPS:-0}" = 1 ]; then echo 'VPAC upgraded a signed package over HTTPS' fi echo 'VPAC FIXTURE GUEST PASS'