#!/usr/bin/env bash
# Build a release binary with the deployed relay baked in. Reads the relay onion + access key from
# the PRIVATE secrets file (outside the repo). This script is gitignored; the secrets never touch git.
set -euo pipefail
SECRETS="${PVTCOMS_SECRETS:-$HOME/.ssh/pvtcoms-relay.secrets}"
[ -f "$SECRETS" ] || { echo "secrets file not found: $SECRETS"; exit 1; }
export PVTCOMS_DEFAULT_RELAY="$(grep '^RELAY_ONION=' "$SECRETS" | cut -d= -f2)"
export PVTCOMS_DEFAULT_RELAY_KEY="$(grep '^RELAY_ACCESS_KEY=' "$SECRETS" | cut -d= -f2)"
echo "baking relay: $PVTCOMS_DEFAULT_RELAY (key: ${PVTCOMS_DEFAULT_RELAY_KEY:0:6}…)"
cargo build --release -p pvtcoms-demo --features tor "$@"
echo "✓ built target/release/pvtcoms-demo with the deployed relay baked in"
