-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathautomountnfs.sh
111 lines (104 loc) · 5.33 KB
/
automountnfs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/bin/bash
# Setup logging
LOGFILE="/var/log/mountscript.log"
exec > >(tee -a ${LOGFILE} )
exec 2> >(tee -a ${LOGFILE} >&2)
SMBV=2.0 # SMB version
DM=10.0.0.5 # Domain IP for external drives
NTFY=10.0.4 # ntfy.sh mobile push notifications IP
NTFY=50025 # ntfy.sh mobile push notifications Port
USER=username # username
PASS=password # password
# mapping of mount points to docker services
declare -A mount_to_service=(
["/mnt/Kingston"]="archivebox absonic fancy-ukraine httpdir"
["/mnt/G2"]="flaresolverr prowlarr radarr sonarr booksonic wg-delugevpn wg-storm"
)
# Function to check if mount was successful
check_mount() {
local MOUNTPOINT=$1
if mountpoint -q $MOUNTPOINT; then
echo "✅ [SUCCESS] $MOUNTPOINT is mounted."
# Restart dependent services
if [[ -n ${mount_to_service[$MOUNTPOINT]} ]]; then
echo "🔄 Restarting services on $MOUNTPOINT..."
affected_services=""
for service in ${mount_to_service[$MOUNTPOINT]}; do
sudo docker restart $service
echo "🔄 Docker Restarted Service: $service"
affected_services+="$service, "
done
# Notify about affected services
curl -d "AutoMountNFS: Restarted services on $MOUNTPOINT: $affected_services" $NTFY:$NTFYPORT/automount_nfs
fi
else
echo "❌ [ERROR] Failed to mount $MOUNTPOINT."
# Notify using curl
curl -d "AutoMountNFS: $MOUNTPOINT failed to mount" $NTFY:$NTFYPORT/automount_nfs
fi
}
# Function to check if file exists and mount if not
mount_drive() {
# local DRIVE_PATH=$1
local DRIVE=$1
local MOUNTPOINT=$2
local CREDENTIALS=$3
local OPTION=$4
local UUID="${DRIVE#UUID=}"
if mountpoint -q "$MOUNTPOINT"; then
echo "🆗 $MOUNTPOINT is already mounted"
else
echo "⭕ $MOUNTPOINT does not exist. Attempting to mount..."
for i in {1..3}; do
if [[ $DRIVE == UUID=* ]]; then
# This is a local drive
sudo mount -U $UUID $MOUNTPOINT && break || sleep 5
echo "✅ Mounted drive: 🈁Local: UUID=$UUID to $MOUNTPOINT"
else
# This is a network drive
sudo mount -t cifs $DRIVE $MOUNTPOINT -o $CREDENTIALS,$OPTION && break || sleep 5
echo "✅ Mounted drive: 📶Remote: $DRIVE to $MOUNTPOINT"
fi
done
check_mount $MOUNTPOINT
fi
}
# Your credentials
credentials="username=$USER,password=$PASS,nobrl,iocharset=utf8,vers=$SMBV,uid=1000,rw,noperm"
# Array of your drives, drive paths and mount points
declare -A drives=(
# Network Drives
["/mnt/C"]="//$DM/C" # C: 1
["/mnt/emby/anime/1"]="//$DM/E/Downloads/Torrents/Movies-Shows/Anime" # E: 1
["/mnt/emby/anime/2"]="//$DM/F/Torrents/Movies-TV/Anime" # F: 1
["/mnt/emby/movies/1"]="//$DM/E/Downloads/Torrents/Movies-Shows/Movies" # E: 2
["/mnt/emby/movies/2"]="//$DM/F/Torrents/Movies-TV/Movies" # F: 2
["/mnt/emby/movies/3"]="//$DM/R/Torrents/Movies-TV/Movies" # R: 1
["/mnt/emby/tv/1"]="//$DM/E/Downloads/Torrents/Movies-Shows/TV-Shows" # E: 3
["/mnt/emby/tv/2"]="//$DM/F/Torrents/Movies-TV/TV-Shows" # F: 3
["/mnt/emby/tv/3"]="//$DM/R/Torrents/Movies-TV/TV-Shows" # R: 2
["/mnt/E"]="//$DM/E" # E: 4
["/mnt/Zero"]="//$DM/R" # R: 3
["/mnt/G2"]="//$DM/G2" # G: 1
["/mnt/Se7en"]="//$DM/J" # J: 1
["/mnt/Purple"]="//$DM/I" # I: 1
["/mnt/Jellyfin"]="//$DM/O" # O: 1
# Local Drives
["/mnt/Ronin"]="UUID=d9363f2a-dce6-4156-a4f6-97dbc56da0f2" # X: 1
["/mnt/Kingston"]="UUID=a85b3ded-84d3-4b24-9cd0-4d3fddc3681a" # Y: 1
# # Total 17
# # C E F G I J O R X Y
)
# Mount all drives
for MOUNTPOINT in "${!drives[@]}"; do
DRIVE="${drives[$MOUNTPOINT]}"
echo "- Processing drive $DRIVE..."
mount_drive $DRIVE $MOUNTPOINT $credentials
done
echo "✅ All drives processed"
echo " "
echo "List drives?"
echo "ls {/mnt/C,/mnt/emby/anime/1,/mnt/emby/anime/2,/mnt/emby/movies/1,/mnt/emby/movies/2,/mnt/emby/movies/3,/mnt/emby/tv/1,/mnt/emby/tv/2,/mnt/emby/tv/3,/mnt/E,/mnt/Zero/,/mnt/G2,/mnt/Se7en,/mnt/LilithPresser,/mnt/Purple,/mnt/Ronin,/mnt/Kingston}"
echo "❇️ Restart complete"
echo "✳️ Script Execution Complete"
curl -d "AutoMountNFS: Execution complete" $NTFY:$NTFYPORT/automount_nfs