#!/bin/bash
set -e

# NetProtego POP Agent Uninstaller

if [ "$EUID" -ne 0 ]; then 
  echo "Please run as root"
  exit 1
fi

echo "Uninstalling NetProtego POP Agent..."

# Stop and disable service
if systemctl is-active --quiet netprotego-pop; then
    echo "Stopping service..."
    systemctl stop netprotego-pop
fi

if systemctl is-enabled --quiet netprotego-pop; then
    echo "Disabling service..."
    systemctl disable netprotego-pop
fi

# Remove service file
if [ -f /etc/systemd/system/netprotego-pop.service ]; then
    echo "Removing service file..."
    rm /etc/systemd/system/netprotego-pop.service
    systemctl daemon-reload
fi

# Remove binary
if [ -f /usr/local/bin/pop-agent ]; then
    echo "Removing binary..."
    rm /usr/local/bin/pop-agent
fi

echo "Uninstallation complete."
