53 lines
1.2 KiB
Bash
Executable File
53 lines
1.2 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
function is_mounted() {
|
|
mountpoint -q "$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
|
|
for mount in "${mounts[@]}"; do
|
|
force_unmount "$mount"
|
|
done
|
|
fi
|
|
|
|
if has_connection "192.168.1.1"; then
|
|
unmount "/home/honney/mount/fritzNAS"
|
|
else
|
|
force_unmount "/home/honney/mount/fritzNAS"
|
|
fi |