network-monitor/scripts/build-installers.sh
neil a17f2b502c Proxmox nodes: install in an LXC container instead of Docker on the node
Run on a Proxmox VE node (pct and /etc/pve present), the installers now
default to INSTALL_MODE=lxc: create or reuse (by tag netmon-hub /
netmon-probe) an unprivileged Debian LXC on vmbr0 with nesting and onboot,
push the installer into it (rebuilt from its own functions) and run it there
in native mode. LXC_* variables override ID, storage, template storage,
bridge, IP and size. Docker on a node now needs an explicit
INSTALL_MODE=docker and prints a warning; an earlier Docker install is
pointed out with removal steps.

Ping setup inside an unprivileged container stays within the mapped group
range, which the kernel requires.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-04 18:28:21 -08:00

64 lines
3.5 KiB
Bash
Executable file

#!/usr/bin/env bash
# Generate install-probe.sh from install.sh. install.sh is the only installer you edit; the
# probe installer is the same script with NETMON_ROLE=probe and its own header comment.
# tests/test_installers.py fails when install-probe.sh is out of date.
set -euo pipefail
cd "$(dirname "$0")/.."
RAW=https://git.neilbantoc.dev/services/network-monitor/raw/branch/main
out=install-probe.sh
[ "${1:-}" = --check ] && out=$(mktemp)
{
cat <<HEADER
#!/usr/bin/env bash
# GENERATED from install.sh by scripts/build-installers.sh. Edit install.sh, then run that script.
#
# Install (or upgrade) a Network Monitor PROBE. The hub's "Add probe" dialog prints the exact
# command, with this probe's token:
#
# curl -fsSL $RAW/install-probe.sh | HUB_URL=http://hub:8000 PROBE_TOKEN=... bash
#
# Native mode on Linux (Proxmox LXC, bare metal) runs as root:
# curl -fsSL $RAW/install-probe.sh | sudo env HUB_URL=http://hub:8000 PROBE_TOKEN=... bash
#
# Serve-only probe (e.g. a VPS the others test against): leave out HUB_URL and PROBE_TOKEN,
# and open PROBE_PORT (default 8765/tcp) in its firewall.
#
# Private repo over https: add GIT_TOKEN, read without echoing it:
# read -rsp 'Git token: ' GIT_TOKEN && export GIT_TOKEN && curl -fsSL -H "Authorization: token \$GIT_TOKEN" $RAW/install-probe.sh | HUB_URL=... PROBE_TOKEN=... bash
#
# Where it installs (INSTALL_MODE):
# lxc On a Proxmox VE node: creates (or reuses) a small Debian LXC container, tagged
# netmon-probe, on the node's bridge, and installs natively inside it. Default on
# Proxmox nodes, so the node itself gets no Docker and no packages.
# docker The probe in a container with host networking. Default on other Linux hosts.
# native A Python virtualenv and a boot service: systemd on Linux, launchd on macOS.
# Default on macOS and inside LXC containers.
# On Linux it also lets unprivileged processes ping (net.ipv4.ping_group_range, persisted in
# /etc/sysctl.d). Re-running is safe: it keeps .env (values you pass replace those keys).
# Ordinary deploys:
# docker: docker exec network-probe update
# native: sudo network-probe-update (macOS: network-probe-update)
#
# Settings (environment variables, all optional):
# HUB_URL, PROBE_TOKEN the hub to report to and this probe's token
# PROBE_PORT default 8765 (the probe's test server, on all interfaces)
# ADVERTISE_ADDR address other probes use for this one (default: what the hub sees)
# INSTALL_MODE docker | native (default: see above)
# INSTALL_DIR default /opt/network-probe
# REPO_URL, REPO_REF default https://git.neilbantoc.dev/services/network-monitor.git, main
# GIT_TOKEN, GIT_USERNAME private repo over https
# GIT_SSH_KEY private repo over SSH (base64-encoded deploy key)
# Proxmox (lxc mode): LXC_ID, LXC_STORAGE, LXC_TEMPLATE_STORAGE, LXC_BRIDGE, LXC_IP, LXC_GW,
# LXC_CORES, LXC_MEMORY, LXC_DISK (see install.sh)
#
# Everything is inside main(), so a partial download runs nothing. bash 3.2 compatible (macOS).
HEADER
sed -n '/^NETMON_ROLE=hub$/,$p' install.sh | sed '1s/^NETMON_ROLE=hub$/NETMON_ROLE=probe/'
} > "$out"
if [ "${1:-}" = --check ]; then
if cmp -s "$out" install-probe.sh; then rm -f "$out"; echo "install-probe.sh is up to date"; exit 0; fi
rm -f "$out"; echo "install-probe.sh is out of date: run scripts/build-installers.sh" >&2; exit 1
fi
chmod +x install-probe.sh
echo "wrote install-probe.sh"