eleven / ocho Public

Clone
git clone https://amadan.net/eleven/ocho

Plain git — no account needed to clone.

Download

Download this file

1#!/usr/bin/env bash
2# πŸ€– tools/marketing-shots/serve.sh β€” build (if needed) + run the local demo
3# instance, seed the "The Commons" civic-tech space, print the URLs + a
4# localhost sign-in link. Wrapped by `./tools/dev shots up`.
5#
6# Foreground: it starts the server, seeds it, prints everything, then blocks so
7# the space stays live for capturing. Ctrl-C stops it. The DB + state are wiped
8# on each start (a clean, reproducible space every run) unless --keep.
9#
10# ./tools/marketing-shots/serve.sh # fresh seed on port 8848
11# ./tools/marketing-shots/serve.sh --keep # reuse the existing DB (don't re-seed)
12# LCHAT_DEMO_PORT=9000 ./tools/marketing-shots/serve.sh
13#
14# Data + isolation: DB lives at tools/marketing-shots/.demo.db (gitignored,
15# wiped each run). Admin token is a throwaway fixed value. Nothing here touches
16# any real/production instance.
17set -euo pipefail
18
19ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
20cd "$ROOT"
21KIT="$ROOT/tools/marketing-shots"
22
23PORT="${LCHAT_DEMO_PORT:-8848}"
24DB="$KIT/.demo.db"
25ADMIN="${LCHAT_DEMO_ADMIN:-capkit-demo-admin}"
26GROUP_NAME="The Commons"
27KEEP=0
28[ "${1:-}" = "--keep" ] && KEEP=1
29
30# Build the binary from THIS worktree if it's missing (or --rebuild).
31if [ ! -x "$ROOT/lchat" ] || [ "${1:-}" = "--rebuild" ]; then
32 echo "serve: building lchat from this worktree…"
33 GOTOOLCHAIN=auto go build -o "$ROOT/lchat" .
34fi
35
36# Refuse to trample another process on the port.
37if lsof -ti "tcp:$PORT" >/dev/null 2>&1; then
38 echo "serve: something is already listening on port $PORT β€” stop it or set LCHAT_DEMO_PORT." >&2
39 exit 1
40fi
41
42if [ "$KEEP" = "0" ]; then
43 rm -f "$DB" "$DB-wal" "$DB-shm" "$KIT/.demo-state.json"
44fi
45
46echo "serve: starting server on 127.0.0.1:$PORT (db $(basename "$DB"))…"
47LCHAT_DB="$DB" LCHAT_ADMIN_TOKEN="$ADMIN" LCHAT_GROUP_NAME="$GROUP_NAME" LCHAT_SKIP_SETUP=1 \
48 ADDR="127.0.0.1:$PORT" "$ROOT/lchat" &
49SERVER_PID=$!
50trap 'echo; echo "serve: stopping server…"; kill "$SERVER_PID" 2>/dev/null || true' EXIT INT TERM
51
52# Wait for it to answer.
53for _ in $(seq 1 100); do
54 curl -sf "http://127.0.0.1:$PORT/api/version" >/dev/null 2>&1 && break
55 sleep 0.1
56done
57curl -sf "http://127.0.0.1:$PORT/api/version" >/dev/null 2>&1 || { echo "serve: server didn't come up" >&2; exit 1; }
58
59LINK=""
60if [ "$KEEP" = "0" ] || [ ! -f "$KIT/.demo-state.json" ]; then
61 echo "serve: seeding The Commons…"
62 LINK="$(node tools/marketing-shots/seed-team.mjs --base "http://127.0.0.1:$PORT" --admin "$ADMIN")"
63else
64 echo "serve: --keep: reusing existing space; minting a fresh sign-in link…"
65 LINK="$(node tools/marketing-shots/device-link.mjs "http://127.0.0.1:$PORT")"
66fi
67
68cat <<EOF
69
70──────────────────────────────────────────────────────────────────────
71 βœ” Demo space "The Commons" is live.
72
73 Local URL: http://127.0.0.1:$PORT/
74 Admin: http://127.0.0.1:$PORT/admin#token=$ADMIN
75 Web check: ./tools/dev shots web-check shot.png (headless 2x screenshot)
76
77 Sign-in link (localhost β€” one-time, signs you in as "Cass"):
78 $LINK
79
80 For the NATIVE apps use the tunnel instead (real https):
81 In another terminal: ./tools/dev shots tunnel
82 It prints https://try-*.11relay.com links to open in the Mac app + on the iPhone.
83
84 Ctrl-C stops the server.
85──────────────────────────────────────────────────────────────────────
86
87EOF
88
89wait "$SERVER_PID"
90