Add mount nas script
This commit is contained in:
parent
0ada1aa767
commit
0710bb9767
1 changed files with 51 additions and 0 deletions
51
mount_nas.sh
Executable file
51
mount_nas.sh
Executable file
|
@ -0,0 +1,51 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Runs script in local directory to pick up .env file
|
||||
parent_path=$( cd "$(dirname "${BASH_SOURCE[0]}")" ; pwd -P )
|
||||
cd "$parent_path"
|
||||
|
||||
# Import variables
|
||||
set -a
|
||||
source .env
|
||||
set +a
|
||||
|
||||
SERVER_IP=friday
|
||||
declare -A MOUNT_POINTS=(
|
||||
["photos"]="/media/nas/photos"
|
||||
["cameraupload"]="/media/nas/cameraupload"
|
||||
)
|
||||
|
||||
mount_share() {
|
||||
local share=$1
|
||||
local mount_point=$2
|
||||
|
||||
# Create directory if it doesn't exist
|
||||
if [ ! -d "$mount_point" ]; then
|
||||
mkdir -p "$mount_point"
|
||||
fi
|
||||
|
||||
if ! mountpoint -q "$mount_point"; then
|
||||
mount -t cifs -o username=${USERNAME},password=${PASSWORD},uid=1000 "//${SERVER_IP}/${share}" "$mount_point"
|
||||
fi
|
||||
}
|
||||
|
||||
unmount_share() {
|
||||
local mount_point=$1
|
||||
if mountpoint -q "$mount_point"; then
|
||||
umount -l "$mount_point"
|
||||
fi
|
||||
}
|
||||
|
||||
ping -c1 -W2 "$SERVER_IP" > /dev/null 2>&1
|
||||
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo "Server is up. Mounting folders..."
|
||||
for share in "${!MOUNT_POINTS[@]}"; do
|
||||
mount_share "$share" "${MOUNT_POINTS[$share]}"
|
||||
done
|
||||
else
|
||||
echo "Server is down. Unmounting folders..."
|
||||
for mount_point in "${MOUNT_POINTS[@]}"; do
|
||||
unmount_share "$mount_point"
|
||||
done
|
||||
fi
|
Loading…
Reference in a new issue