Files
OrbitTv/tools/restore-tv.sh
T
pauljdandClaude Opus 5.5 6dec924a83 Restore sends one zip, after a rehearsal on the TV found adb can't make folders there (0.108.109)
Rehearsal downstairs (8 November 2026): Android 14 lets adb put files only in a folder Orbit made, so 'prepare-restore'
makes install-restore/ and the PC sends restore.zip; the receiver unpacks only restore.txt and snapshot names (zip-slip
refused) and removes the pushed copy afterwards. The script restarts Orbit even if a step fails. Rehearsed end to end:
snapshot, restore of all 278 files, snapshot again: identical (the sign-in file is re-saved on every launch anyway).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-08 11:41:32 +00:00

28 lines
2.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Put a pulled Orbit snapshot back on a TV (8 November 2026, audit U12).
# tools/restore-tv.sh <adb-device> <snapshot-folder> e.g. 192.168.0.252:5555 backups/install-0.108.107-.../before
# The snapshot folder is one pulled by the install procedure (no_backup/schedule and shared_prefs inside it).
# Orbit is force-stopped first; the TV keeps what it had in no_backup/before-restore-<time> (the last two are kept).
# Only schedules, settings and profiles come back; never the library catalogue, the sign-in or the PIN.
set -euo pipefail
A=${ADB:-/opt/android-sdk/platform-tools/adb}; D=$1; SNAP=$(cd "$2" && pwd)
[ -d "$SNAP/no_backup/schedule" ] || { echo "Not a snapshot folder: $SNAP"; exit 1; }
REMOTE=/sdcard/Android/data/tv.orbit.classic/files/install-restore
STAGE=$(mktemp -d); trap 'rm -rf "$STAGE"; $A -s "$D" shell am start -n tv.orbit.classic/.MainActivity >/dev/null 2>&1 || true' EXIT
( cd "$SNAP" && find no_backup/schedule -type f; for p in shared_prefs/orbit_settings.xml shared_prefs/orbit_profiles.xml; do [ -f "$p" ] && echo "$p"; done ) | sort > "$STAGE/list"
( cd "$SNAP" && xargs -d '\n' sha256sum < "$STAGE/list" ) > "$STAGE/restore.txt"
echo "restoring $(wc -l < "$STAGE/list") files from $SNAP"
read -r -p "Type RESTORE to put this snapshot back on $D: " ok; [ "$ok" = "RESTORE" ] || { echo "Not restored."; exit 1; }
( cd "$SNAP" && python3 -I -c 'import sys,zipfile
z=zipfile.ZipFile(sys.argv[1],"w",zipfile.ZIP_DEFLATED)
[z.write(p.strip(),p.strip()) for p in open(sys.argv[2]) if p.strip()]
z.write(sys.argv[3],"restore.txt"); z.close()' "$STAGE/restore.zip" "$STAGE/list" "$STAGE/restore.txt" )
$A -s "$D" shell am force-stop tv.orbit.classic
R="$A -s $D shell am broadcast -f 0x20 -n tv.orbit.classic/.InstallSnapshotReceiver -a tv.orbit.classic.INSTALL_SNAPSHOT"
$R --es do prepare-restore | grep -q 'data="ready"' || { echo "The TV couldn't get ready; nothing changed."; $A -s "$D" shell am start -n tv.orbit.classic/.MainActivity >/dev/null; exit 1; }
$A -s "$D" push "$STAGE/restore.zip" "$REMOTE/restore.zip" >/dev/null
$R --es do restore --es confirm RESTORE | grep -o 'data="[^"]*"'
$A -s "$D" shell am force-stop tv.orbit.classic
$A -s "$D" shell am start -n tv.orbit.classic/.MainActivity >/dev/null
echo "Orbit restarted. Take a snapshot and compare it with $SNAP to check."