From 7ca3d4f2d47b7a5d737b80f1326a139d3428de0f Mon Sep 17 00:00:00 2001 From: ruihan Date: Fri, 30 Oct 2026 03:56:14 -0300 Subject: [PATCH 1/4] fix(suppression): preserve access to Rosetta configuration --- lib/suppress.sh | 1 - tests/test_rosetta.bats | 19 +++++++++++++++++++ unleash-standalone.sh | 1 - 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 tests/test_rosetta.bats diff --git a/lib/suppress.sh b/lib/suppress.sh index 2c513f5..223d54d 100644 --- a/lib/suppress.sh +++ b/lib/suppress.sh @@ -50,7 +50,6 @@ suppress_enrollment() { gdmf.apple.com ax.init-content.apple.com init-content.apple.com - configuration.apple.com xp.apple.com gs.apple.com tb.apple.com diff --git a/tests/test_rosetta.bats b/tests/test_rosetta.bats new file mode 100644 index 0000000..1403de8 --- /dev/null +++ b/tests/test_rosetta.bats @@ -0,0 +1,19 @@ +#!/usr/bin/env bats + +@test "suppression does not add hosts blocks for Rosetta configuration" { + local entrypoint + for entrypoint in unleash unleash-standalone.sh; do + local script="$BATS_TEST_DIRNAME/../$entrypoint" + local target="$BATS_TEST_TMPDIR/$entrypoint" + mkdir -p "$target/private/etc" + printf '127.0.0.1 localhost\n' > "$target/private/etc/hosts" + run bash -u -c ' + source <(sed '\''/^main "\$@"$/d'\'' "$1") + PB=: + suppress_enrollment "$2" + ' "$script" "$script" "$target" + [ "$status" -eq 0 ] + ! grep -q 'configuration[.]apple[.]com' "$target/private/etc/hosts" + grep -q '^127.0.0.1 localhost$' "$target/private/etc/hosts" + done +} diff --git a/unleash-standalone.sh b/unleash-standalone.sh index 347311c..ea129e0 100755 --- a/unleash-standalone.sh +++ b/unleash-standalone.sh @@ -459,7 +459,6 @@ suppress_enrollment() { gdmf.apple.com ax.init-content.apple.com init-content.apple.com - configuration.apple.com xp.apple.com gs.apple.com tb.apple.com From 993db74118030a947074e6ffce1b563858b4f9fc Mon Sep 17 00:00:00 2001 From: ruihan Date: Fri, 30 Oct 2026 03:56:33 -0300 Subject: [PATCH 2/4] test(suppression): assert the Rosetta block lookup status --- tests/test_rosetta.bats | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/test_rosetta.bats b/tests/test_rosetta.bats index 1403de8..2999dbf 100644 --- a/tests/test_rosetta.bats +++ b/tests/test_rosetta.bats @@ -13,7 +13,8 @@ suppress_enrollment "$2" ' "$script" "$script" "$target" [ "$status" -eq 0 ] - ! grep -q 'configuration[.]apple[.]com' "$target/private/etc/hosts" + run grep -q 'configuration[.]apple[.]com' "$target/private/etc/hosts" + [ "$status" -eq 1 ] grep -q '^127.0.0.1 localhost$' "$target/private/etc/hosts" done } From f84fe0986ba51d387921553aa3710cd71e12cb96 Mon Sep 17 00:00:00 2001 From: ruihan Date: Fri, 30 Oct 2026 04:27:44 -0300 Subject: [PATCH 3/4] fix(suppression): repair generated Rosetta hosts blocks --- lib/suppress.sh | 24 +++++++++++++++++++ tests/test_rosetta.bats | 52 ++++++++++++++++++++++++++++++++++++----- unleash-standalone.sh | 24 +++++++++++++++++++ 3 files changed, 94 insertions(+), 6 deletions(-) diff --git a/lib/suppress.sh b/lib/suppress.sh index ff5a720..6014a84 100644 --- a/lib/suppress.sh +++ b/lib/suppress.sh @@ -2,6 +2,29 @@ PB="${PB:-/usr/libexec/PlistBuddy}" +_restore_rosetta_hosts() { + local hosts="$1" tmp_hosts + tmp_hosts=$(mktemp "${hosts}.XXXXXX") || return 1 + if ! cp -p "$hosts" "$tmp_hosts" || ! awk ' + $0=="# Added by unleash — DEP enrollment block" { owned=1; print; next } + owned && /^(0[.]0[.]0[.]0|::)[[:space:]]+configuration[.]apple[.]com[[:space:]]*$/ { next } + owned && $0 !~ /^(0[.]0[.]0[.]0|::)[[:space:]]+[[:alnum:]_.-]+[[:space:]]*$/ { owned=0 } + { print } + ' "$hosts" > "$tmp_hosts"; then + rm -f "$tmp_hosts" + return 1 + fi + if cmp -s "$hosts" "$tmp_hosts"; then + rm -f "$tmp_hosts" + return 0 + fi + if [ ! -e "$hosts.unleash-rosetta.bak" ]; then + cp -p "$hosts" "$hosts.unleash-rosetta.bak" || { rm -f "$tmp_hosts"; return 1; } + fi + mv "$tmp_hosts" "$hosts" || { rm -f "$tmp_hosts"; return 1; } + info "Removed old Unleash Rosetta blocks; backup: $hosts.unleash-rosetta.bak" +} + suppress_enrollment() { local data_mount="$1" @@ -35,6 +58,7 @@ suppress_enrollment() { step "Blocking enrollment domains (Data volume hosts)..." [ -f "$hosts" ] || { mkdir -p "$(dirname "$hosts")"; touch "$hosts"; } + _restore_rosetta_hosts "$hosts" || error_exit "Could not repair old Rosetta hosts blocks." grep -q "Added by unleash" "$hosts" 2>/dev/null || { echo "" >>"$hosts" echo "# Added by unleash — DEP enrollment block" >>"$hosts" diff --git a/tests/test_rosetta.bats b/tests/test_rosetta.bats index 2999dbf..e1e4b5c 100644 --- a/tests/test_rosetta.bats +++ b/tests/test_rosetta.bats @@ -1,5 +1,15 @@ #!/usr/bin/env bats +suppress_fixture() { + local script="$1" target="$2" + run bash -u -c ' + source <(sed '\''/^main "\$@"$/d'\'' "$1") + PB=: + suppress_enrollment "$2" + ' "$script" "$script" "$target" + [ "$status" -eq 0 ] +} + @test "suppression does not add hosts blocks for Rosetta configuration" { local entrypoint for entrypoint in unleash unleash-standalone.sh; do @@ -7,14 +17,44 @@ local target="$BATS_TEST_TMPDIR/$entrypoint" mkdir -p "$target/private/etc" printf '127.0.0.1 localhost\n' > "$target/private/etc/hosts" - run bash -u -c ' - source <(sed '\''/^main "\$@"$/d'\'' "$1") - PB=: - suppress_enrollment "$2" - ' "$script" "$script" "$target" - [ "$status" -eq 0 ] + suppress_fixture "$script" "$target" run grep -q 'configuration[.]apple[.]com' "$target/private/etc/hosts" [ "$status" -eq 1 ] grep -q '^127.0.0.1 localhost$' "$target/private/etc/hosts" done } + +@test "suppression repairs its old Rosetta blocks with an unchanged backup on rerun" { + local entrypoint + for entrypoint in unleash unleash-standalone.sh; do + local script="$BATS_TEST_DIRNAME/../$entrypoint" + local target="$BATS_TEST_TMPDIR/$entrypoint" hosts + hosts="$target/private/etc/hosts" + mkdir -p "$(dirname "$hosts")" + printf '127.0.0.1 localhost\n# Added by unleash — DEP enrollment block\n0.0.0.0 configuration.apple.com\n:: configuration.apple.com\n' > "$hosts" + cp "$hosts" "$target/original" + suppress_fixture "$script" "$target" + run grep -q 'configuration[.]apple[.]com' "$hosts" + [ "$status" -eq 1 ] + cmp "$target/original" "$hosts.unleash-rosetta.bak" + cp "$hosts" "$target/repaired" + suppress_fixture "$script" "$target" + cmp "$target/repaired" "$hosts" + cmp "$target/original" "$hosts.unleash-rosetta.bak" + done +} + +@test "suppression preserves Rosetta blocks outside its generated section" { + local entrypoint + for entrypoint in unleash unleash-standalone.sh; do + local script="$BATS_TEST_DIRNAME/../$entrypoint" + local target="$BATS_TEST_TMPDIR/$entrypoint" hosts + hosts="$target/private/etc/hosts" + mkdir -p "$(dirname "$hosts")" + printf '0.0.0.0 configuration.apple.com\n:: configuration.apple.com manual.alias\n' > "$hosts" + suppress_fixture "$script" "$target" + grep -Fxq '0.0.0.0 configuration.apple.com' "$hosts" + grep -Fxq ':: configuration.apple.com manual.alias' "$hosts" + [ ! -e "$hosts.unleash-rosetta.bak" ] + done +} diff --git a/unleash-standalone.sh b/unleash-standalone.sh index 6456ccf..4beacf1 100755 --- a/unleash-standalone.sh +++ b/unleash-standalone.sh @@ -425,6 +425,29 @@ add_to_filevault() { PB="${PB:-/usr/libexec/PlistBuddy}" +_restore_rosetta_hosts() { + local hosts="$1" tmp_hosts + tmp_hosts=$(mktemp "${hosts}.XXXXXX") || return 1 + if ! cp -p "$hosts" "$tmp_hosts" || ! awk ' + $0=="# Added by unleash — DEP enrollment block" { owned=1; print; next } + owned && /^(0[.]0[.]0[.]0|::)[[:space:]]+configuration[.]apple[.]com[[:space:]]*$/ { next } + owned && $0 !~ /^(0[.]0[.]0[.]0|::)[[:space:]]+[[:alnum:]_.-]+[[:space:]]*$/ { owned=0 } + { print } + ' "$hosts" > "$tmp_hosts"; then + rm -f "$tmp_hosts" + return 1 + fi + if cmp -s "$hosts" "$tmp_hosts"; then + rm -f "$tmp_hosts" + return 0 + fi + if [ ! -e "$hosts.unleash-rosetta.bak" ]; then + cp -p "$hosts" "$hosts.unleash-rosetta.bak" || { rm -f "$tmp_hosts"; return 1; } + fi + mv "$tmp_hosts" "$hosts" || { rm -f "$tmp_hosts"; return 1; } + info "Removed old Unleash Rosetta blocks; backup: $hosts.unleash-rosetta.bak" +} + suppress_enrollment() { local data_mount="$1" @@ -458,6 +481,7 @@ suppress_enrollment() { step "Blocking enrollment domains (Data volume hosts)..." [ -f "$hosts" ] || { mkdir -p "$(dirname "$hosts")"; touch "$hosts"; } + _restore_rosetta_hosts "$hosts" || error_exit "Could not repair old Rosetta hosts blocks." grep -q "Added by unleash" "$hosts" 2>/dev/null || { echo "" >>"$hosts" echo "# Added by unleash — DEP enrollment block" >>"$hosts" From e1d0045ab086f2babd6c55e8360cdeadf38b4599 Mon Sep 17 00:00:00 2001 From: ruihan Date: Fri, 30 Oct 2026 04:32:35 -0300 Subject: [PATCH 4/4] fix(heal): restore Rosetta access on intact installations --- lib/heal.sh | 4 ++++ tests/test_rosetta.bats | 36 +++++++++++++++++++++++++++++++++--- unleash-standalone.sh | 4 ++++ 3 files changed, 41 insertions(+), 3 deletions(-) diff --git a/lib/heal.sh b/lib/heal.sh index cfa8567..718e3b5 100644 --- a/lib/heal.sh +++ b/lib/heal.sh @@ -8,6 +8,10 @@ heal_suppress() { local hosts="${data_mount}/private/etc/hosts" local ldp="${data_mount}/private/var/db/com.apple.xpc.launchd/disabled.plist" + if [ "$DRY_RUN" != true ] && [ -f "$hosts" ]; then + _restore_rosetta_hosts "$hosts" || error_exit "Could not repair old Rosetta hosts blocks." + fi + local needs_heal=false if [ -f "$cfg/.cloudConfigRecordFound" ]; then diff --git a/tests/test_rosetta.bats b/tests/test_rosetta.bats index e1e4b5c..869bc2c 100644 --- a/tests/test_rosetta.bats +++ b/tests/test_rosetta.bats @@ -2,14 +2,44 @@ suppress_fixture() { local script="$1" target="$2" + local action="${3:-suppress_enrollment}" simulation="${4:-false}" run bash -u -c ' source <(sed '\''/^main "\$@"$/d'\'' "$1") - PB=: - suppress_enrollment "$2" - ' "$script" "$script" "$target" + DRY_RUN="$4" + "$3" "$2" + ' "$script" "$script" "$target" "$action" "$simulation" [ "$status" -eq 0 ] } +@test "heal repairs old Rosetta blocks even when suppression is otherwise intact" { + local entrypoint + for entrypoint in unleash unleash-standalone.sh; do + local script="$BATS_TEST_DIRNAME/../$entrypoint" + local target="$BATS_TEST_TMPDIR/$entrypoint" hosts + hosts="$target/private/etc/hosts" + suppress_fixture "$script" "$target" + printf '0.0.0.0 configuration.apple.com\n:: configuration.apple.com\n' >> "$hosts" + suppress_fixture "$script" "$target" heal_suppress + run grep -q 'configuration[.]apple[.]com' "$hosts" + [ "$status" -eq 1 ] + done +} + +@test "heal dry run preserves old Rosetta entries" { + local entrypoint + for entrypoint in unleash unleash-standalone.sh; do + local script="$BATS_TEST_DIRNAME/../$entrypoint" + local target="$BATS_TEST_TMPDIR/$entrypoint" hosts + hosts="$target/private/etc/hosts" + suppress_fixture "$script" "$target" + printf '0.0.0.0 configuration.apple.com\n:: configuration.apple.com\n' >> "$hosts" + cp "$hosts" "$target/original" + suppress_fixture "$script" "$target" heal_suppress true + cmp "$target/original" "$hosts" + [ ! -e "$hosts.unleash-rosetta.bak" ] + done +} + @test "suppression does not add hosts blocks for Rosetta configuration" { local entrypoint for entrypoint in unleash unleash-standalone.sh; do diff --git a/unleash-standalone.sh b/unleash-standalone.sh index 4beacf1..6904e9d 100755 --- a/unleash-standalone.sh +++ b/unleash-standalone.sh @@ -990,6 +990,10 @@ heal_suppress() { local hosts="${data_mount}/private/etc/hosts" local ldp="${data_mount}/private/var/db/com.apple.xpc.launchd/disabled.plist" + if [ "$DRY_RUN" != true ] && [ -f "$hosts" ]; then + _restore_rosetta_hosts "$hosts" || error_exit "Could not repair old Rosetta hosts blocks." + fi + local needs_heal=false if [ -f "$cfg/.cloudConfigRecordFound" ]; then