BetterFrame/deploy/systemd/betterframe-expand-data.sh
Mitchell R 0c74e26e42
feat: expand BF_DATA on first boot + wire update progress banner + partition reporting
- Add betterframe-expand-data systemd service: growpart + resize2fs on
  BF_DATA (last partition) so it fills the full SD card on first boot.
  Solves the "No space left on device" issue with OS update downloads.
- Change OS update staging dir from /var/tmp/betterframe to
  /var/lib/betterframe/tmp (on BF_DATA partition, not rootfs).
- Wire firmware and OS update progress callbacks into the GTK overlay
  banner — shows "OS Update v1.2.3: Downloading — 45%" etc.
- Add per-partition disk reporting in heartbeat (/, /boot/firmware,
  /var/lib/betterframe) with total/used/free/percent.
- Display partition table on kiosk detail page in admin UI.
- PG + SQLite migrations for partitions_json column on kiosks.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-26 08:09:20 +02:00

54 lines
1.7 KiB
Bash

#!/bin/bash
# Expand BF_DATA (last partition) to fill the SD card on first boot.
# BF_DATA is mounted at /var/lib/betterframe. On a fresh image it's ~512MB;
# after expansion it fills whatever SD card size the operator used.
#
# Safe to re-run: growpart is idempotent (exits 0 "NOCHANGE" if already grown),
# and the marker file prevents systemd from re-invoking after success.
set -euo pipefail
MARKER="/var/lib/betterframe/.data-expanded"
MOUNTPOINT="/var/lib/betterframe"
if [ -f "$MARKER" ]; then
echo "BF_DATA already expanded, skipping."
exit 0
fi
# Find the block device backing BF_DATA from the mount table.
DATA_DEV="$(findmnt -n -o SOURCE "$MOUNTPOINT" 2>/dev/null || true)"
if [ -z "$DATA_DEV" ]; then
echo "WARNING: $MOUNTPOINT not mounted, cannot expand. Skipping."
exit 0
fi
# Extract disk + partition number (e.g. /dev/mmcblk0p5 → /dev/mmcblk0 + 5).
if [[ "$DATA_DEV" =~ ^(/dev/mmcblk[0-9]+)p([0-9]+)$ ]]; then
DISK="${BASH_REMATCH[1]}"
PARTNUM="${BASH_REMATCH[2]}"
elif [[ "$DATA_DEV" =~ ^(/dev/sd[a-z]+)([0-9]+)$ ]]; then
DISK="${BASH_REMATCH[1]}"
PARTNUM="${BASH_REMATCH[2]}"
else
echo "WARNING: cannot parse device $DATA_DEV, skipping expansion."
exit 0
fi
echo "Expanding partition ${DISK}p${PARTNUM} (BF_DATA) to fill disk..."
# growpart expands the partition to use all trailing free space.
# Exit code 0 = grown, 1 = error, NOCHANGE printed if already at max.
if ! growpart "$DISK" "$PARTNUM"; then
echo "growpart returned non-zero (may already be at max size)."
fi
# Inform the kernel of the new partition size.
partprobe "$DISK" 2>/dev/null || true
# Resize the ext4 filesystem to fill the expanded partition.
resize2fs "$DATA_DEV"
# Drop marker so this doesn't run again.
touch "$MARKER"
echo "BF_DATA expanded successfully."