feat: kit-connect + syno-balance SPK builds, busfleet hub registration endpoint
- kit-connect SPK (ipq806x): postinst with hub registration, start-stop-status, connect-daemon management, Tailscale + reverse SSH tunnel integration - syno-balance SPK (noarch, test build): SmartWAN-aware dual-WAN load balancer with 6-factor scoring engine, syno-daemon lifecycle - Busfleet hub: register.sh (port pool 2230-2299), Python HTTP server, systemd service, port-registry.json with x4078/x5925 assignments - .gitignore: exclude SSH keys (*_id_ed25519), SPK artifacts (*.spk) Gitea releases: - kit-connect v0.1-0001 → x5925-kit-connect-v1 (production) - syno-balance v0.1-0001 → syno-balance-test-v1 (prerelease) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
# Busfleet Hub
|
||||
|
||||
Registration endpoint for kit-connect devices. Runs on the VPS at `162.243.83.36:8080`.
|
||||
|
||||
## Files
|
||||
|
||||
- **register.sh** — Called per-device. Assigns a tunnel port from pool 2230-2299, records it in `port-registry.json`, returns JSON.
|
||||
- **server.py** — Minimal Python HTTP server. Routes `GET /api/register/<DEVICE_ID>` → `register.sh`.
|
||||
- **port-registry.json** — Persistent device→port mapping.
|
||||
|
||||
## Deploy
|
||||
|
||||
```bash
|
||||
scp hub/register.sh hub/server.py root@162.243.83.36:/opt/busfleet-hub/
|
||||
ssh root@162.243.83.36 systemctl restart busfleet-hub
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
```
|
||||
GET /api/register/<DEVICE_ID>
|
||||
```
|
||||
|
||||
Response (existing device):
|
||||
```json
|
||||
{"device_id": "x5925", "tunnel_port": 2230, "tailscale_auth_key": "tskey-auth-...", "status": "existing"}
|
||||
```
|
||||
|
||||
Response (new device):
|
||||
```json
|
||||
{"device_id": "x9999", "tunnel_port": 2231, "tailscale_auth_key": "tskey-auth-...", "status": "new"}
|
||||
```
|
||||
|
||||
## Port Pool
|
||||
|
||||
2230–2299. Already assigned:
|
||||
- x4078: 2226 (grandfathered)
|
||||
- x5925: 2230
|
||||
@@ -0,0 +1,4 @@
|
||||
{
|
||||
"x4078": {"tunnel_port": 2226, "assigned": "2026-07-21"},
|
||||
"x5925": {"tunnel_port": 2230, "assigned": "2026-07-22"}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
#!/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 <<EOF
|
||||
{"device_id": "${DEVICE_ID}", "tunnel_port": ${EXISTING_PORT}, "tailscale_auth_key": "${TAILSCALE_AUTH_KEY}", "status": "existing"}
|
||||
EOF
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Find next available port
|
||||
ASSIGNED_PORT=$(python3 -c "
|
||||
import json
|
||||
with open('$REGISTRY') as f:
|
||||
reg = json.load(f)
|
||||
used = set(v['tunnel_port'] for v in reg.values())
|
||||
for port in range($PORT_POOL_START, $PORT_POOL_END + 1):
|
||||
if port not in used:
|
||||
print(port)
|
||||
break
|
||||
" 2>/dev/null)
|
||||
|
||||
if [ -z "$ASSIGNED_PORT" ]; then
|
||||
cat <<EOF
|
||||
{"device_id": "${DEVICE_ID}", "error": "no ports available in pool ${PORT_POOL_START}-${PORT_POOL_END}"}
|
||||
EOF
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Record assignment
|
||||
TODAY=$(date +%Y-%m-%d)
|
||||
python3 -c "
|
||||
import json
|
||||
with open('$REGISTRY') as f:
|
||||
reg = json.load(f)
|
||||
reg['$DEVICE_ID'] = {'tunnel_port': $ASSIGNED_PORT, 'assigned': '$TODAY'}
|
||||
with open('$REGISTRY', 'w') as f:
|
||||
json.dump(reg, f, indent=2)
|
||||
" 2>/dev/null
|
||||
|
||||
cat <<EOF
|
||||
{"device_id": "${DEVICE_ID}", "tunnel_port": ${ASSIGNED_PORT}, "tailscale_auth_key": "${TAILSCALE_AUTH_KEY}", "status": "new"}
|
||||
EOF
|
||||
exit 0
|
||||
@@ -0,0 +1,76 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Busfleet Hub — minimal HTTP registration server for kit-connect devices.
|
||||
|
||||
Listens on :8080. Routes:
|
||||
GET /api/register/<DEVICE_ID> — assign tunnel port, return JSON
|
||||
GET /health — health check
|
||||
"""
|
||||
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
from http.server import HTTPServer, BaseHTTPRequestHandler
|
||||
|
||||
REGISTER_SH = "/opt/busfleet-hub/register.sh"
|
||||
|
||||
|
||||
class HubHandler(BaseHTTPRequestHandler):
|
||||
"""Handle hub registration requests."""
|
||||
|
||||
def do_GET(self):
|
||||
# Route: /api/register/<DEVICE_ID>
|
||||
if self.path.startswith("/api/register/"):
|
||||
device_id = self.path.split("/api/register/", 1)[1].strip("/")
|
||||
if not device_id:
|
||||
self.send_json_error(400, "Missing device ID")
|
||||
return
|
||||
|
||||
try:
|
||||
result = subprocess.run(
|
||||
[REGISTER_SH, device_id],
|
||||
capture_output=True, text=True, timeout=15,
|
||||
)
|
||||
status = 200 if result.returncode == 0 else 500
|
||||
self.send_json(status, result.stdout.strip())
|
||||
except subprocess.TimeoutExpired:
|
||||
self.send_json_error(504, "Registration timed out")
|
||||
except Exception as exc:
|
||||
self.send_json_error(500, str(exc))
|
||||
return
|
||||
|
||||
# Health check
|
||||
if self.path in ("/", "/health"):
|
||||
self.send_json(200, '{"status":"ok","service":"busfleet-hub"}')
|
||||
return
|
||||
|
||||
self.send_json_error(404, "Not found")
|
||||
|
||||
def send_json(self, status, body):
|
||||
"""Send a JSON response."""
|
||||
self.send_response(status)
|
||||
self.send_header("Content-Type", "application/json")
|
||||
self.send_header("Access-Control-Allow-Origin", "*")
|
||||
self.end_headers()
|
||||
self.wfile.write(body.encode() if isinstance(body, str) else body)
|
||||
|
||||
def send_json_error(self, status, message):
|
||||
"""Send a JSON error response."""
|
||||
self.send_json(status, json.dumps({"error": message}))
|
||||
|
||||
def log_message(self, fmt, *args):
|
||||
print(f"[hub] {args[0]}", file=sys.stderr)
|
||||
|
||||
|
||||
def main():
|
||||
port = int(sys.argv[1]) if len(sys.argv) > 1 else 8080
|
||||
server = HTTPServer(("0.0.0.0", port), HubHandler)
|
||||
print(f"Busfleet Hub listening on :{port}", flush=True)
|
||||
try:
|
||||
server.serve_forever()
|
||||
except KeyboardInterrupt:
|
||||
print("\nShutting down.", flush=True)
|
||||
server.shutdown()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user