Skip to content

Commit c0aa391

Browse files
authored
refactor: self-contained install functions in first-boot.sh (#50)
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 .<addon>-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.
1 parent 00f37c6 commit c0aa391

1 file changed

Lines changed: 12 additions & 24 deletions

File tree

first-boot.sh

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ install_gapps() {
5656
adb push gapps-11/app /system
5757
adb push gapps-11/priv-app /system
5858
rm -r gapps-11
59+
adb reboot
60+
adb wait-for-device
5961
touch /data/.gapps-done
6062
}
6163

@@ -109,6 +111,7 @@ EOF
109111
'
110112

111113
adb reboot
114+
adb wait-for-device
112115
touch /data/.arm-translation-done
113116
}
114117

@@ -132,32 +135,17 @@ if bool_true "$GAPPS_SETUP" && [ ! -f /data/.gapps-done ]; then gapps_needed=tru
132135
if bool_true "$ROOT_SETUP" && [ ! -f /data/.root-done ]; then root_needed=true; fi
133136
if bool_true "$ARM_TRANSLATION" && [ ! -f /data/.arm-translation-done ]; then arm_translation_needed=true; fi
134137

135-
needs_reboot() {
136-
# Reboot needed if only GAPPS was installed (no root or ARM translation)
137-
[ "$gapps_needed" = true ] && [ "$root_needed" = false ] && [ "$arm_translation_needed" = false ]
138-
}
139-
140-
# Skip initialization if first boot already completed.
141-
if [ -f /data/.first-boot-done ]; then
142-
if [ "$gapps_needed" = true ]; then
143-
install_gapps
144-
needs_reboot && adb reboot
145-
fi
146-
[ "$root_needed" = true ] && install_root
147-
[ "$arm_translation_needed" = true ] && install_arm_translation
148-
apply_settings
149-
copy_extras
150-
exit 0
138+
# Create the AVD on first boot only.
139+
if [ ! -f /data/.first-boot-done ]; then
140+
echo "Init AVD ..."
141+
echo "no" | avdmanager create avd -n android -k "system-images;android-30;default;x86_64"
151142
fi
152143

153-
echo "Init AVD ..."
154-
echo "no" | avdmanager create avd -n android -k "system-images;android-30;default;x86_64"
155-
156-
if [ "$gapps_needed" = true ]; then
157-
install_gapps
158-
needs_reboot && adb reboot
159-
fi
160-
[ "$root_needed" = true ] && install_root
144+
# Each install is self-contained: prepares the system, applies its changes,
145+
# reboots, waits for adbd, then writes its done-marker. Safe to run after the
146+
# first boot — only the missing markers will fire.
147+
[ "$gapps_needed" = true ] && install_gapps
148+
[ "$root_needed" = true ] && install_root
161149
[ "$arm_translation_needed" = true ] && install_arm_translation
162150
apply_settings
163151
copy_extras

0 commit comments

Comments
 (0)