53 lines
2.4 KiB
Bash
53 lines
2.4 KiB
Bash
#!/usr/bin/env bash
|
|
#
|
|
# a2a-peer-setup.sh — A2A inbound on a Hermes peer box (verified pattern, 2026-10-23)
|
|
#
|
|
# Run on EVERY box that must RECEIVE A2A tasks (NAS, RPi, MacBook, …).
|
|
# bash a2a-peer-setup.sh [AGENT_NAME] # e.g. bash a2a-peer-setup.sh nas
|
|
#
|
|
# Requires on the box: hermes (+ A2A plugin) and tailscaled in the same tailnet.
|
|
# Magic DNS NOT required — the published URL is the box's 100.x CGNAT address.
|
|
#
|
|
set -euo pipefail
|
|
|
|
NAME="${1:-peer}"
|
|
PORT="${A2A_PORT:-9900}"
|
|
TOK="${A2A_BEARER_TOKEN:?run with A2A_BEARER_TOKEN=<shared token> to avoid editing this file}"
|
|
ENVF="${HERMES_HOME:-$HOME/.hermes}/.env"
|
|
|
|
echo "→ enabling A2A platform + toolsets (agent_name=$NAME, port=$PORT)"
|
|
hermes config set gateway.platforms.a2a.enabled true >/dev/null 2>&1 || true
|
|
hermes tools enable a2a --platform a2a >/dev/null 2>&1 || true
|
|
hermes tools enable a2a --platform cli >/dev/null 2>&1 || true
|
|
|
|
# Tailnet IP (works without Magic DNS); first 100.x interface as fallback
|
|
TS_CLI="$(command -v tailscale || echo tailscale)"
|
|
TS_IP="$("$TS_CLI" ip -4 2>/dev/null || true)"
|
|
[ -z "${TS_IP:-}" ] && TS_IP="$(ip -4 -o addr 2>/dev/null | awk '{print $4}' | cut -d/ -f1 | awk -F. '$1==100{print; exit}')"
|
|
[ -z "${TS_IP:-}" ] && { echo "✗ no tailnet IP found — is tailscaled running and logged in?"; exit 1; }
|
|
PUBLIC_URL="http://${TS_IP}:${PORT}"
|
|
|
|
# ~/.hermes/.env — idempotent upsert (never duplicate keys)
|
|
mkdir -p "$(dirname "$ENVF")"; [ -f "$ENVF" ] || : > "$ENVF"
|
|
set_var() { # key value
|
|
if grep -qE "^$1=" "$ENVF" 2>/dev/null; then
|
|
sed -i.bak "s#^$1=.*#$1=$2#" "$ENVF" && rm -f "$ENVF.bak"
|
|
else
|
|
printf '%s=%s\n' "$1" "$2" >> "$ENVF"
|
|
fi
|
|
}
|
|
set_var A2A_HOST "0.0.0.0"
|
|
set_var A2A_PORT "$PORT"
|
|
set_var A2A_PUBLIC_URL "$PUBLIC_URL"
|
|
set_var A2A_AGENT_NAME "$NAME"
|
|
set_var A2A_BEARER_TOKEN "$TOK"
|
|
|
|
echo "→ done. Public URL: $PUBLIC_URL"
|
|
echo "→ start (or restart) the gateway in its own tmux session:"
|
|
echo " tmux new -d -s gateway 'env TERM=xterm hermes gateway run 2>&1 | tee -a ~/.hermes/logs/gw.log'"
|
|
echo "→ verify (from inside the box): curl -sS ${PUBLIC_URL}/.well-known/agent-card.json | head -c 200"
|
|
echo "→ verify from ANOTHER tailnet box: curl -sS ${PUBLIC_URL}/.well-known/agent-card.json"
|
|
echo
|
|
echo "NOTE: other peers must now point their a2a_agents.<name>.url at ${PUBLIC_URL}"
|
|
echo " (CGNAT-IP form) if their tailnet has no Magic DNS for the old name."
|