QUICKSTART.md had the author's personal domain as the example anchor URL (wss://waste.dev.xplwd.com/ws) which would confuse anyone reading it. Replaced with wss://YOUR_ANCHOR_DOMAIN/ws and added a new Option 3 section explaining the example scripts. Added committed *.example versions of the four local-workflow scripts (launch-tui, launch-web, deploy-web, serve-web). The real filenames are gitignored so local edits (HOST, ANCHOR, etc.) are never accidentally committed; the .example files serve as templates users copy once. Each script fails fast if the placeholder URL/host is still set. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
97 lines
3.2 KiB
Bash
97 lines
3.2 KiB
Bash
#!/usr/bin/env bash
|
|
# launch-tui.sh — build and launch the TUI against a remote anchor.
|
|
# Starts a local daemon then opens the Bubble Tea terminal UI.
|
|
#
|
|
# SETUP: copy this file to launch-tui.sh (gitignored) and set ANCHOR below.
|
|
#
|
|
# Usage:
|
|
# ./launch-tui.sh
|
|
# ALIAS=alice NETWORK=friends ./launch-tui.sh
|
|
#
|
|
# Optional env vars (all have defaults):
|
|
# ANCHOR anchor WebSocket URL (required — edit below)
|
|
# NETWORK network name to join (default: "friends")
|
|
# ALIAS display name (default: $USER)
|
|
# DATA_DIR identity + message store dir (default: ~/.waste-$ALIAS)
|
|
# IPC_PORT local daemon IPC port (default: 17337)
|
|
# SHARE_DIR directory to share with peers (optional)
|
|
|
|
set -euo pipefail
|
|
|
|
ANCHOR="${ANCHOR:-wss://YOUR_ANCHOR_DOMAIN/ws}" # ← edit this
|
|
|
|
NETWORK="${NETWORK:-friends}"
|
|
ALIAS="${ALIAS:-${USER:-anon}}"
|
|
DATA_DIR="${DATA_DIR:-${HOME}/.waste-${ALIAS}}"
|
|
|
|
_DEFAULT_ALIAS="${USER:-anon}"
|
|
if [ "${ALIAS}" = "${_DEFAULT_ALIAS}" ]; then
|
|
IPC_PORT="${IPC_PORT:-17337}"
|
|
else
|
|
_HASH=$(printf '%d' "0x$(printf '%s' "$ALIAS" | md5sum | cut -c1-4)")
|
|
IPC_PORT="${IPC_PORT:-$(( 17400 + _HASH % 1000 ))}"
|
|
fi
|
|
|
|
SHARE_DIR="${SHARE_DIR:-}"
|
|
|
|
RED='\033[0;31m'; GREEN='\033[0;32m'; DIM='\033[2m'; BOLD='\033[1m'; RESET='\033[0m'
|
|
|
|
if [[ "$ANCHOR" == *YOUR_ANCHOR_DOMAIN* ]]; then
|
|
echo -e "${RED}error: edit ANCHOR in this script (or export ANCHOR=wss://... before running)${RESET}" >&2
|
|
exit 1
|
|
fi
|
|
|
|
mkdir -p "$DATA_DIR"
|
|
|
|
echo ""
|
|
echo -e "${BOLD}waste TUI${RESET}"
|
|
echo -e "${DIM}anchor : ${BOLD}${ANCHOR}${RESET}"
|
|
echo -e "${DIM}network : ${BOLD}${NETWORK}${RESET}"
|
|
echo -e "${DIM}alias : ${BOLD}${ALIAS}${RESET}"
|
|
echo -e "${DIM}data : ${DATA_DIR}${RESET}"
|
|
[ -n "$SHARE_DIR" ] && echo -e "${DIM}share : ${SHARE_DIR}${RESET}"
|
|
echo ""
|
|
|
|
echo -e "${DIM}building binaries…${RESET}"
|
|
go build -o /tmp/waste-daemon-run ./cmd/daemon
|
|
go build -o /tmp/waste-tui-run ./cmd/tui
|
|
echo -e "${GREEN}✓ built${RESET}"
|
|
echo ""
|
|
|
|
existing=$(lsof -ti tcp:"$IPC_PORT" 2>/dev/null || true)
|
|
[ -n "$existing" ] && kill "$existing" 2>/dev/null && sleep 0.3 || true
|
|
|
|
echo -e "${DIM}starting daemon on :${IPC_PORT}…${RESET}"
|
|
WS_PORT=$(( IPC_PORT + 1 ))
|
|
/tmp/waste-daemon-run \
|
|
-alias "$ALIAS" -data-dir "$DATA_DIR" \
|
|
-ipc-port "$IPC_PORT" -ws-port "$WS_PORT" \
|
|
-anchor "$ANCHOR" \
|
|
2>/tmp/waste-daemon.log &
|
|
DAEMON_PID=$!
|
|
|
|
n=0
|
|
while ! nc -z 127.0.0.1 "$IPC_PORT" 2>/dev/null; do
|
|
sleep 0.1; n=$(( n + 1 ))
|
|
[ "$n" -gt 80 ] && echo -e "${RED}daemon failed — check /tmp/waste-daemon.log${RESET}" >&2 && exit 1
|
|
done
|
|
echo -e "${GREEN}✓ daemon started (pid ${DAEMON_PID})${RESET}"
|
|
|
|
sleep 0.3
|
|
if [ -n "$SHARE_DIR" ]; then
|
|
JOIN=$(jq -cn --arg net "$NETWORK" --arg dir "$SHARE_DIR" \
|
|
'{"type":"join_network","network_name":$net,"share_dir":$dir}')
|
|
else
|
|
JOIN=$(jq -cn --arg net "$NETWORK" '{"type":"join_network","network_name":$net}')
|
|
fi
|
|
echo "$JOIN" | nc -q 0 127.0.0.1 "$IPC_PORT" >/dev/null 2>&1 || true
|
|
echo -e "${DIM}joined network: ${BOLD}${NETWORK}${RESET}"
|
|
|
|
cleanup() { kill "$DAEMON_PID" 2>/dev/null || true; }
|
|
trap cleanup EXIT INT TERM
|
|
|
|
echo ""
|
|
echo -e "${BOLD}launching TUI${RESET} — ${DIM}ctrl+c to quit${RESET}"
|
|
echo ""
|
|
exec /tmp/waste-tui-run -ipc "$IPC_PORT" -network "$NETWORK"
|