plum-control-mcp/deploy/install-bridge.sh
Natalie 4c8b5702f9 feat(@applications/plum-control-mcp): add http bridge endpoint for tvanarchy
Co-Authored-By: Lilith Autocommit <noreply@atlilith.com>
2026-06-09 19:50:44 -07:00

35 lines
1.3 KiB
Bash
Executable file

#!/usr/bin/env bash
# Install the TVAnarchy bridge as a systemd --user service. Run this ON the host
# that should serve the bridge (black). Idempotent.
set -euo pipefail
REPO="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
BUN="$(command -v bun || true)"
[ -n "$BUN" ] || BUN="$HOME/.bun/bin/bun"
[ -x "$BUN" ] || { echo "bun not found (looked for 'bun' on PATH and $HOME/.bun/bin/bun)"; exit 1; }
CFG_DIR="$HOME/.config/tvanarchy-bridge"
UNIT_DIR="$HOME/.config/systemd/user"
mkdir -p "$CFG_DIR" "$UNIT_DIR"
ENV_FILE="$CFG_DIR/bridge.env"
if [ ! -f "$ENV_FILE" ]; then
cp "$REPO/deploy/bridge.env.example" "$ENV_FILE"
echo "Wrote $ENV_FILE — EDIT IT (set BRIDGE_TOKEN, confirm MEDIA_ROOTS) before relying on it."
fi
sed -e "s#__BUN__#$BUN#g" \
-e "s#__HTTP__#$REPO/src/http.ts#g" \
-e "s#__ENV__#$ENV_FILE#g" \
"$REPO/deploy/tvanarchy-bridge.service" > "$UNIT_DIR/tvanarchy-bridge.service"
systemctl --user daemon-reload
systemctl --user enable --now tvanarchy-bridge.service
# Keep the service running when no user session is active.
loginctl enable-linger "$USER" >/dev/null 2>&1 || true
echo
echo "Installed. Health check:"
echo " curl -s http://\$BRIDGE_HOST:\$BRIDGE_PORT/healthz"
echo "Point the iOS app (Settings) at this host's IP + port + token."
systemctl --user --no-pager status tvanarchy-bridge.service || true