#!/bin/sh
set -eu

BOOT="/boot"
OTA="$BOOT/ota"
CYCLE_MARKER="/run/signage-cycle-complete"

mountpoint -q "$BOOT" || mount "$BOOT"

if [ -f "$OTA/pending-root" ]; then
	echo "[OTA] Waiting for signage to complete a full playlist cycle..."
	while [ ! -f "$CYCLE_MARKER" ]; do
		sleep 5
	done
	echo "[OTA] Signage completed a full playlist cycle"
fi

rm -f "$OTA/rollback.flag"
rm -f "$OTA/pending-root"
rm -f "$OTA/previous-root"

sync
