#!/usr/bin/env bash # πŸ€– tools/marketing-shots/serve.sh β€” build (if needed) + run the local demo # instance, seed the "The Commons" civic-tech space, print the URLs + a # localhost sign-in link. Wrapped by `./tools/dev shots up`. # # Foreground: it starts the server, seeds it, prints everything, then blocks so # the space stays live for capturing. Ctrl-C stops it. The DB + state are wiped # on each start (a clean, reproducible space every run) unless --keep. # # ./tools/marketing-shots/serve.sh # fresh seed on port 8848 # ./tools/marketing-shots/serve.sh --keep # reuse the existing DB (don't re-seed) # LCHAT_DEMO_PORT=9000 ./tools/marketing-shots/serve.sh # # Data + isolation: DB lives at tools/marketing-shots/.demo.db (gitignored, # wiped each run). Admin token is a throwaway fixed value. Nothing here touches # any real/production instance. set -euo pipefail ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" cd "$ROOT" KIT="$ROOT/tools/marketing-shots" PORT="${LCHAT_DEMO_PORT:-8848}" DB="$KIT/.demo.db" ADMIN="${LCHAT_DEMO_ADMIN:-capkit-demo-admin}" GROUP_NAME="The Commons" KEEP=0 [ "${1:-}" = "--keep" ] && KEEP=1 # Build the binary from THIS worktree if it's missing (or --rebuild). if [ ! -x "$ROOT/lchat" ] || [ "${1:-}" = "--rebuild" ]; then echo "serve: building lchat from this worktree…" GOTOOLCHAIN=auto go build -o "$ROOT/lchat" . fi # Refuse to trample another process on the port. if lsof -ti "tcp:$PORT" >/dev/null 2>&1; then echo "serve: something is already listening on port $PORT β€” stop it or set LCHAT_DEMO_PORT." >&2 exit 1 fi if [ "$KEEP" = "0" ]; then rm -f "$DB" "$DB-wal" "$DB-shm" "$KIT/.demo-state.json" fi echo "serve: starting server on 127.0.0.1:$PORT (db $(basename "$DB"))…" LCHAT_DB="$DB" LCHAT_ADMIN_TOKEN="$ADMIN" LCHAT_GROUP_NAME="$GROUP_NAME" LCHAT_SKIP_SETUP=1 \ ADDR="127.0.0.1:$PORT" "$ROOT/lchat" & SERVER_PID=$! trap 'echo; echo "serve: stopping server…"; kill "$SERVER_PID" 2>/dev/null || true' EXIT INT TERM # Wait for it to answer. for _ in $(seq 1 100); do curl -sf "http://127.0.0.1:$PORT/api/version" >/dev/null 2>&1 && break sleep 0.1 done curl -sf "http://127.0.0.1:$PORT/api/version" >/dev/null 2>&1 || { echo "serve: server didn't come up" >&2; exit 1; } LINK="" if [ "$KEEP" = "0" ] || [ ! -f "$KIT/.demo-state.json" ]; then echo "serve: seeding The Commons…" LINK="$(node tools/marketing-shots/seed-team.mjs --base "http://127.0.0.1:$PORT" --admin "$ADMIN")" else echo "serve: --keep: reusing existing space; minting a fresh sign-in link…" LINK="$(node tools/marketing-shots/device-link.mjs "http://127.0.0.1:$PORT")" fi cat <