| 1 | #!/bin/sh |
| 2 | # Boot a root with target vpac installed and netbase available only in the embedded feed. |
| 3 | set -eu |
| 4 | export PATH=/bin:/usr/bin:/sbin:/usr/sbin LC_ALL=C HOME=/root |
| 5 | phase=identity |
| 6 | finish() { |
| 7 | status=$? |
| 8 | if [ "$status" -ne 0 ]; then echo "VPAC TRANSACTION FAIL at $phase with status $status"; fi |
| 9 | /sbin/poweroff -f |
| 10 | } |
| 11 | trap finish EXIT |
| 12 | test "$(uname -o)" = Vinix |
| 13 | mkdir -p /tmp |
| 14 | vpac q -F name,validation local/musl >/tmp/musl |
| 15 | grep -Eq '^validation[[:space:]]+signature$' /tmp/musl |
| 16 | vpac o /bin/busybox | grep -q busybox |
| 17 | arch=$(uname -m) |
| 18 | package_command=${VPAC_TEST_PACKAGE_COMMAND:-vpac} |
| 19 | case "$package_command" in |
| 20 | vpac) ;; |
| 21 | pkg) vpac o /usr/bin/pkg | grep -q vinix-pkg ;; |
| 22 | *) echo "unknown test package command $package_command" >&2; exit 2 ;; |
| 23 | esac |
| 24 | |
| 25 | install_netbase() { |
| 26 | if [ "$package_command" = pkg ]; then |
| 27 | pkg install netbase |
| 28 | else |
| 29 | vpac i --noconfirm netbase |
| 30 | fi |
| 31 | } |
| 32 | |
| 33 | install_test() { |
| 34 | test ! -e /etc/services |
| 35 | set -- /var/lib/vinix/repository/"$arch"/netbase-[0-9]*.pkg.tar.zst |
| 36 | test "$#" -eq 1 && test -s "$1" |
| 37 | archive=$1 |
| 38 | |
| 39 | phase=reject |
| 40 | cp "$archive" /tmp/netbase-original |
| 41 | # Change the Zstd magic without changing the signed archive's byte count. |
| 42 | printf '\000' | dd of="$archive" bs=1 count=1 conv=notrunc 2>/dev/null |
| 43 | test "$(wc -c <"$archive")" = "$(wc -c </tmp/netbase-original)" |
| 44 | if cmp -s "$archive" /tmp/netbase-original; then exit 1; fi |
| 45 | status=0 |
| 46 | install_netbase >/tmp/reject.log 2>&1 || status=$? |
| 47 | cat /tmp/reject.log |
| 48 | test "$status" -ne 0 |
| 49 | grep -Fiq 'invalid or corrupted package (PGP signature)' /tmp/reject.log |
| 50 | test ! -e /etc/services |
| 51 | for record in /var/lib/vpac/local/netbase-*; do test ! -d "$record"; done |
| 52 | mv /tmp/netbase-original "$archive" |
| 53 | |
| 54 | phase=install |
| 55 | install_netbase |
| 56 | echo 'VPAC transaction installed authentic netbase' |
| 57 | phase=installed-ownership |
| 58 | vpac o /etc/services | grep -q netbase |
| 59 | phase=installed-record |
| 60 | vpac q -F name,validation local/netbase >/tmp/netbase |
| 61 | grep -Eq '^name[[:space:]]+netbase$' /tmp/netbase |
| 62 | grep -Eq '^validation[[:space:]]+signature$' /tmp/netbase |
| 63 | grep -Eq '^ssh[[:space:]]+22/tcp' /etc/services |
| 64 | |
| 65 | echo 'VPAC transaction verified installed owner and signature' |
| 66 | phase=remote-record |
| 67 | vpac q --noconfirm -F name,version vinix/netbase >/tmp/exact |
| 68 | grep -Eq '^name[[:space:]]+netbase$' /tmp/exact |
| 69 | echo 'VPAC transaction resolved the exact repository record' |
| 70 | phase=local-search |
| 71 | vpac s --noconfirm --local --quiet netbase >/tmp/local-names |
| 72 | grep -Fxq netbase /tmp/local-names |
| 73 | echo 'VPAC transaction searched installed packages' |
| 74 | phase=remote-search |
| 75 | vpac s --noconfirm --remote --quiet netbase >/tmp/remote-names |
| 76 | grep -Fxq netbase /tmp/remote-names |
| 77 | vpac s --noconfirm --remote --quiet vinix-fixture-absent-port >/tmp/unknown |
| 78 | test ! -s /tmp/unknown |
| 79 | |
| 80 | echo 'VPAC transaction verified package lookup' |
| 81 | } |
| 82 | |
| 83 | mode=${VPAC_TEST_SCENARIO:-all} |
| 84 | case "$mode" in |
| 85 | install) install_test; echo 'VPAC FIXTURE GUEST PASS'; exit 0 ;; |
| 86 | all) install_test ;; |
| 87 | upgrade) ;; |
| 88 | *) echo "unknown test scenario $mode" >&2; exit 2 ;; |
| 89 | esac |
| 90 | phase=upgrade |
| 91 | reference=/var/lib/vinix/test-update |
| 92 | test ! -e /etc/ssl1.1/cert.pem |
| 93 | vpac q -F version local/ca-certificates-bundle >/tmp/bundle |
| 94 | grep -Eq '^version[[:space:]]+20261020-2$' /tmp/bundle |
| 95 | cp "$reference/"* "/var/lib/vinix/repository/$arch/" |
| 96 | if [ "$package_command" = pkg ]; then |
| 97 | pkg upgrade |
| 98 | else |
| 99 | vpac u --sync --noconfirm |
| 100 | fi |
| 101 | phase=upgraded-record |
| 102 | vpac q -F version,validation local/ca-certificates-bundle >/tmp/upgraded |
| 103 | grep -Eq '^version[[:space:]]+20261020-3$' /tmp/upgraded |
| 104 | grep -Eq '^validation[[:space:]]+signature$' /tmp/upgraded |
| 105 | test ! -d /var/lib/vpac/local/ca-certificates-bundle-20261020-2 |
| 106 | phase=upgraded-files |
| 107 | test "$(readlink /etc/ssl1.1/cert.pem)" = ../ssl/cert.pem |
| 108 | cmp /etc/ssl1.1/cert.pem /etc/ssl/certs/ca-certificates.crt |
| 109 | vpac o /etc/ssl1.1/cert.pem | grep -q ca-certificates-bundle |
| 110 | echo 'VPAC FIXTURE GUEST PASS' |
| 111 | |