A rootless Android app that boots Alpine Linux: run containers (Podman/Docker/LXC) and GUI desktop apps.
feat(rootfs): add podroid-migrate service for versioned guest migrations
ExTvee2ec4fce647
diff --git a/build-rootfs/build-rootfs.sh b/build-rootfs/build-rootfs.shindex 456b0d0..83cd7d6 100755--- a/build-rootfs/build-rootfs.sh+++ b/build-rootfs/build-rootfs.sh@@ -104,6 +104,7 @@ cp /work/files/etc/init.d/podroid-ready "$ROOTFS/etc/init.d/"cp /work/files/etc/init.d/podroid-x11 "$ROOTFS/etc/init.d/"cp /work/files/etc/init.d/podroid-vsock "$ROOTFS/etc/init.d/"cp /work/files/etc/init.d/podroid-hostd "$ROOTFS/etc/init.d/"+cp /work/files/etc/init.d/podroid-migrate "$ROOTFS/etc/init.d/"chmod +x "$ROOTFS/etc/init.d/podroid-"*# Copy /usr/local/bin scripts (resize daemon + login wrapper + getty selector)@@ -133,6 +134,9 @@ cp /work/files/etc/conf.d/podroid "$ROOTFS/etc/conf.d/"mkdir -p "$ROOTFS/etc/podroid"cp /work/files/etc/podroid/forwards.conf "$ROOTFS/etc/podroid/forwards.conf"chmod 0644 "$ROOTFS/etc/podroid/forwards.conf"+# Migration scripts dir (seeded with its README; per-version <v>.sh added over time).+mkdir -p "$ROOTFS/etc/podroid/migrations"+cp /work/files/etc/podroid/migrations/README "$ROOTFS/etc/podroid/migrations/README"# System-version stamp: the migration anchor. Baked from the app versionCode at# build time; compared against /mnt/persist/.podroid/applied-version at boot.printf '%s\n' "${SYSTEM_VERSION:-0}" > "$ROOTFS/etc/podroid/system-version"@@ -181,7 +185,7 @@ mkdir -p "$ROOTFS/etc/runlevels/default" "$ROOTFS/etc/runlevels/boot"# Guard each link: a dangling symlink (e.g. dnsmasq.lxcbr0, which lxc-bridge# may ship only as dnsmasq config and not an init script) makes OpenRC log# an error every boot and stalls podroid-ready's `after *` on a phantom.-for svc in podroid-bootstrap podroid-network podroid-resize dropbear docker lxc dnsmasq.lxcbr0 podroid-x11 podroid-vsock podroid-hostd podroid-ready; do+for svc in podroid-migrate podroid-bootstrap podroid-network podroid-resize dropbear docker lxc dnsmasq.lxcbr0 podroid-x11 podroid-vsock podroid-hostd podroid-ready; doif [ -e "$ROOTFS/etc/init.d/$svc" ]; thenln -sf "/etc/init.d/$svc" "$ROOTFS/etc/runlevels/default/$svc"elsediff --git a/build-rootfs/files/etc/init.d/podroid-migrate b/build-rootfs/files/etc/init.d/podroid-migratenew file mode 100644index 0000000..58566d3--- /dev/null+++ b/build-rootfs/files/etc/init.d/podroid-migrate@@ -0,0 +1,52 @@+#!/sbin/openrc-run+description="Podroid system migrations (runs versioned upgrade scripts once)"++# Run early, before the rest of Podroid bringup, so migrations can prepare state+# the other services rely on. localmount is already satisfied (initramfs mounted+# /mnt/persist), but we declare it for ordering correctness.+depend() {+ need localmount+ before podroid-bootstrap+}++SYSVER_FILE="/etc/podroid/system-version"+APPLIED_FILE="/mnt/persist/.podroid/applied-version"+MIGRATIONS_DIR="/etc/podroid/migrations"++start() {+ ebegin "Running Podroid migrations"+ mkdir -p /mnt/persist/.podroid++ current=$(cat "$SYSVER_FILE" 2>/dev/null || echo 0)+ applied=$(cat "$APPLIED_FILE" 2>/dev/null || echo "")++ # Fresh install (no marker): seed the marker, run nothing — the squashfs+ # already ships the current state.+ if [ -z "$applied" ]; then+ printf '%s\n' "$current" > "$APPLIED_FILE.tmp" && mv "$APPLIED_FILE.tmp" "$APPLIED_FILE"+ eend 0+ return 0+ fi++ # Fast path / downgrade: nothing to do.+ if [ "$current" -le "$applied" ] 2>/dev/null; then+ eend 0+ return 0+ fi++ # Run each migrations/<v>.sh with applied < v <= current, in ascending+ # numeric order (sort the basenames, not full paths). Scripts MUST be+ # idempotent (a crash mid-run re-runs them next boot).+ for base in $(ls "$MIGRATIONS_DIR" 2>/dev/null | sed -n 's/\.sh$//p' | sort -n); do+ case "$base" in *[!0-9]*) continue ;; esac # digits only+ if [ "$base" -gt "$applied" ] 2>/dev/null && [ "$base" -le "$current" ] 2>/dev/null; then+ echo "podroid-migrate: applying $base" > /dev/console+ sh "$MIGRATIONS_DIR/$base.sh" > /dev/console 2>&1 \+ || echo "podroid-migrate: $base failed (continuing)" > /dev/console+ fi+ done++ # Advance the marker atomically only after the loop completes.+ printf '%s\n' "$current" > "$APPLIED_FILE.tmp" && mv "$APPLIED_FILE.tmp" "$APPLIED_FILE"+ eend 0+}diff --git a/build-rootfs/files/etc/podroid/migrations/README b/build-rootfs/files/etc/podroid/migrations/READMEnew file mode 100644index 0000000..9163835--- /dev/null+++ b/build-rootfs/files/etc/podroid/migrations/README@@ -0,0 +1,16 @@+Podroid migration scripts.++podroid-migrate (OpenRC) runs each <version>.sh here exactly once, when the+guest upgrades across that version: it executes every <v>.sh with+ applied-version < v <= system-version+in ascending numeric order, then records system-version as the new+applied-version. <version> is the app versionCode the change shipped in.++Rules:+ - Name files <versionCode>.sh (digits only), e.g. 27.sh.+ - Scripts MUST be idempotent: a crash mid-migration re-runs them next boot,+ and a fresh install never runs them at all (it seeds the marker instead).+ - Use for imperative fixups a file-union can't express, e.g.:+ rc-update -u add my-new-service default # enable a newly-added service+ rm -f /etc/something-deprecated.conf # retire a stale config+ - Do NOT delete user data. Keep them small and reversible-in-spirit.