#!/usr/bin/env bash # Host-side fleet helper. Mints a random 6-digit claim code per kit, writes the # per-board env file each Uno Q needs (apess-node.env), and emits a printable # CSV (kit, code, claim_url) for the QR stickers. # # FLEET_SECRET=... APESS_URL=https://apess-api.redclaw.dev \ # APESS_WEB=https://apess.redclaw.dev ./gen-kit-codes.sh 15 [out-dir] # # Then, per board: copy out/env/KIT-NN.env → the board's # /home/arduino/.zeroclaw/apess-node.env, and encode the claim_url in its QR # sticker (scanning it lands on /workshop?kit=..&code=.. with both pre-filled). set -euo pipefail N="${1:-15}" OUT="${2:-./kit-codes}" FLEET_SECRET="${FLEET_SECRET:?set FLEET_SECRET (the shared fleet secret, == APESS FLEET_SECRET)}" APESS_URL="${APESS_URL:-https://apess-api.redclaw.dev}" APESS_WEB="${APESS_WEB:-https://apess.redclaw.dev}" mkdir -p "$OUT/env" echo "kit,code,claim_url" > "$OUT/kit-codes.csv" for i in $(seq 1 "$N"); do kit=$(printf "KIT-%02d" "$i") # 3 random bytes → hex → integer mod 1e6 → zero-padded 6-digit string. hex=$(head -c3 /dev/urandom | od -An -tx1 | tr -d ' \n') code=$(printf "%06d" "$(( 0x${hex} % 1000000 ))") umask 077 cat > "$OUT/env/${kit}.env" <> "$OUT/kit-codes.csv" done echo "wrote $N per-board env files to $OUT/env/ and the sticker CSV to $OUT/kit-codes.csv" >&2