#!/usr/bin/env bash
# Bench only. SSH this onto a workshop Pi. Never a field / HTTP control.
# Sets ~/EtherGold/sync/rclone.env OTA_CHANNEL=dev (SGVI/dev).
set -euo pipefail
RCLONE_ENV="/home/topbox/EtherGold/sync/rclone.env"
if [[ ! -f "${RCLONE_ENV}" ]]; then
  echo "FATAL: missing ${RCLONE_ENV}" >&2
  exit 1
fi
chmod 600 "${RCLONE_ENV}"
python3 - "${RCLONE_ENV}" <<'PY'
from pathlib import Path
import sys
p = Path(sys.argv[1])
text = p.read_text(encoding="utf-8")
lines = text.splitlines(True)
out = []
found = False
for line in lines:
    if line.startswith("OTA_CHANNEL="):
        out.append("OTA_CHANNEL=dev\n")
        found = True
    else:
        out.append(line)
if not found:
    if out and not out[-1].endswith("\n"):
        out[-1] = out[-1] + "\n"
    out.append("OTA_CHANNEL=dev\n")
p.write_text("".join(out), encoding="utf-8")
print("wrote OTA_CHANNEL=dev")
PY
grep -E '^OTA_CHANNEL=' "${RCLONE_ENV}"
