#!/bin/sh # Register the gateway public key on swaprelay.smesh.lol. # # set-gateway.sh # # The three gateway-only rules carry an all-zeros placeholder until this is run, so those kinds # are refused rather than trusted. The public key is the one nostrino-bridge prints in its URI: # nostr+chaindata://?chains=... set -eu key=$(printf '%s' "${1:-}" | tr 'A-Z' 'a-z') case "$key" in *[!0-9a-f]*) echo "set-gateway: not hex: $key" >&2; exit 2 ;; esac if [ "${#key}" -ne 64 ]; then echo "set-gateway: expected 64 hex characters, got ${#key}" >&2 exit 2 fi policy=/etc/torly/policy/swaprelay.json if [ ! -w "$policy" ]; then echo "set-gateway: $policy is not writable (run as root)" >&2 exit 2 fi cp -a "$policy" "$policy.bak" old=$(sed -n 's/.*"authors": \["\([0-9a-f]\{64\}\)"\].*/\1/p' "$policy" | head -1) sed -i "s/$old/$key/g" "$policy" old_short=$(printf %s "$old" | cut -c1-16) echo "replaced the gateway key ${old_short}… with $key" systemctl restart torly-swap sleep 2 if systemctl is-active --quiet torly-swap; then echo "torly-swap is active" curl -fsS --max-time 5 http://127.0.0.1:3337/health && echo else echo "torly-swap failed to start; restoring $policy.bak" >&2 mv "$policy.bak" "$policy" systemctl restart torly-swap exit 1 fi echo "rollback copy: $policy.bak"