#!/bin/bash # Deploy the relay server (server/bubble_relay.py) over ssh. Where it goes # comes from scripts/relay.env (not in git; see scripts/relay.env.example). # This only touches $RELAY_DIR and its own screen session, and installs nothing. # # scripts/deploy-relay.sh copy the code and (re)start it # scripts/deploy-relay.sh --stop stop it # scripts/deploy-relay.sh --token print the bearer token, for Settings → Relay server on the desktop # # What runs is server/run.sh; have the server start that at boot too, e.g. # screen -dmS bubble-relay bash -c 'bash $RELAY_DIR/app/run.sh' set -euo pipefail cd "$(dirname "$0")/.." [ -f scripts/relay.env ] || { echo "No scripts/relay.env: copy scripts/relay.env.example and fill it in." >&2; exit 1; } . scripts/relay.env : "${RELAY_SSH:?}" "${RELAY_DIR:?}" "${RELAY_BIND:?}" PORT=${RELAY_PORT:-8080} NAME=bubble-relay case "${1:-}" in --token) ssh "$RELAY_SSH" "cat $RELAY_DIR/data/token"; echo; exit 0 ;; --stop) ssh "$RELAY_SSH" "screen -S $NAME -X quit || true"; echo "stopped"; exit 0 ;; esac ssh "$RELAY_SSH" "mkdir -p $RELAY_DIR/app $RELAY_DIR/data ~/service-logs && chmod 700 $RELAY_DIR $RELAY_DIR/data" rsync -a server/bubble_relay.py server/run.sh "$RELAY_SSH:$RELAY_DIR/app/" printf 'RELAY_BIND=%q\nRELAY_PORT=%q\n' "$RELAY_BIND" "$PORT" | ssh "$RELAY_SSH" "cat > $RELAY_DIR/app/relay.env" ssh "$RELAY_SSH" bash -s </dev/null || true sleep 1 screen -dmS $NAME bash -c 'bash $RELAY_DIR/app/run.sh 2>&1 | tee ~/service-logs/$NAME.log' sleep 2 for pid in \$(pgrep -f bubble_relay.py); do echo 1000 > /proc/\$pid/oom_score_adj; done curl -s -m 5 http://$RELAY_BIND:$PORT/health; echo REMOTE