diff --git a/migrations/1790461245.sh b/migrations/1790461245.sh new file mode 100644 index 00000000000..12dd697ab1f --- /dev/null +++ b/migrations/1790461245.sh @@ -0,0 +1,17 @@ +echo "Move this Mac onto Omarchy's official packages with the released omarchy-mac-boot" + +# Only this runtime carries it; official Omarchy reaches a Mac through +# 1790347292 and its installed omarchy-mac-boot. A tester's Mac may have no +# omarchy-mac-boot or an unofficial one, and may have run 1790347292 before +# any target existed, so this runs the engine from a verified download of the +# official package. Until that package ships its target, and while preflight +# refuses, it exits 75 and stays pending without holding up the update. The +# work is machine-wide: once it ran, the marker spares every other account. +marker="${OMARCHY_MAC_ACTIVATION_MARKER:-/var/lib/omarchy/migrations/1790461245}" +[[ ! -e $marker ]] || exit 0 + +platform=$(omarchy-hw-platform) +[[ $platform == "apple-silicon" ]] || exit 0 + +sudo omarchy-mac-migrate-bootstrap +sudo install -Dm644 /dev/null "$marker" diff --git a/packages/omarchy-mac/boot/files/usr/lib/omarchy-mac/boot/migration-target b/packages/omarchy-mac/boot/files/usr/lib/omarchy-mac/boot/migration-target new file mode 100644 index 00000000000..06d01219ea9 --- /dev/null +++ b/packages/omarchy-mac/boot/files/usr/lib/omarchy-mac/boot/migration-target @@ -0,0 +1,4 @@ +# Activates the Mac migration (ticket 53): Macs move onto Omarchy's stable channel. +format=1 +type=repository +channel=stable diff --git a/packages/omarchy-mac/boot/test/mac-migrate-test.sh b/packages/omarchy-mac/boot/test/mac-migrate-test.sh index eb3b68c4458..ac2c11610d8 100644 --- a/packages/omarchy-mac/boot/test/mac-migrate-test.sh +++ b/packages/omarchy-mac/boot/test/mac-migrate-test.sh @@ -515,7 +515,7 @@ echo generic-aarch64 >"$F/platform" output=$(migrate run 2>&1) || fail "another platform is a no-op" "$output" grep -q "Not an Apple Silicon Mac" <<<"$output" && [[ ! -e $(state_dir) ]] || fail "another platform is left alone" "$output" echo apple-silicon >"$F/platform" -rm "$R/etc/omarchy-mac/migration-target" +rm "$R/etc/omarchy-mac/migration-target" "$R/usr/lib/omarchy-mac/boot/migration-target" output=$(migrate run 2>&1) || fail "no target is a no-op" "$output" grep -q "No migration target is set" <<<"$output" && [[ ! -e $(state_dir) ]] || fail "without a target nothing runs" "$output" if OMARCHY_MAC_MIGRATE_ROOT="" "$R/usr/bin/omarchy-mac-migrate" run 2>/dev/null; then fail "a normal user without a fixture root is refused"; fi @@ -790,6 +790,8 @@ pass "a repository target (omacom stable later) replaces the same names from [om [[ -x $R/usr/lib/omarchy/mac-boot/migrate && $(stat -c %a "$R/usr/lib/omarchy/mac-boot/migrate") == 755 ]] || fail "the migrate entrypoint is staged for omarchy-lifecycle-dispatch" [[ -f $R/usr/lib/systemd/system/omarchy-mac-migrate-verify.service ]] || fail "the post-reboot unit is staged" +[[ $(grep -v '^#' "$R/usr/lib/omarchy-mac/boot/migration-target") == $'format=1\ntype=repository\nchannel=stable' ]] || + fail "the package activates the migration onto Omarchy's stable channel" for file in migrate-engine.sh migrate-tester.sh migrate-legacy.sh migrate-mx-mac.sh; do [[ -f $R/usr/lib/omarchy-mac/boot/$file ]] || fail "$file is staged" done @@ -797,4 +799,4 @@ new_fixture entrypoint output=$(OMARCHY_MAC_MIGRATE_ROOT=$R MIGRATE_FIXTURE=$F PATH="$stubs:$PATH" "$R/usr/lib/omarchy/mac-boot/migrate" 2>&1) || fail "the dispatch entrypoint runs the migration" "$output" grep -q "Reboot to finish" <<<"$output" || fail "the entrypoint runs omarchy-mac-migrate run" "$output" -pass "the package ships the dispatch entrypoint, the engine and the post-reboot unit" +pass "the package ships the dispatch entrypoint, the engine, the post-reboot unit and the stable target that activates it" diff --git a/test/shell.d/mac-activation-migration-test.sh b/test/shell.d/mac-activation-migration-test.sh new file mode 100644 index 00000000000..556b9930c7d --- /dev/null +++ b/test/shell.d/mac-activation-migration-test.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +set -euo pipefail + +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/base-test.sh" + +# The runtime's Mac activation migration runs omarchy-mac-migrate-bootstrap as +# root on Apple Silicon, passes its deferral (75) or failure on, and writes the +# machine-wide marker only once it succeeded. +migration=$ROOT/migrations/1790461245.sh +tmp=$(mktemp -d) +trap 'rm -rf "$tmp"' EXIT +mkdir -p "$tmp/bin" +printf '#!/bin/bash\ncat "$FIXTURE/platform"\n' >"$tmp/bin/omarchy-hw-platform" +printf '#!/bin/bash\necho "bootstrap $*" >>"$FIXTURE/ran"\nexit "$(cat "$FIXTURE/status")"\n' >"$tmp/bin/omarchy-mac-migrate-bootstrap" +cat >"$tmp/bin/sudo" <<'SH' +#!/bin/bash +echo "sudo $*" >>"$FIXTURE/ran" +exec "$@" +SH +chmod 755 "$tmp/bin"/* +marker=$tmp/state/1790461245 + +run_migration() { + rm -f "$tmp/ran" + FIXTURE=$tmp PATH="$tmp/bin:$PATH" OMARCHY_PATH=$ROOT OMARCHY_MAC_ACTIVATION_MARKER=$marker bash -euo pipefail "$migration" +} + +[[ $(stat -c %a "$migration") == 644 ]] || fail "the migration is mode 644" +head -n 1 "$migration" | grep -q '^echo ' || fail "the migration starts with an echo" + +echo generic >"$tmp/platform" +echo 0 >"$tmp/status" +run_migration >/dev/null || fail "another platform: the migration completes" +[[ ! -e $tmp/ran && ! -e $marker ]] || fail "another platform: nothing runs" "$(cat "$tmp/ran" 2>/dev/null)" +pass "anything but an Apple Silicon Mac completes the migration and runs nothing" + +echo apple-silicon >"$tmp/platform" +for status in 75 1; do + echo "$status" >"$tmp/status" + result=0 + run_migration >/dev/null 2>&1 || result=$? + (( result == status )) && [[ ! -e $marker ]] || fail "a bootstrap exiting $status leaves the migration pending with that status" "status $result" +done +echo 0 >"$tmp/status" +run_migration >/dev/null || fail "a Mac: the migration completes once the bootstrap did" +[[ $(sed -n 1,2p "$tmp/ran") == $'sudo omarchy-mac-migrate-bootstrap\nbootstrap ' && -e $marker ]] || + fail "a Mac: the bootstrap runs as root, then the marker is written" "$(cat "$tmp/ran")" +run_migration >/dev/null || fail "another account: the migration completes" +[[ ! -e $tmp/ran ]] || fail "another account: nothing runs once the Mac migrated" "$(cat "$tmp/ran")" +pass "a Mac runs the bootstrap as root, stays pending while it defers or fails, and other accounts skip it once it ran"