Board-side half of "preloaded + self-register + claim", plus the QR flow.
- apess-selfregister.sh (on-board): pairs locally for a token, discovers
the LAN IP, and announces {kitId, url, token, claimCode} to APESS
/nodes/self-register (x-fleet-secret gated). Retries until APESS is up;
idempotent, safe on boot and on a timer.
- systemd/apess-selfregister.{service,timer}: self-register After the
daemon, re-announce every 5 min so a DHCP lease change can't strand a
board.
- apess-node.env.example: per-board identity (KIT_ID, CLAIM_CODE,
FLEET_SECRET, APESS_URL).
- gen-kit-codes.sh (host): mint per-kit 6-digit codes, write the
per-board env files, and emit the QR sticker CSV
(…/workshop?kit=KIT-NN&code=NNNNNN).
- web: BoardClaim accepts initialCode; TeamRegistration pre-fills it from
?code= so scanning the kit QR fills kit + code — one tap to claim.
- deploy/uno-q/README: documents the whole self-serve onboarding path.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
39 lines
1.5 KiB
Bash
Executable File
39 lines
1.5 KiB
Bash
Executable File
#!/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" <<EOF
|
|
KIT_ID=${kit}
|
|
CLAIM_CODE=${code}
|
|
FLEET_SECRET=${FLEET_SECRET}
|
|
APESS_URL=${APESS_URL}
|
|
EOF
|
|
echo "${kit},${code},${APESS_WEB%/}/workshop?kit=${kit}&code=${code}" >> "$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
|