install.sh hinzugefügt
This commit is contained in:
69
install.sh
Normal file
69
install.sh
Normal file
@ -0,0 +1,69 @@
|
||||
#!/bin/bash
|
||||
|
||||
# === 1. Root-Rechte prüfen ===
|
||||
if [ "$EUID" -ne 0 ]; then
|
||||
echo "🚫 Bitte führe dieses Skript mit Root-Rechten aus (sudo ./install_fail2ban_discord.sh)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ Root-Rechte erkannt"
|
||||
|
||||
# === 2. Webhook-Link abfragen ===
|
||||
read -rp "Bitte gib deinen Discord Webhook-Link ein: " DISCORD_WEBHOOK
|
||||
|
||||
if [[ -z "$DISCORD_WEBHOOK" ]]; then
|
||||
echo "🚫 Kein Webhook angegeben. Abbruch."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# === 3. Testnachricht an Webhook senden ===
|
||||
echo "📨 Sende Testnachricht an Discord Webhook..."
|
||||
curl -H "Content-Type: application/json" \
|
||||
-X POST \
|
||||
-d '{"content": "✅ Testnachricht: Fail2Ban Discord Alert erfolgreich eingerichtet!"}' \
|
||||
"$DISCORD_WEBHOOK"
|
||||
|
||||
# === 4. Webhook in .env schreiben ===
|
||||
echo "🔧 Trage Webhook in .env-Datei ein..."
|
||||
echo "DISCORD_WEBHOOK_URL=$DISCORD_WEBHOOK" > .env
|
||||
|
||||
# === 5. Python virtualenv erstellen und Abhängigkeiten installieren ===
|
||||
echo "🐍 Erstelle Python-Umgebung..."
|
||||
python3 -m venv venv
|
||||
source venv/bin/activate
|
||||
pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
deactivate
|
||||
|
||||
# === 6. Systemd Service erstellen ===
|
||||
SERVICE_PATH="/etc/systemd/system/fail2ban_discord_alert.service"
|
||||
|
||||
echo "🛠️ Erstelle systemd service unter $SERVICE_PATH ..."
|
||||
|
||||
cat <<EOF > "$SERVICE_PATH"
|
||||
[Unit]
|
||||
Description=Fail2Ban Discord Webhook Monitor
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
WorkingDirectory=$(pwd)
|
||||
ExecStart=$(pwd)/venv/bin/python3 $(pwd)/fail2ban_discord.py
|
||||
Restart=on-failure
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
EOF
|
||||
|
||||
# === 7. Service aktivieren und starten ===
|
||||
echo "🔄 Aktiviere und starte fail2ban_discord_alert.service..."
|
||||
systemctl daemon-reexec
|
||||
systemctl daemon-reload
|
||||
systemctl enable fail2ban_discord_alert.service
|
||||
systemctl start fail2ban_discord_alert.service
|
||||
|
||||
# === 8. Status anzeigen ===
|
||||
echo "📋 Status des Dienstes:"
|
||||
systemctl status fail2ban_discord_alert.service --no-pager
|
||||
|
||||
echo "✅ Installation abgeschlossen."
|
Reference in New Issue
Block a user