#!/bin/bash # Installed-system package-lane cycles. Run only inside a validated disposable # qcow2 guest; the host driver authenticates sudo before invoking this script. set -uo pipefail SYS="${SYS_BIN:-/tmp/sys-lanes}" WORK="$(mktemp -d)" trap 'rm -rf "$WORK"' EXIT PASS=0 FAIL=0 report() { printf 'CASE %s %s %s\n' "$1" "$2" "$3" if [[ $2 == PASS ]]; then PASS=$((PASS + 1)); else FAIL=$((FAIL + 1)); fi } failure() { tail -c 240 "$1" | tr '\n' ' ' } run_root() { sudo -n "$SYS" -y "$@" } echo '===SYS-LANES-START===' if [[ ! -x "$SYS" || ! -e /dev/mapper/cryptroot || $(id -u) -eq 0 ]]; then report preflight FAIL 'requires an installed encrypted VM and a normal user' echo "===SYS-LANES-END=== SUMMARY PASS=$PASS FAIL=$FAIL" exit 1 fi report preflight PASS 'installed encrypted VM, normal user' # Personal state must work without a privileged system lock. mkdir -p "$WORK/personal" if PHOEBUS_PERSONAL_DIR="$WORK/personal" "$SYS" --legacy --action \ '{"action":"set_package_preference","name":"lane-fixture","backend":"flatpak"}' \ >"$WORK/pref.out" 2>"$WORK/pref.err" && \ grep -q 'lane-fixture' "$WORK/personal/.config/phoebus/package-preferences.toml"; then report personal-preference PASS 'unprivileged preference saved' else report personal-preference FAIL "$(failure "$WORK/pref.err")" fi # No lane with no update feed may claim that it was checked and is current. for lane in appimage nix ebuild; do if "$SYS" updates --legacy "--$lane" >"$WORK/updates-$lane.out" 2>"$WORK/updates-$lane.err" && \ grep -q 'not checked:' "$WORK/updates-$lane.out" && \ ! grep -q 'All supported package sources are up to date' "$WORK/updates-$lane.out"; then report "updates-$lane-honest" PASS 'manual or unavailable lane identified' else report "updates-$lane-honest" FAIL "$(failure "$WORK/updates-$lane.err")" fi done # Portage install and removal must change the VDB and expose merge output. PKG=app-misc/hello if run_root install "$PKG" --legacy --portage >"$WORK/portage-install.out" 2>&1 && \ compgen -G "/var/db/pkg/${PKG}-*" >/dev/null; then report portage-install PASS 'package present in VDB' if grep -Eq '>>> (Emerging|Installing)|\[ebuild' "$WORK/portage-install.out"; then report portage-live-output PASS 'merge output reached the sys terminal' else report portage-live-output FAIL 'no Portage merge output in sys terminal' fi else report portage-install FAIL "$(failure "$WORK/portage-install.out")" fi if run_root remove "$PKG" --legacy --portage >"$WORK/portage-remove.out" 2>&1 && \ ! compgen -G "/var/db/pkg/${PKG}-*" >/dev/null; then report portage-remove PASS 'package absent from VDB' else report portage-remove FAIL "$(failure "$WORK/portage-remove.out")" fi # Flatseal is already in the fast-default Flatpak set. Remove then restore the # exact app so the test overlay finishes with the same desktop application. APP=com.github.tchx84.Flatseal if flatpak list --system --app --columns=application | grep -Fxq "$APP"; then if run_root remove "$APP" --legacy --flatpak >"$WORK/flatpak-remove.out" 2>&1 && \ ! flatpak list --system --app --columns=application | grep -Fxq "$APP"; then report flatpak-remove PASS 'app absent from system Flatpak list' if grep -q '^protective snapshot: ' "$WORK/flatpak-remove.out"; then report flatpak-snapshot PASS 'coordinated recovery point recorded' else report flatpak-snapshot FAIL 'no protective snapshot for Flatpak removal' fi else report flatpak-remove FAIL "$(failure "$WORK/flatpak-remove.out")" fi if run_root install "$APP" --legacy --flatpak >"$WORK/flatpak-install.out" 2>&1 && \ flatpak list --system --app --columns=application | grep -Fxq "$APP"; then report flatpak-install PASS 'app restored in system Flatpak list' if grep -Eqi 'installing|installation|fetching|downloading|progress' "$WORK/flatpak-install.out"; then report flatpak-live-output PASS 'Flatpak transaction output reached sys terminal' else report flatpak-live-output FAIL 'no Flatpak transaction output in sys terminal' fi else report flatpak-install FAIL "$(failure "$WORK/flatpak-install.out")" fi else report flatpak-fixture FAIL 'the fast-default Flatseal app is missing' fi # AppImage import/update/remove use bounded, pinned fixtures. A small ELF # exercises integrity and managed-file behavior without executing a download. install -m 0755 /usr/bin/true "$WORK/lane-fixture.AppImage" if run_root --legacy --action \ "{\"action\":\"appimage_import\",\"path\":\"$WORK/lane-fixture.AppImage\",\"name\":\"lane-fixture\"}" \ >"$WORK/appimage-import.out" 2>&1 && \ sudo -n test -f /opt/phoebus/appimages/lane-fixture.AppImage; then report appimage-import PASS 'managed image and record created' if grep -q '^protective snapshot: ' "$WORK/appimage-import.out"; then report appimage-snapshot PASS 'coordinated recovery point recorded' else report appimage-snapshot FAIL 'no protective snapshot for AppImage import' fi else report appimage-import FAIL "$(failure "$WORK/appimage-import.out")" fi if "$SYS" --legacy appimage list >"$WORK/appimage-list.out" 2>&1 && \ grep -q 'lane-fixture' "$WORK/appimage-list.out" && \ /opt/phoebus/appimages/lane-fixture.AppImage; then report appimage-user-access PASS 'normal account can list and launch managed image' else report appimage-user-access FAIL "$(stat -c '%a %n' /var/lib/phoebus /opt/phoebus/appimages 2>&1 | tr '\n' ' ') $(failure "$WORK/appimage-list.out")" fi if curl -fsSL http://10.0.2.2:8000/appimage-update-fixture -o "$WORK/appimage-new"; then sha="$(sha256sum "$WORK/appimage-new" | cut -d ' ' -f1)" if run_root --legacy --action \ "{\"action\":\"appimage_update\",\"name\":\"lane-fixture\",\"url\":\"http://10.0.2.2:8000/appimage-update-fixture\",\"sha256\":\"$sha\"}" \ >"$WORK/appimage-update.out" 2>&1 && \ test "$(sudo -n sha256sum /opt/phoebus/appimages/lane-fixture.AppImage | cut -d ' ' -f1)" = "$sha"; then report appimage-update PASS 'pinned replacement verified on disk' else report appimage-update FAIL "$(failure "$WORK/appimage-update.out")" fi else report appimage-update FAIL 'could not fetch host-served pinned fixture' fi if run_root appimage remove lane-fixture --legacy \ >"$WORK/appimage-remove.out" 2>&1 && \ ! sudo -n test -e /opt/phoebus/appimages/lane-fixture.AppImage; then report appimage-remove PASS 'managed image removed' else report appimage-remove FAIL "$(failure "$WORK/appimage-remove.out")" fi # A reviewed Nix install must create a persistent profile executable. if run_root install hello --legacy --nix >"$WORK/nix-install.out" 2>&1 && \ test -x /nix/var/nix/profiles/profile/bin/hello && \ grep -q 'run hello directly' "$WORK/nix-install.out"; then report nix-install PASS 'profile command is executable without nix shell' else report nix-install FAIL "$(failure "$WORK/nix-install.out")" fi echo "===SYS-LANES-END=== SUMMARY PASS=$PASS FAIL=$FAIL" [[ $FAIL -eq 0 ]]