updates
This commit is contained in:
+44
-26
@@ -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
|
||||
Reference in New Issue
Block a user