#!/bin/bash set -e id agent-gw >/dev/null 2>&1 || useradd --system --no-create-home --shell /usr/sbin/nologin agent-gw UIDG=$(id -u agent-gw) mkdir -p /opt/agent-gw cp /root/buryan-infra/ops/ai/gateway_agent.py /opt/agent-gw/agent.py chown -R agent-gw:agent-gw /opt/agent-gw chmod 755 /opt/agent-gw /opt/agent-gw/agent.py iptables-save > /root/iptables-before-agentgw-20261129.rules 2>/dev/null || true iptables -N AGENT_GW_OUT 2>/dev/null || true iptables -F AGENT_GW_OUT iptables -A AGENT_GW_OUT -o lo -p tcp --dport 9137 -j ACCEPT iptables -A AGENT_GW_OUT -p udp --dport 53 -j ACCEPT iptables -A AGENT_GW_OUT -j REJECT iptables -C OUTPUT -m owner --uid-owner "$UIDG" -j AGENT_GW_OUT 2>/dev/null || iptables -I OUTPUT 1 -m owner --uid-owner "$UIDG" -j AGENT_GW_OUT iptables-save > /etc/iptables/rules.v4 2>/dev/null || true echo "uid=$UIDG" echo '--- gateway as agent' sudo -u agent-gw /usr/bin/python3 /opt/agent-gw/agent.py 2>&1 | tail -3 echo '--- direct as agent' sudo -u agent-gw curl -sS -o /dev/null -w 'direct=%{http_code}\n' --max-time 3 http://127.0.0.1:9120/catalog 2>&1 | tail -2 || true