Files
netmaker-status-script/install-wg-client-status-check.sh

45 lines
1.5 KiB
Bash
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# --- EINSTELLUNGEN ---
GITEA_URL="https://me-gitea.maieredv.cloud/MAIEREDV/netmaker-status-script/raw/branch/main/wg-client-status.sh"
SCRIPT_PATH="/root/wg-client-status.sh"
# --- Funktion: Script herunterladen ---
download_script() {
echo "Lade Script von Gitea..."
curl -s -L -o "$SCRIPT_PATH" "$GITEA_URL"
if [ $? -ne 0 ]; then
echo "Fehler: Script konnte nicht heruntergeladen werden!"
exit 1
fi
chmod +x "$SCRIPT_PATH"
echo "Script gespeichert und ausführbar gemacht: $SCRIPT_PATH"
}
# --- 1⃣ Erstmaliges Setup ---
download_script
# --- 2⃣ Cronjob: jede Minute (VPN Status) ---
CRON_LINE_MIN="* * * * * /bin/bash $SCRIPT_PATH"
crontab -l 2>/dev/null | grep -F "$SCRIPT_PATH" >/dev/null
if [ $? -ne 0 ]; then
(crontab -l 2>/dev/null; echo "$CRON_LINE_MIN") | crontab -
echo "Cronjob hinzugefügt: jede Minute wird das Script ausgeführt."
else
echo "Cronjob jede Minute existiert bereits nichts geändert."
fi
# --- 3⃣ Cronjob: einmal nachts (Update vom Gitea) ---
# Beispiel: 03:00 Uhr
CRON_LINE_UPDATE="0 3 * * * /bin/bash -c 'curl -s -L -o $SCRIPT_PATH $GITEA_URL && chmod +x $SCRIPT_PATH'"
crontab -l 2>/dev/null | grep -F "curl -s -L -o $SCRIPT_PATH" >/dev/null
if [ $? -ne 0 ]; then
(crontab -l 2>/dev/null; echo "$CRON_LINE_UPDATE") | crontab -
echo "Cronjob hinzugefügt: Script wird jede Nacht um 03:00 Uhr aktualisiert."
else
echo "Nacht-Update-Cronjob existiert bereits nichts geändert."
fi
echo "Setup abgeschlossen!"