#!/bin/sh
set -eu

BOOT="/boot"
OTA="$BOOT/ota"

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

mkdir -p "$OTA"

rm -f "$OTA/rollback.flag"
rm -f "$OTA/pending-root"
rm -f "$OTA/previous-root"
rm -f "$OTA/attempted-root"
rm -f "$OTA/pending-label"
rm -f "$OTA/pending-partition"
rm -f "$OTA/staged-at"
rm -f "$OTA/boot-attempts"


if [ -f "$OTA/last-booted-root" ]; then
	cp "$OTA/last-booted-root" "$OTA/current-root"
fi

date -u +"%Y-%m-%dT%H:%M:%SZ" > "$OTA/last-good-boot"

sync
