#!/bin/sh # busfleet-hub register.sh — Device registration endpoint # Called with DEVICE_ID as $1. Returns JSON on stdout. # Port pool: 2230-2299 DEVICE_ID="${1:-unknown}" REGISTRY="/opt/busfleet-hub/port-registry.json" PORT_POOL_START="${PORT_POOL_START:-2230}" PORT_POOL_END="${PORT_POOL_END:-2299}" TAILSCALE_AUTH_KEY="${TAILSCALE_AUTH_KEY:-tskey-auth-kJz8wqNVo211CNTRL-GNL5EFjp5aWQcaWPSVn2aW9TNworKUNBV}" # Init registry if missing if [ ! -f "$REGISTRY" ]; then echo '{}' > "$REGISTRY" fi # Check if device already registered EXISTING_PORT=$(python3 -c " import json with open('$REGISTRY') as f: reg = json.load(f) print(reg.get('$DEVICE_ID', {}).get('tunnel_port', '')) " 2>/dev/null) if [ -n "$EXISTING_PORT" ]; then cat </dev/null) if [ -z "$ASSIGNED_PORT" ]; then cat </dev/null cat <