Compare commits
No commits in common. "b3dedd446ff0c63a8a59bf274e18296c47d9a203" and "5226d50aa34d2fda998853ae4886dd728db02b3b" have entirely different histories.
b3dedd446f
...
5226d50aa3
@ -2,27 +2,11 @@
|
||||
|
||||
# === IMPORTS ===
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
source "$SCRIPT_DIR/../Utility/IsWebdavMounted.sh"
|
||||
source "$SCRIPT_DIR/../Utility/WakeOnLan.sh"
|
||||
source "$SCRIPT_DIR/../Utility/IsMounted.sh"
|
||||
source "$SCRIPT_DIR/../Utility/Lock.sh"
|
||||
source "$SCRIPT_DIR/../Utility/Log.sh"
|
||||
|
||||
# === TRAP EINRICHTEN ===
|
||||
trap trap_remove_lock SIGINT SIGTERM
|
||||
|
||||
# === LOCK-FILE ERSTELLEN ===
|
||||
create_lock
|
||||
|
||||
# === KONSTANTEN ===
|
||||
MAX_RESTARTS=2 # Maximale Anzahl an Neustarts
|
||||
RESTART_COUNT_FILE="/tmp/hidrive_restart_count" # Datei zur Speicherung des Neustart-Zählers
|
||||
|
||||
# === Neustart-Zähler initialisieren ===
|
||||
if [[ ! -f "$RESTART_COUNT_FILE" ]]; then
|
||||
echo 0 >"$RESTART_COUNT_FILE"
|
||||
fi
|
||||
RESTART_COUNT=$(<"$RESTART_COUNT_FILE")
|
||||
|
||||
# === Hilfe-Seite ===
|
||||
if [[ "$*" == *"-h"* ]]; then
|
||||
echo "Benutzung: $0 <DEVICE_MAC> <WEBDAV_URL> <NFS_PATH>"
|
||||
@ -38,21 +22,18 @@ if [[ "$*" == *"-h"* ]]; then
|
||||
echo
|
||||
echo "Dieses Skript bindet HiDrive als Dateisystem ein bzw. ein lokales NAS, sollte dieses vorhanden sein."
|
||||
echo "WakeOnLan-Pakete werden zum Starten versendet."
|
||||
remove_lock
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# === ROOT-PRÜFUNG ===
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
echo "Dieses Skript muss als root ausgeführt werden! Bitte starte es mit sudo."
|
||||
remove_lock
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# === PARAMETER-ÜBERPRÜFUNG ===
|
||||
if [[ "$#" -ne 3 ]]; then
|
||||
echo "Benutzung: $0 <DEVICE_MAC> <WEBDAV_URL> <NFS_PATH>"
|
||||
remove_lock
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -81,30 +62,16 @@ check_webdav_installed() {
|
||||
return 0
|
||||
}
|
||||
|
||||
restart_script() {
|
||||
if [[ $RESTART_COUNT -lt $MAX_RESTARTS ]]; then
|
||||
RESTART_COUNT=$((RESTART_COUNT + 1))
|
||||
echo "$RESTART_COUNT" >"$RESTART_COUNT_FILE"
|
||||
log "Neustart des Skripts (Versuch $RESTART_COUNT von $MAX_RESTARTS)..."
|
||||
remove_lock
|
||||
exec "$0" "$@"
|
||||
else
|
||||
log "Maximale Anzahl an Neustarts erreicht ($MAX_RESTARTS). Skript wird beendet."
|
||||
rm -f "$RESTART_COUNT_FILE" # Neustart-Zähler zurücksetzen
|
||||
remove_lock
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
unmount() {
|
||||
local mount_point="$1"
|
||||
log "Unmounting $mount_point..."
|
||||
if umount "$mount_point"; then
|
||||
log "Unmount erfolgreich."
|
||||
else
|
||||
log "Fehler beim Unmounten von $mount_point."
|
||||
check_webdav_credentials() {
|
||||
if [[ ! -f "$WEBDAV_CREDENTIALS" ]]; then
|
||||
log "Fehler: WebDAV-Passwortdatei nicht gefunden unter $WEBDAV_CREDENTIALS!"
|
||||
return 1
|
||||
fi
|
||||
if ! grep -q "$MOUNT_POINT" "$WEBDAV_CREDENTIALS"; then
|
||||
log "Fehler: Keine Zugangsdaten für den Mountpoint $MOUNT_POINT in $WEBDAV_CREDENTIALS gefunden!"
|
||||
return 1
|
||||
fi
|
||||
return 0
|
||||
}
|
||||
|
||||
mount_nfs() {
|
||||
@ -133,46 +100,25 @@ mount_webdav() {
|
||||
|
||||
# === HAUPTLOGIK ===
|
||||
|
||||
# Prüfen, ob NFS oder WebDAV installiert ist
|
||||
if ! check_nfs_installed && ! check_webdav_installed; then
|
||||
log "Weder NFS noch WebDAV sind installiert. Neustart erforderlich."
|
||||
restart_script "$@"
|
||||
# Prüfen, ob das Dateisystem bereits gemountet ist
|
||||
if is_mounted "$MOUNT_POINT"; then
|
||||
log "Das Dateisystem ist bereits gemountet unter $MOUNT_POINT."
|
||||
exit 0 # Skript beenden, da kein weiteres Mounten erforderlich ist
|
||||
fi
|
||||
|
||||
# Gerät erreichbar?
|
||||
# Wenn nicht gemountet, mit der Hauptlogik fortfahren
|
||||
log "Starte Wake-on-LAN-Prozess..."
|
||||
DEVICE_IP=$(wake_device "$DEVICE_MAC")
|
||||
|
||||
if [[ -n "$DEVICE_IP" ]]; then
|
||||
log "Gerät ist unter $DEVICE_IP erreichbar. Prüfe NFS-Mount..."
|
||||
NFS_SERVER="$DEVICE_IP:$NFS_PATH"
|
||||
if ! is_nfs_mounted "$MOUNT_POINT"; then
|
||||
log "NFS ist nicht gemountet. Wechsel zu NFS..."
|
||||
if is_mounted "$MOUNT_POINT"; then
|
||||
unmount "$MOUNT_POINT"
|
||||
fi
|
||||
if check_nfs_installed; then
|
||||
mount_nfs || restart_script "$@"
|
||||
fi
|
||||
else
|
||||
log "NFS ist bereits gemountet."
|
||||
log "Gerät ist unter $DEVICE_IP erreichbar, versuche NFS-Mount..."
|
||||
NFS_SERVER="$DEVICE_IP:$NFS_PATH" # Dynamische NFS-Server-Adresse setzen
|
||||
if check_nfs_installed; then
|
||||
mount_nfs
|
||||
fi
|
||||
else
|
||||
log "Gerät ist nicht erreichbar. Prüfe WebDAV-Mount..."
|
||||
if ! is_webdav_mounted "$MOUNT_POINT"; then
|
||||
log "WebDAV ist nicht gemountet. Wechsel zu WebDAV..."
|
||||
if is_mounted "$MOUNT_POINT"; then
|
||||
unmount "$MOUNT_POINT"
|
||||
fi
|
||||
if check_webdav_installed && check_webdav_credentials; then
|
||||
mount_webdav || restart_script "$@"
|
||||
fi
|
||||
else
|
||||
log "WebDAV ist bereits gemountet."
|
||||
log "Gerät konnte nicht geweckt werden, versuche WebDAV-Mount..."
|
||||
if check_webdav_installed && check_webdav_credentials; then
|
||||
mount_webdav
|
||||
fi
|
||||
fi
|
||||
|
||||
# Neustart-Zähler zurücksetzen, wenn erfolgreich
|
||||
rm -f "$RESTART_COUNT_FILE"
|
||||
|
||||
# === LOCK-FILE ENTFERNEN ===
|
||||
remove_lock
|
||||
|
||||
@ -8,21 +8,3 @@ is_mounted() {
|
||||
return 1 # Nicht gemountet
|
||||
fi
|
||||
}
|
||||
|
||||
is_webdav_mounted() {
|
||||
local mount_point="$1"
|
||||
if mount | grep -q "on $mount_point type davfs"; then
|
||||
return 0 # WebDAV ist gemountet
|
||||
else
|
||||
return 1 # WebDAV ist nicht gemountet
|
||||
fi
|
||||
}
|
||||
|
||||
is_nfs_mounted() {
|
||||
local mount_point="$1"
|
||||
if mount | grep -q "on $mount_point type nfs"; then
|
||||
return 0 # NFS ist gemountet
|
||||
else
|
||||
return 1 # NFS ist nicht gemountet
|
||||
fi
|
||||
}
|
||||
|
||||
@ -1,30 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
LOCK_DIR="/run/lock" # Standard für systemweite Locks
|
||||
if [[ ! -w "$LOCK_DIR" ]]; then
|
||||
LOCK_DIR="/tmp" # Fallback für benutzerspezifische Locks
|
||||
fi
|
||||
|
||||
LOCK_FILE="$LOCK_DIR/$(basename "$0").lock"
|
||||
|
||||
create_lock() {
|
||||
if [[ -e "$LOCK_FILE" ]]; then
|
||||
log "Ein anderer Prozess läuft bereits. Lock-File gefunden: $LOCK_FILE"
|
||||
exit 1
|
||||
fi
|
||||
touch "$LOCK_FILE"
|
||||
log "Lock-File erstellt: $LOCK_FILE"
|
||||
}
|
||||
|
||||
remove_lock() {
|
||||
if [[ -e "$LOCK_FILE" ]]; then
|
||||
rm -f "$LOCK_FILE"
|
||||
log "Lock-File entfernt: $LOCK_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
trap_remove_lock() {
|
||||
log "Signal empfangen. Lock-File wird entfernt."
|
||||
remove_lock
|
||||
exit 1
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user