#!/bin/bash # Cross-lane rollback acceptance. Run only inside the disposable encrypted VM # through serial-driver.py rollback; the driver validates the qcow2 target. set -uo pipefail if [[ $(id -u) -ne 0 || ! -e /dev/mapper/cryptroot ]]; then echo '===ROLLBACK-NEEDS-ROOT-VM===' exit 1 fi SYS=/tmp/sys-lanes curl -fsSL http://10.0.2.2:8000/sys-lanes -o "$SYS" || exit 1 chmod 0755 "$SYS" WORK=$(mktemp -d) IMAGE=/opt/phoebus/appimages/rollback-fixture.AppImage if [[ -e $IMAGE ]]; then echo '===ROLLBACK-BREAK-PRESENT refusing vacuous run===' exit 1 fi fingerprint() { if [[ -f $IMAGE ]]; then sha256sum "$IMAGE" | awk '{print $1}' else echo absent fi } HOME_MARKER="appimage-rollback-$$-$(uname -r)" printf '%s\n' "$HOME_MARKER" > /home/phoebus/rollback-marker.txt echo "===ROLLBACK-KNOWN-GOOD pkgs=$(fingerprint) kernel=$(uname -r) home=$HOME_MARKER===" "$SYS" -y snapshot 'AppImage rollback acceptance' --legacy >"$WORK/snapshot.out" 2>&1 || exit 1 SNAP_ID=$(sed -n 's/^protective snapshot: //p' "$WORK/snapshot.out" | tail -1) echo "===ROLLBACK-SNAPSHOT id=$SNAP_ID===" [[ -n $SNAP_ID ]] || exit 1 mkdir -p /etc/phoebus printf 'rollback acceptance\n' > /etc/phoebus/rollback-broken.txt echo '===ROLLBACK-MARKER present===' install -m 0755 /usr/bin/true "$WORK/rollback-fixture.AppImage" "$SYS" -y --legacy --action \ "{\"action\":\"appimage_import\",\"path\":\"$WORK/rollback-fixture.AppImage\",\"name\":\"rollback-fixture\"}" \ >"$WORK/import.out" 2>&1 || exit 1 AUTO_ID=$(sed -n 's/^protective snapshot: //p' "$WORK/import.out" | tail -1) echo "===ROLLBACK-AUTO-SNAPSHOT id=$AUTO_ID===" [[ -n $AUTO_ID ]] || { sed -n '1,30p' "$WORK/import.out"; exit 1; } echo "===ROLLBACK-BROKEN pkgs=$(fingerprint)===" [[ -f $IMAGE ]] || exit 1 "$SYS" -y undo "$SNAP_ID" --legacy >"$WORK/undo.out" 2>&1 RC=$? echo "===ROLLBACK-UNDO rc=$RC id=$SNAP_ID===" [[ $RC -eq 0 ]] || { sed -n '1,30p' "$WORK/undo.out"; exit 1; } echo '===ROLLBACK-DONE===' sync poweroff -f echo '===POWEROFF==='