#!/usr/bin/env bash
# backup-maint/remove — delete this plan's scratch dir and restic cache (never the repository).
set -euo pipefail
P=$(cat)
plan=$(jq -r '.planId // empty' <<<"$P")
[[ "$plan" =~ ^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$ ]] || { echo "ERROR: invalid planId" >&2; exit 1; }
rm -rf "${SSR_BACKUP_STATE:-/var/lib/silvershell-backup}/scratch/$plan" "${SSR_BACKUP_CACHE:-/var/cache/silvershell-backup}/$plan"
echo '{}' > "$SSR_OUTPUTS"
