#!/usr/bin/env bash
set -e

export DEBIAN_FRONTEND=noninteractive
export NEEDRESTART_MODE=a

echo "[+] Stopping sysstat services..."
systemctl stop sysstat || true
systemctl stop sysstat-collect.timer || true
systemctl stop sysstat-summary.timer || true

echo "[+] Disabling sysstat services..."
systemctl disable sysstat || true
systemctl disable sysstat-collect.timer || true
systemctl disable sysstat-summary.timer || true

echo "[+] Removing sysstat package..."
apt purge -y sysstat

echo "[+] Removing leftover logs/configs..."
rm -rf /var/log/sysstat
rm -f /etc/default/sysstat
rm -f /etc/cron.d/sysstat

echo "[+] Reloading systemd..."
systemctl daemon-reload

echo "[+] Done. sysstat removed."