From 318420eba64465aee360f1a577a9f0b8209907f8 Mon Sep 17 00:00:00 2001 From: Hannes Date: Thu, 20 Aug 2026 17:45:44 +0200 Subject: [PATCH] fixes to mount scripts --- scripts/mount.sh | 90 +++++++++++++++++++++++++---------------------- scripts/umount.sh | 8 ++--- 2 files changed, 52 insertions(+), 46 deletions(-) diff --git a/scripts/mount.sh b/scripts/mount.sh index b562b8e..3011eb1 100755 --- a/scripts/mount.sh +++ b/scripts/mount.sh @@ -20,52 +20,58 @@ mount_cifs() { echo "Successfully mounted: $mount_point" } +function is_mounted() { + mountpoint -q "$1" +} + # Mount FRITZ.NAS (from fstab line 1) -if ping -c 1 -W 1 "$HOST" >/dev/null 2>&1; then - mount_cifs "//192.168.1.1/FRITZ.NAS" \ - "/home/honney/mount/fritzNAS" \ - "credentials=/home/honney/.cred/samba_credentials,uid=1000,gid=1000,vers=3.0,cache=none,nounix,noserverino,file_mode=0755,dir_mode=0755" +if ! is_mounted "/home/honney/mount/fritzNAS"; then + if ping -c 1 -W 1 "192.168.1.1" >/dev/null 2>&1; then + mount_cifs "//192.168.1.1/FRITZ.NAS" \ + "/home/honney/mount/fritzNAS" \ + "credentials=/home/honney/.cred/samba_credentials,uid=1000,gid=1000,vers=3.0,cache=none,nounix,noserverino,file_mode=0755,dir_mode=0755" + fi fi +echo "" +mount_points=("/home/honney/mount/Data" "/home/honney/mount/Media" "/home/honney/mount/Ripping" "/home/honney/mount/Apps") + 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" \ - "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" - - # Mount Media (from fstab line 3) - mount_cifs "//100.64.0.3/Media" \ - "/home/honney/mount/Media" \ - "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" - - # Mount Ripping (from fstab line 4) - mount_cifs "//100.64.0.3/Ripping" \ - "/home/honney/mount/Ripping" \ - "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" - - # Mount Apps (from fstab line 5) - mount_cifs "//100.64.0.3/Apps" \ - "/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" + echo "192.168.188.122, mounting shares..." + echo "" + mounts=("//192.168.188.122/Data" "//192.168.188.122/Media" "//192.168.188.122/Ripping" "//192.168.188.122/Apps") + for i in "${!mounts[@]}"; do + mount="${mounts[$i]}" + mount_point="${mount_points[$i]}" + echo "Checking $mount_point" + if ! is_mounted "$mount_point"; then + echo "$mount_point unmounted" + mount_cifs "$mount" \ + "$mount_point" \ + "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" + else + echo "$mount_point already mounted" + fi + echo "" + done 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" \ - "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" - - # Mount Media (from fstab line 3) - mount_cifs "//192.168.188.122/Media" \ - "/home/honney/mount/Media" \ - "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" - - # Mount Ripping (from fstab line 4) - mount_cifs "//192.168.188.122/Ripping" \ - "/home/honney/mount/Ripping" \ - "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" - - # Mount Apps (from fstab line 5) - mount_cifs "//192.168.188.122/Apps" \ - "/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" + echo "192.168.188.122 unreachable" + echo "100.64.0.3 reachable, mounting shares..." + echo "" + mounts=("//100.64.0.3/Data" "//100.64.0.3/Media" "//100.64.0.3/Ripping" "//100.64.0.3/Apps") + for i in "${!mounts[@]}"; do + mount="${mounts[$i]}" + mount_point="${mount_points[$i]}" + echo "Checking $mount_point" + if ! is_mounted "$mount_point"; then + echo "$mount_point unmounted" + mount_cifs "$mount" \ + "$mount_point" \ + "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" + else + echo "$mount_point already mounted" + fi + echo "" + done fi diff --git a/scripts/umount.sh b/scripts/umount.sh index d2d13f4..83bdb1e 100755 --- a/scripts/umount.sh +++ b/scripts/umount.sh @@ -7,10 +7,10 @@ function is_mounted() { function unmount() { if is_mounted "$1"; then if ! sudo umount -l "$1"; then - notify-send -u critical "Unmount failed" "$1" + echo "Unmount failed: $1" return 1 else - notify-send -u low "Unmount completed" "$1" + echo "Unmount completed: $1" fi fi } @@ -18,10 +18,10 @@ function unmount() { function force_unmount() { if is_mounted "$1"; then if ! sudo umount -fl "$1"; then - notify-send -u critical "Unmount failed" "$1" + echo "Unmount failed: $1" return 1 else - notify-send -u low "Unmount completed" "$1" + echo "Unmount completed: $1" fi fi }