This commit is contained in:
Hannes
2026-08-19 23:31:01 +02:00
parent 95183069ce
commit e6785a24a7
3 changed files with 47 additions and 28 deletions
+2 -2
View File
@@ -27,7 +27,7 @@ if ping -c 1 -W 1 "$HOST" >/dev/null 2>&1; then
"credentials=/home/honney/.cred/samba_credentials,uid=1000,gid=1000,vers=3.0,cache=none,nounix,noserverino,file_mode=0755,dir_mode=0755"
fi
if ping -c 1 -W 1 "100.64.0.3" >/dev/null 2>&1; then
if ping -c 1 -W 1 "192.168.188.122" >/dev/null 2>&1; then
# Mount Data (from fstab line 2)
mount_cifs "//100.64.0.3/Data" \
"/home/honney/mount/Data" \
@@ -48,7 +48,7 @@ if ping -c 1 -W 1 "100.64.0.3" >/dev/null 2>&1; then
"/home/honney/mount/Apps" \
"credentials=/home/honney/.cred/trueNAS_credentials,vers=3.1.1,iocharset=utf8,rw,uid=1000,gid=1000,nounix,noperm,file_mode=0660,dir_mode=0770,hard,intr,cache=loose"
elif ping -c 1 -W 1 "192.168.188.122" >/dev/null 2>&1; then
elif ping -c 1 -W 1 "100.64.0.3" >/dev/null 2>&1; then
# Mount Data (from fstab line 2)
mount_cifs "//192.168.188.122/Data" \
"/home/honney/mount/Data" \
+44 -26
View File
@@ -1,35 +1,53 @@
#!/bin/bash
# Source the functions file
source "$HOME/.config/function_helper.sh"
function is_mounted() {
mountpoint -q "$1"
}
# Define mount points
MOUNT_POINT_RAID="$HOME/Raid/"
MOUNT_POINT_SSD="$HOME/Server-SSD/"
PASSWORD_FILE="$HOME/.cred/credentials.txt"
PASSWORD=$(<"$PASSWORD_FILE")
# Unmount RAID
if is_mounted "$MOUNT_POINT_RAID"; then
if echo "$PASSWORD" | sudo -S umount "$MOUNT_POINT_RAID"; then
send_notification "low" "Unmount Successful" "Unmounted $MOUNT_POINT_RAID successfully." "$HOME/.icons/BeautyLine-Garuda/devices/scalable/drive-harddisk-encrypted-symbolic.svg"
else
send_notification "high" "Unmount Failed" "Failed to unmount $MOUNT_POINT_RAID." "$HOME/.icons/BeautyLine-Garuda/devices/scalable/drive-harddisk-symbolic.svg"
exit 1
function unmount() {
if is_mounted "$1"; then
if ! sudo umount -l "$1"; then
notify-send -u critical "Unmount failed" "$1"
return 1
else
notify-send -u low "Unmount completed" "$1"
fi
fi
}
function force_unmount() {
if is_mounted "$1"; then
if ! sudo umount -fl "$1"; then
notify-send -u critical "Unmount failed" "$1"
return 1
else
notify-send -u low "Unmount completed" "$1"
fi
fi
}
function has_connection() {
if ping -c 1 -W 1 "$1" &>/dev/null; then
return 0
else
return 1
fi
}
mounts=("/home/honney/mount/Data" "/home/honney/mount/Media" "/home/honney/mount/Ripping" "/home/honney/mount/Apps")
if has_connection "100.64.0.3" || has_connection "192.168.188.122"; then
for mount in "${mounts[@]}"; do
unmount "$mount"
done
else
send_notification "low" "Not Mounted" "$MOUNT_POINT_RAID is not mounted." "$HOME/.icons/BeautyLine-Garuda/devices/scalable/drive-harddisk.svg"
for mount in "${mounts[@]}"; do
force_unmount "$mount"
done
fi
# Unmount SSD
if is_mounted "$MOUNT_POINT_SSD"; then
if echo "$PASSWORD" | sudo -S umount "$MOUNT_POINT_SSD"; then
send_notification "low" "Unmount Successful" "Unmounted $MOUNT_POINT_SSD successfully." "$HOME/.icons/BeautyLine-Garuda/devices/scalable/drive-harddisk-encrypted-symbolic.svg"
else
send_notification "high" "Unmount Failed" "Failed to unmount $MOUNT_POINT_SSD." "$HOME/.icons/BeautyLine-Garuda/devices/scalable/drive-harddisk-symbolic.svg"
exit 1
fi
if has_connection "192.168.1.1"; then
unmount "/home/honney/mount/fritzNAS"
else
send_notification "low" "Not Mounted" "$MOUNT_POINT_SSD is not mounted." "$HOME/.icons/BeautyLine-Garuda/devices/scalable/drive-harddisk.svg"
force_unmount "/home/honney/mount/fritzNAS"
fi