#!/usr/bin/env bash # Clawmates Visualization Layer — installer (idempotent, safe to re-run) set -euo pipefail cd "$(dirname "$0")" say() { printf '\033[1;38;5;209m›\033[0m %s\n' "$*"; } ok() { printf '\033[1;32m✓\033[0m %s\n' "$*"; } warn() { printf '\033[1;33m!\033[0m %s\n' "$*"; } echo say "Clawmates visualization layer — install" echo # 1) Node >= 20 ------------------------------------------------------------- if command -v node >/dev/null 2>&1; then NODE_MAJOR="$(node -p 'process.versions.node.split(".")[0]')" if [ "$NODE_MAJOR" -ge 20 ]; then ok "Node $(node -v)"; else warn "Node $(node -v) found but >= 20 is required." echo " Install Node 20 LTS: https://nodejs.org or 'sudo apt install nodejs' from NodeSource." exit 1 fi else warn "Node not found. Install Node 20 LTS, then re-run:" echo " curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt-get install -y nodejs" exit 1 fi # 2) Bridge deps (intentionally none beyond Node built-ins) ----------------- if [ -f realtime/package.json ]; then ( cd realtime && npm ci --omit=dev 2>/dev/null || npm install --omit=dev 2>/dev/null || true ) ok "Bridge ready (dependency-free)" fi # 3) Static file server ------------------------------------------------------ if command -v caddy >/dev/null 2>&1; then ok "Caddy present — will serve screens/" elif command -v npx >/dev/null 2>&1; then warn "Caddy not found; will fall back to 'npx serve'." else warn "No static server found. Install Caddy: https://caddyserver.com/docs/install" fi # 4) .env -------------------------------------------------------------------- if [ ! -f .env ]; then cp .env.example .env ok "Wrote .env from .env.example — edit it before running live mode." else ok ".env already exists (left untouched)" fi echo ok "Install complete." echo say "Next — DEMO mode (no backend):" echo " (cd realtime && CLAWMATES_MODE=demo node server.mjs)" echo " caddy file-server --root ./screens --listen :8080 # or: npx serve ./screens -l 8080" echo " open http://localhost:8080/Clawmates%20World.dc.html?live=http://localhost:8420/live" echo say "Next — LIVE mode (wire to cm-api): edit .env, then" echo " (cd realtime && CLAWMATES_MODE=live node server.mjs)" echo say "See IMPLEMENTATION.md for per-screen wiring, the event taxonomy, Infrastructure (Tailscale/daemon/cloud), and the systemd unit." echo