#!/usr/bin/env bash
# Remove FastestInternetEver portable install on Linux (requires root).
set -euo pipefail

# shellcheck source=../../scripts/names.sh
source "$(cd "$(dirname "$0")/../.." && pwd)/scripts/names.sh"
PREFIX="${PREFIX:-/usr/local}"
BIN_DIR="$PREFIX/bin"
ETC_DIR="/etc/fastestinternetever"
SYSTEMD_UNIT="fastestinternetever-dns.service"

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

if command -v systemctl >/dev/null 2>&1; then
  systemctl disable --now "$SYSTEMD_UNIT" 2>/dev/null || true
  rm -f "/etc/systemd/system/$SYSTEMD_UNIT"
  systemctl daemon-reload
fi

rm -f "$BIN_DIR/$FIE_DNS_BIN" "$BIN_DIR/$FIE_AGENT_BIN"
rm -rf "$ETC_DIR"

echo "FastestInternetEver removed"