#!/usr/bin/env bash
set -euo pipefail
# Run on an operator-provisioned Linux VPN worker. No downloaded shell scripts.
if [ "$(id -u)" -ne 0 ]; then echo 'Run the reviewed installer as root.' >&2; exit 1; fi
dnf install -y iproute nftables wireguard-tools openvpn util-linux shadow-utils policycoreutils-python-utils
for entry in '991:iphub-agent' '992:iphub-vpn' '993:iphub-source'; do
 uid="${entry%%:*}"; account="${entry#*:}"
 if ! getent passwd "$account" >/dev/null; then groupadd -g "$uid" "$account"; useradd -r -u "$uid" -g "$uid" -M -s /sbin/nologin "$account"; fi
 if [ "$(id -u "$account")" != "$uid" ]; then echo "Unexpected UID for $account; update and review the service configuration." >&2; exit 1; fi
done
install -d -m 0700 -o iphub-agent -g iphub-agent /var/lib/iphub-agent
install -d -m 0755 /etc/netns /run/netns /usr/local/libexec
echo 'Install checksum-verified architecture-specific binaries and service units. Provision forwarding/firewall and SELinux policy, enroll privately, and install TLS before starting the agent.'
echo 'The helper needs network namespace mounts and per-namespace network sysctls. Keep the management listener behind an explicit firewall allowlist.'
