#!/bin/bash
set -e

# NetProtego CPE Agent Uninstaller (Alpine Linux Support)

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

echo "Uninstalling NetProtego CPE Agent..."

# Stop and remove from runlevel
if rc-service -e netprotego-cpe; then
    echo "Stopping service..."
    rc-service netprotego-cpe stop || true
    echo "Removing from default runlevel..."
    rc-update del netprotego-cpe default || true
fi

# Remove init script
if [ -f /etc/init.d/netprotego-cpe ]; then
    echo "Removing init script..."
    rm /etc/init.d/netprotego-cpe
fi

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

echo "Uninstallation complete."
