| 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> |
| 17 | set -euo pipefail |
| 18 | |
| 19 | ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" |
| 20 | cd "$ROOT" |
| 21 | KIT="$ROOT/tools/marketing-shots" |
| 22 | |
| 23 | PORT="${LCHAT_DEMO_PORT:-8848}" |
| 24 | if ! 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 |
| 27 | fi |
| 28 | if [ ! -f "$KIT/.demo-state.json" ]; then |
| 29 | echo "tunnel: no .demo-state.json β run ./tools/dev shots up first." >&2 |
| 30 | exit 1 |
| 31 | fi |
| 32 | |
| 33 | LOG="$(mktemp -t capkit-tunnel.XXXXXX)" |
| 34 | echo "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 & |
| 36 | TRY_PID=$! |
| 37 | trap '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). |
| 40 | ORIGIN="" |
| 41 | for _ 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 |
| 46 | done |
| 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). |
| 50 | MAC_LINK="$(node tools/marketing-shots/device-link.mjs "$ORIGIN")" |
| 51 | IOS_LINK="$(node tools/marketing-shots/device-link.mjs "$ORIGIN")" |
| 52 | |
| 53 | cat <<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 | |
| 70 | EOF |
| 71 | |
| 72 | wait "$TRY_PID" |
| 73 | |