Files
fish/scripts/umount.sh
T
2026-08-25 23:58:46 +02:00

59 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
echo "Unmount failed: $1"
return 1
else
echo "Unmount completed: $1"
fi
else
echo "$1 is not mounted"
fi
}
function force_unmount() {
if is_mounted "$1"; then
if ! sudo umount -fl "$1"; then
echo "Unmount failed: $1"
return 1
else
echo "Unmount completed: $1"
fi
else
echo "$1 is not mounted"
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
exit 0