78 lines
2.8 KiB
Bash
Executable File
78 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Function to mount CIFS share with error handling
|
|
mount_cifs() {
|
|
local source="$1"
|
|
local mount_point="$2"
|
|
local options="$3"
|
|
|
|
# Create mount point if missing
|
|
if [ ! -d "$mount_point" ]; then
|
|
echo "Creating mount point: $mount_point"
|
|
sudo mkdir -p "$mount_point || { echo 'Mount point creation failed'; exit 1; }"
|
|
fi
|
|
|
|
echo "Mounting $source to $mount_point with options: $options"
|
|
sudo mount -t cifs -o "$options" "$source" "$mount_point" || {
|
|
echo "Mount failed for $source. Check credentials and network."
|
|
exit 1
|
|
}
|
|
echo "Successfully mounted: $mount_point"
|
|
}
|
|
|
|
function is_mounted() {
|
|
mountpoint -q "$1"
|
|
}
|
|
|
|
# Mount FRITZ.NAS (from fstab line 1)
|
|
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
|
|
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
|
|
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
|