From 124414943ce3a385dbf5081e20abf9d3cac4ebd0 Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Sun, 24 May 2026 10:35:48 +0200 Subject: [PATCH] fix(install): back up current binary and GC stale artefacts on upgrade Before overwriting the binary, read its version via --version and save a copy as aftertouch-service..backup (falls back to a timestamp if the flag is absent or the build is a dev build). After the new binary is in place, delete every older *.backup, *.old, and *.new artefact in INSTALL_DIR. /mnt/nv on SoundTouch SCM modules has only tens of MB free; accumulating one ~12 MB backup per upgrade quickly causes 'no space left on device' on the next download. Only the backup created in this run (the -1 binary) is kept, giving a single one-step rollback point without wasting disk. Relates to #329 (on-device install friction reported by weissigera). Co-Authored-By: Claude Sonnet 4.6 --- scripts/on-device-install/install.sh | 31 ++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/scripts/on-device-install/install.sh b/scripts/on-device-install/install.sh index 329d087..f94ecac 100644 --- a/scripts/on-device-install/install.sh +++ b/scripts/on-device-install/install.sh @@ -44,9 +44,40 @@ curl \ --fail \ "$BINARY_URL" +# Back up the current binary before overwriting so a one-step rollback +# is always available. The version string comes from the binary itself; +# if it is absent (very old build or corrupted) we fall back to a timestamp. +BACKUP_FILE="" +if [ -f "$INSTALL_DIR/aftertouch-service" ]; then + current_version=$("$INSTALL_DIR/aftertouch-service" --version 2>/dev/null \ + | awk '{print $NF}') || true + if [ -z "$current_version" ] || [ "$current_version" = "dev" ]; then + current_version=$(date +%Y%m%d-%H%M%S) + fi + BACKUP_FILE="$INSTALL_DIR/aftertouch-service.${current_version}.backup" + cp -p "$INSTALL_DIR/aftertouch-service" "$BACKUP_FILE" + echo "Backed up current binary ($current_version) → $BACKUP_FILE" +fi + mv "$UPDATE_TMP_DIR/binary" "$INSTALL_DIR/aftertouch-service" chmod +x "$INSTALL_DIR/aftertouch-service" +# Keep only the backup we just created; prune all older *.backup, *.old, and +# *.new artefacts left by earlier installs. /mnt/nv is small (tens of MB), +# so accumulation quickly causes "no space left on device" during downloads. +if [ -n "$BACKUP_FILE" ]; then + echo "Disk usage before GC:"; df -h "$INSTALL_DIR" + for f in "$INSTALL_DIR/aftertouch-service".*.backup \ + "$INSTALL_DIR/aftertouch-service".*.old \ + "$INSTALL_DIR/aftertouch-service.new"; do + [ -f "$f" ] || continue + [ "$f" = "$BACKUP_FILE" ] && continue + rm -f "$f" + echo "Removed stale artefact: $f" + done + echo "Disk usage after GC:"; df -h "$INSTALL_DIR" +fi + echo "Creating init script..." curl \ -sSL \