2026-10-02 11:48:19 +01:00
|
|
|
#!/usr/bin/env sh
|
2026-10-02 13:46:27 +01:00
|
|
|
# Installs the static tsunagi binary and, where systemd is present, a service
|
|
|
|
|
# that runs the agent as a dedicated unprivileged "tsunagi" user. Run as root:
|
2026-10-02 11:48:19 +01:00
|
|
|
#
|
|
|
|
|
# sudo ./install.sh
|
|
|
|
|
#
|
2026-10-02 13:46:27 +01:00
|
|
|
# PREFIX overrides the install prefix (default /usr/local); if you change it,
|
|
|
|
|
# edit ExecStart in tsunagi.service to match.
|
2026-10-02 11:48:19 +01:00
|
|
|
set -eu
|
|
|
|
|
|
|
|
|
|
PREFIX="${PREFIX:-/usr/local}"
|
|
|
|
|
here="$(cd "$(dirname "$0")" && pwd)"
|
|
|
|
|
|
|
|
|
|
if [ "$(id -u)" -ne 0 ]; then
|
|
|
|
|
echo "This installer writes to ${PREFIX}/bin and /etc; re-run it as root (sudo)." >&2
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "Installing tsunagi to ${PREFIX}/bin"
|
|
|
|
|
install -d "${PREFIX}/bin"
|
2026-10-03 02:14:43 +01:00
|
|
|
install -m 0755 "${here}/tsng" "${PREFIX}/bin/tsng"
|
2026-10-02 11:48:19 +01:00
|
|
|
|
2026-10-02 13:46:27 +01:00
|
|
|
# The dedicated system user the service runs as (works with either shadow's
|
|
|
|
|
# useradd or Debian's adduser).
|
|
|
|
|
if ! getent group tsunagi >/dev/null 2>&1; then
|
|
|
|
|
groupadd -r tsunagi 2>/dev/null || addgroup --system tsunagi 2>/dev/null || true
|
|
|
|
|
fi
|
|
|
|
|
if ! getent passwd tsunagi >/dev/null 2>&1; then
|
|
|
|
|
useradd -r -g tsunagi -d /var/lib/tsunagi -s /usr/sbin/nologin -c "tsunagi agent" tsunagi 2>/dev/null \
|
|
|
|
|
|| adduser --system --ingroup tsunagi --home /var/lib/tsunagi --no-create-home \
|
|
|
|
|
--gecos "tsunagi agent" --disabled-login tsunagi 2>/dev/null || true
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# polkit rule so the agent (as the tsunagi user) may configure systemd-resolved.
|
|
|
|
|
install -d /etc/polkit-1/rules.d
|
|
|
|
|
install -m 0644 "${here}/50-tsunagi-resolved.rules" /etc/polkit-1/rules.d/50-tsunagi-resolved.rules
|
|
|
|
|
|
2026-10-02 11:48:19 +01:00
|
|
|
if command -v systemctl >/dev/null 2>&1; then
|
2026-10-02 13:46:27 +01:00
|
|
|
echo "Installing the systemd service (runs as the tsunagi user)"
|
2026-10-02 11:48:19 +01:00
|
|
|
install -m 0644 "${here}/tsunagi.service" /etc/systemd/system/tsunagi.service
|
|
|
|
|
systemctl daemon-reload
|
|
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
|
|
Done. Start the agent with:
|
|
|
|
|
|
|
|
|
|
sudo systemctl enable --now tsunagi
|
|
|
|
|
|
2026-10-02 13:46:27 +01:00
|
|
|
Control it with sudo (the CLI finds the service's socket automatically):
|
2026-10-02 11:48:19 +01:00
|
|
|
|
2026-10-03 02:14:43 +01:00
|
|
|
sudo tsng status
|
2026-10-03 17:47:44 +01:00
|
|
|
sudo tsng join -n <network-name> -s <tsn1…secret>
|
2026-10-02 11:48:19 +01:00
|
|
|
EOF
|
|
|
|
|
else
|
|
|
|
|
cat <<EOF
|
|
|
|
|
|
|
|
|
|
Installed the binary; no systemd found, so no service was set up. Either:
|
|
|
|
|
|
2026-10-03 02:14:43 +01:00
|
|
|
* run it as root: sudo ${PREFIX}/bin/tsng up
|
|
|
|
|
* or as your own user: sudo setcap cap_net_admin,cap_net_bind_service+p ${PREFIX}/bin/tsng
|
|
|
|
|
tsng up
|
2026-10-02 13:46:27 +01:00
|
|
|
(add yourself to the tsunagi group so the resolver works:
|
|
|
|
|
sudo usermod -aG tsunagi "\$USER")
|
2026-10-03 02:14:43 +01:00
|
|
|
* or without touching the OS: tsng up --no-tun
|
2026-10-02 11:48:19 +01:00
|
|
|
EOF
|
|
|
|
|
fi
|