From eae3cd2b15d925ffc37b96eb82b5e7cd695fd0e0 Mon Sep 17 00:00:00 2001 From: Haroun EL ALAMI Date: Fri, 29 May 2026 03:44:34 +0200 Subject: [PATCH] refactor: self-contained install functions in first-boot.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each install (gapps, root, arm_translation) is now responsible for its own reboot + wait + done-marker sequence, in that order. The marker is only written once adbd has come back, so a container killed mid-reboot won't leave a "marked done but not applied" state. - Drop the needs_reboot() helper; the reboot decision is now local to each install function instead of crossing function boundaries. - Collapse the duplicate first-boot / post-first-boot branches in main into one path — only AVD creation is conditional on /data/.first-boot-done. - install_gapps and install_arm_translation now end with 'adb reboot; adb wait-for-device; touch .-done', so they are safe to invoke standalone after the initial first boot when a flag is flipped on a previously initialized container. One extra AVD reboot occurs in the rare case where both GAPPS and ARM_TRANSLATION are enabled in the same pass (~25s), traded for the cleaner per-function encapsulation. --- first-boot.sh | 36 ++++++++++++------------------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/first-boot.sh b/first-boot.sh index e529d04..1a4fdae 100755 --- a/first-boot.sh +++ b/first-boot.sh @@ -56,6 +56,8 @@ install_gapps() { adb push gapps-11/app /system adb push gapps-11/priv-app /system rm -r gapps-11 + adb reboot + adb wait-for-device touch /data/.gapps-done } @@ -109,6 +111,7 @@ EOF ' adb reboot + adb wait-for-device touch /data/.arm-translation-done } @@ -132,32 +135,17 @@ if bool_true "$GAPPS_SETUP" && [ ! -f /data/.gapps-done ]; then gapps_needed=tru if bool_true "$ROOT_SETUP" && [ ! -f /data/.root-done ]; then root_needed=true; fi if bool_true "$ARM_TRANSLATION" && [ ! -f /data/.arm-translation-done ]; then arm_translation_needed=true; fi -needs_reboot() { - # Reboot needed if only GAPPS was installed (no root or ARM translation) - [ "$gapps_needed" = true ] && [ "$root_needed" = false ] && [ "$arm_translation_needed" = false ] -} - -# Skip initialization if first boot already completed. -if [ -f /data/.first-boot-done ]; then - if [ "$gapps_needed" = true ]; then - install_gapps - needs_reboot && adb reboot - fi - [ "$root_needed" = true ] && install_root - [ "$arm_translation_needed" = true ] && install_arm_translation - apply_settings - copy_extras - exit 0 +# Create the AVD on first boot only. +if [ ! -f /data/.first-boot-done ]; then + echo "Init AVD ..." + echo "no" | avdmanager create avd -n android -k "system-images;android-30;default;x86_64" fi -echo "Init AVD ..." -echo "no" | avdmanager create avd -n android -k "system-images;android-30;default;x86_64" - -if [ "$gapps_needed" = true ]; then - install_gapps - needs_reboot && adb reboot -fi -[ "$root_needed" = true ] && install_root +# Each install is self-contained: prepares the system, applies its changes, +# reboots, waits for adbd, then writes its done-marker. Safe to run after the +# first boot — only the missing markers will fire. +[ "$gapps_needed" = true ] && install_gapps +[ "$root_needed" = true ] && install_root [ "$arm_translation_needed" = true ] && install_arm_translation apply_settings copy_extras