1+ #! /bin/bash
2+
3+ set -e # Exit immediately if a command fails
4+
5+ echo " 🧹 Uninstalling the Discord Whitelist Bot..."
6+
7+ # 1. Stop and disable the systemd service if it exists
8+ if systemctl list-units --full -all | grep -Fq " ip_whitelister_bot.service" ; then
9+ echo " 🛑 Stopping and disabling the service..."
10+ systemctl stop ip_whitelister_bot
11+ systemctl disable ip_whitelister_bot
12+ systemctl daemon-reload
13+ else
14+ echo " Service not found, skipping stop/disable."
15+ fi
16+
17+ # 2. Remove the systemd service file
18+ if [ -f /etc/systemd/system/ip_whitelister_bot.service ]; then
19+ echo " 🗑️ Removing systemd service file..."
20+ rm -f /etc/systemd/system/ip_whitelister_bot.service
21+ systemctl daemon-reload
22+ else
23+ echo " Systemd service file already removed."
24+ fi
25+
26+ # 3. Remove the bot binary
27+ if [ -f /usr/local/bin/ip_whitelister_bot ]; then
28+ echo " 🗑️ Removing bot executable..."
29+ rm -f /usr/local/bin/ip_whitelister_bot
30+ fi
31+
32+ # 4. Remove environment and configuration files
33+ if [ -d /etc/ip_whitelister_bot ]; then
34+ echo " 🗑️ Removing configuration directory..."
35+ rm -rf /etc/ip_whitelister_bot
36+ fi
37+
38+ # 5. Preserve logs: Do NOT delete /var/log/ip_whitelister_bot.log
39+ echo " 🛑 Skipping log file removal (preserving /var/log/ip_whitelister_bot.log)."
40+
41+ # 6. Remove bot data directory (only /var/lib/ip_whitelister_bot)
42+ if [ -d /var/lib/ip_whitelister_bot ]; then
43+ echo " 🗑️ Removing bot data directory..."
44+ rm -rf /var/lib/ip_whitelister_bot
45+ fi
46+
47+ # 7. Remove sudoers permission
48+ if [ -f /etc/sudoers.d/ip_whitelister_bot ]; then
49+ echo " 🗑️ Removing sudoers file..."
50+ rm -f /etc/sudoers.d/ip_whitelister_bot
51+ fi
52+
53+ # 8. Remove system user and group
54+ if id " whitelistbot" & > /dev/null; then
55+ echo " 👤 Deleting system user whitelistbot..."
56+ userdel whitelistbot || true
57+ else
58+ echo " User whitelistbot not found."
59+ fi
60+
61+ echo " ✅ Uninstallation completed successfully!"
0 commit comments