#!/bin/sh
# adacam-pair — open a ONE-SHOT pairing window on the device.
#
# While the window is open, GET /pair returns the device's random API token
# exactly once, then the window closes automatically. Run this on the device
# (over the local console / SSH) whenever you want to (re)pair the Varroa app.
#
# This is the physical-presence gate that replaces the old broken scheme where
# the token was derivable from the unauthenticated serial.
set -eu
mkdir -p /data/adacam
: > /data/adacam/pairing_open
chmod 600 /data/adacam/pairing_open 2>/dev/null || true
echo "Pairing window OPEN."
echo "Open the Varroa app and pair now — the window closes after one successful pair."
echo "If you don't pair, close it manually with:  rm -f /data/adacam/pairing_open"
