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/tunnel.sh β€” lend the local demo instance a real public
3# https address via `lchat try --local`, so the native apps (especially the
4# iPhone) can join over real TLS. Prints the try-*.11relay.com origin +
5# ready-to-open sign-in links. Wrapped by `./tools/dev shots tunnel`.
6#
7# Prereqs: `./tools/dev shots up` is already running (this tunnels its port). The
8# tunnel uses the production gateway tunnel.11ch.at β€” it carries only the same
9# encrypted traffic any hosted space would; the instance it fronts is your local
10# demo DB.
11#
12# ./tools/marketing-shots/tunnel.sh
13#
14# Foreground: it holds the tunnel open (Ctrl-C retires the address). Each printed
15# sign-in link is SINGLE-USE β€” for another device run:
16# node tools/marketing-shots/device-link.mjs <origin>
17set -euo pipefail
18
19ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)"
20cd "$ROOT"
21KIT="$ROOT/tools/marketing-shots"
22
23PORT="${LCHAT_DEMO_PORT:-8848}"
24if ! curl -sf "http://127.0.0.1:$PORT/api/version" >/dev/null 2>&1; then
25 echo "tunnel: nothing answering on 127.0.0.1:$PORT β€” start ./tools/dev shots up first." >&2
26 exit 1
27fi
28if [ ! -f "$KIT/.demo-state.json" ]; then
29 echo "tunnel: no .demo-state.json β€” run ./tools/dev shots up first." >&2
30 exit 1
31fi
32
33LOG="$(mktemp -t capkit-tunnel.XXXXXX)"
34echo "tunnel: opening a public address for 127.0.0.1:$PORT via tunnel.11ch.at…"
35"$ROOT/lchat" try --local "127.0.0.1:$PORT" >"$LOG" 2>&1 &
36TRY_PID=$!
37trap 'echo; echo "tunnel: retiring the address…"; kill "$TRY_PID" 2>/dev/null || true; rm -f "$LOG"' EXIT INT TERM
38
39# Wait for the gateway to assign an origin (grep it out of the try output).
40ORIGIN=""
41for _ in $(seq 1 120); do
42 ORIGIN="$(grep -oE 'https://try-[a-z0-9.-]+' "$LOG" | head -1 || true)"
43 [ -n "$ORIGIN" ] && break
44 kill -0 "$TRY_PID" 2>/dev/null || { echo "tunnel: lchat try exited early:" >&2; cat "$LOG" >&2; exit 1; }
45 sleep 0.5
46done
47[ -n "$ORIGIN" ] || { echo "tunnel: gateway didn't assign an address in time:" >&2; cat "$LOG" >&2; exit 1; }
48
49# Mint two fresh single-use sign-in links on the public origin (Mac + iPhone).
50MAC_LINK="$(node tools/marketing-shots/device-link.mjs "$ORIGIN")"
51IOS_LINK="$(node tools/marketing-shots/device-link.mjs "$ORIGIN")"
52
53cat <<EOF
54
55──────────────────────────────────────────────────────────────────────
56 βœ” Public address: $ORIGIN
57
58 Mac app β€” Spaces β–Έ Add from link… and paste (signs in as "Cass"):
59 $MAC_LINK
60
61 iPhone β€” open this link ON THE DEVICE (Safari β†’ Open in the app / join):
62 $IOS_LINK
63
64 Each link is single-use. Need another device? run:
65 node tools/marketing-shots/device-link.mjs $ORIGIN
66
67 Ctrl-C retires the address (the space's data stays in tools/marketing-shots/.demo.db).
68──────────────────────────────────────────────────────────────────────
69
70EOF
71
72wait "$TRY_PID"
73