Skip to content

Commit a45c1f4

Browse files
authored
Merge pull request #2 from geekloper/fix_1
fix #1
2 parents 3911b38 + d1356ef commit a45c1f4

File tree

4 files changed

+82
-6
lines changed

4 files changed

+82
-6
lines changed

README.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ This script will:
4141
Edit the `.env` file to add your Discord bot credentials:
4242

4343
```sh
44-
sudo vi /etc/whitelist_bot/.env
44+
sudo vi /etc/ip_whitelister_bot/.env
4545
```
4646

4747
Example `.env` file:
@@ -74,6 +74,10 @@ sudo systemctl status ip_whitelister_bot
7474

7575
View logs:
7676

77+
```sh
78+
sudo cat /var/log/ip_whitelister_bot.log
79+
```
80+
7781
```sh
7882
sudo journalctl -u ip_whitelister_bot -f
7983
```
@@ -103,7 +107,14 @@ Banning removes their ability to whitelist IPs & deny their ips in UFW.
103107

104108

105109
## Uninstallation
106-
To remove the bot completely:
110+
111+
Using uninstall.sh
112+
113+
```sh
114+
curl -sSL https://raw.githubusercontent.com/geekloper/discord-bot-ip-whitelister/main/uninstall.sh | sudo bash
115+
```
116+
117+
Or this commands if installed manually:
107118

108119
```sh
109120
sudo systemctl stop ip_whitelister_bot

config/env.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ import (
99

1010
// LoadEnv loads environment variables from a .env file
1111
func LoadEnv() {
12-
err := godotenv.Load()
13-
if err != nil {
14-
log.Fatal("Error loading .env file")
12+
if os.Getenv("BOT_TOKEN") == "" {
13+
// Only load .env if not already set by the environment (like systemd)
14+
err := godotenv.Load("/etc/ip_whitelister_bot/.env")
15+
if err != nil {
16+
log.Fatal("Error loading .env file")
17+
}
1518
}
1619
}
1720

install.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ mkdir -p /var/log
3434

3535

3636
# Download the latest release from GitHub
37-
GITHUB_REPO="geekloper/discord-bot-ip-whitelister" # Remplace par ton repo GitHub
37+
GITHUB_REPO="geekloper/discord-bot-ip-whitelister"
3838
LATEST_RELEASE_URL=$(curl -s https://api.github.com/repos/$GITHUB_REPO/releases/latest | grep "browser_download_url" | cut -d '"' -f 4)
3939

4040
if [[ -z "$LATEST_RELEASE_URL" ]]; then
@@ -87,6 +87,7 @@ EOL
8787
# Setting the correct permissions
8888
chown -R whitelistbot:whitelistbot /var/lib/ip_whitelister_bot
8989
chmod 600 /etc/ip_whitelister_bot/.env
90+
chown whitelistbot:whitelistbot /etc/ip_whitelister_bot/.env
9091

9192

9293
# Give bot sudo permission for UFW

uninstall.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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

Comments
 (0)