Files
LUKS-Lock-und-Unlock-per-Bash/lock_and_unmount.sh
2025-08-15 11:14:55 +00:00

54 lines
1.7 KiB
Bash
Raw Permalink Blame History

This file contains ambiguous Unicode characters

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
# === KONFIGURATION ===
declare -A DRIVES
source /root/logger.sh
# Format: [Mapper-Name]="/srv/dev-disk-by-uuid-<UUID>"
DRIVES[media]="/srv/dev-disk-by-uuid-cdd3de56-0b4f-48cf-aec0-abf441a759b5"
DRIVES[eintb]="/srv/dev-disk-by-uuid-97a953c1-2796-48d6-878b-083d4553bcf4"
DRIVES[kleine]="/srv/dev-disk-by-uuid-e8faffbf-7ba0-4fc3-876e-107f7c6a429d"
for MAPPER in "${!DRIVES[@]}"; do
MOUNTPOINT="${DRIVES[$MAPPER]}"
log_info ">>> Verarbeite $MAPPER (Mountpoint: $MOUNTPOINT)"
if mountpoint -q "$MOUNTPOINT"; then
log_info " 📢 Mountpoint ist eingehängt."
# Blockierende Prozesse anzeigen
log_info " 🔎 Blockierende Prozesse:"
sudo fuser -vm "$MOUNTPOINT" || log_error " Keine Prozesse gefunden."
# Normal aushängen versuchen
log_info " 🚪 Versuche normales Aushängen..."
if sudo umount "$MOUNTPOINT"; then
log_info " ✅ Erfolgreich ausgehängt."
else
log_error " ⚠ Normales Aushängen fehlgeschlagen."
log_info " 💤 Versuche Lazy Unmount..."
if sudo umount -l "$MOUNTPOINT"; then
log_info " ✅ Lazy Unmount erfolgreich."
else
log_error " ❌ Lazy Unmount ebenfalls fehlgeschlagen. Bitte prüfen!"
continue
fi
fi
else
log_info " Mountpoint ist nicht eingehängt."
fi
# LUKS schließen
log_info " 🔒 Schließe LUKS-Mapper /dev/mapper/$MAPPER ..."
if sudo cryptsetup close "$MAPPER"; then
log_info " ✅ Mapper $MAPPER geschlossen."
else
log_error " ⚠ Mapper $MAPPER konnte nicht geschlossen werden (evtl. noch in Benutzung)."
fi
echo
done
log_end