#!/bin/sh
# SandVPN Linux uninstaller — reverses install.sh completely.
set -eu

if [ "$(id -u)" -ne 0 ]; then
    echo "Run as root: sudo ./uninstall.sh" >&2
    exit 1
fi

# Stop any active tunnel first so routes/firewall are restored
/usr/local/bin/sandvpn disconnect 2>/dev/null || true

# Remove the systemd unit (handles stop + disable + daemon-reload)
/usr/local/bin/sandvpn-service --uninstall 2>/dev/null || true

rm -f /usr/local/bin/sandvpn /usr/local/bin/sandvpn-service
rm -rf /usr/lib/sandvpn
rm -rf /var/lib/sandvpn
rm -f /run/sandvpn.sock

# Per-user data (tokens) lives in each user's ~/.config/sandvpn — tell,
# don't touch: we can't know every user, and deleting homes isn't ours to do.
echo "SandVPN uninstalled."
echo "Per-user tokens remain in ~/.config/sandvpn — remove manually if wanted."
