|
1 |
| -#!/bin/bash |
2 |
| - |
3 |
| -# Setup logging |
4 |
| -LOGFILE="/var/log/mountscript.log" |
5 |
| -exec > >(tee -a ${LOGFILE} ) |
6 |
| -exec 2> >(tee -a ${LOGFILE} >&2) |
7 |
| - |
8 |
| -SMBV=2.0 # SMB version |
9 |
| -DM=10.0.0.5 # External domain |
10 |
| -NTFY=10.0.0.4 # ntfy.sh mobile push notifications ip |
11 |
| -NTFYPORT=50025 # ntfy.sh mobile push notifications port |
12 |
| -PASS=1234 # password |
13 |
| -USER=username # username |
14 |
| -# mapping of mount points to docker services |
15 |
| -declare -A mount_to_service=( |
16 |
| - ["/mnt/Kingston"]="archivebox absonic fancy-ukraine httpdir" |
17 |
| - ["/mnt/G2"]="flaresolverr prowlarr radarr sonarr booksonic wg-delugevpn wg-storm" |
18 |
| -) |
19 |
| - |
20 |
| -# Function to check if mount was successful |
21 |
| -check_mount() { |
22 |
| - local MOUNTPOINT=$1 |
23 |
| - if mountpoint -q $MOUNTPOINT; then |
24 |
| - echo "✅ [SUCCESS] $MOUNTPOINT is mounted." |
25 |
| - # Restart dependent services |
26 |
| - if [[ -n ${mount_to_service[$MOUNTPOINT]} ]]; then |
27 |
| - echo "🔄 Restarting services on $MOUNTPOINT..." |
28 |
| - affected_services="" |
29 |
| - for service in ${mount_to_service[$MOUNTPOINT]}; do |
30 |
| - sudo docker restart $service |
31 |
| - echo "🔄 Docker Restarted Service: $service" |
32 |
| - affected_services+="$service, " |
33 |
| - done |
34 |
| - # Notify about affected services |
35 |
| - if command -v ntfy >/dev/null 2>&1; then |
36 |
| - # ntfy is installed, proceed with sending the message |
37 |
| - curl -d "AutoMountNFS: Restarted services on $MOUNTPOINT: $affected_services" "$NTFY:$NTFYPORT/automount_nfs" |
38 |
| - else |
39 |
| - echo "ntfy is not installed." |
40 |
| - # Handle the case where ntfy is not installed, if necessary |
41 |
| - fi |
42 |
| - fi |
43 |
| - else |
44 |
| - echo "❌ [ERROR] Failed to mount $MOUNTPOINT." |
45 |
| - # Notify using curl |
46 |
| - if command -v ntfy >/dev/null 2>&1; then |
47 |
| - # ntfy is installed, proceed with sending the message |
48 |
| - curl -d "AutoMountNFS: $MOUNTPOINT failed to mount" "$NTFY:$NTFYPORT/automount_nfs" |
49 |
| - else |
50 |
| - echo "ntfy is not installed." |
51 |
| - # Handle the case where ntfy is not installed, if necessary |
52 |
| - fi |
53 |
| - fi |
54 |
| -} |
55 |
| - |
56 |
| -# Function to check if file exists and mount if not |
57 |
| -mount_drive() { |
58 |
| - local DRIVE=$1 |
59 |
| - local MOUNTPOINT=$2 |
60 |
| - local CREDENTIALS=$3 |
61 |
| - local OPTION=$4 |
62 |
| - local UUID="${DRIVE#UUID=}" |
63 |
| - if mountpoint -q "$MOUNTPOINT"; then |
64 |
| - echo "🆗 $MOUNTPOINT is already mounted" |
65 |
| - else |
66 |
| - echo "⭕ $MOUNTPOINT does not exist. Attempting to mount..." |
67 |
| - for i in {1..3}; do |
68 |
| - if [[ $DRIVE == UUID=* ]]; then |
69 |
| - # This is a local drive |
70 |
| - sudo mount -U $UUID $MOUNTPOINT && break || sleep 5 |
71 |
| - echo "✅ Mounted drive: 🈁Local: UUID=$UUID to $MOUNTPOINT" |
72 |
| - |
73 |
| - else |
74 |
| - # This is a network drive |
75 |
| - sudo mount -t cifs $DRIVE $MOUNTPOINT -o $CREDENTIALS,$OPTION && break || sleep 5 |
76 |
| - echo "✅ Mounted drive: 📶Remote: $DRIVE to $MOUNTPOINT" |
77 |
| - fi |
78 |
| - done |
79 |
| - check_mount $MOUNTPOINT |
80 |
| - fi |
81 |
| -} |
82 |
| -# Your credentials |
83 |
| -credentials="username=$USER,password=$PASS,nobrl,iocharset=utf8,vers=$SMBV,uid=1000,rw,noperm" |
84 |
| - |
85 |
| -# Array of your drives, drive paths and mount points |
86 |
| -declare -A drives=( |
87 |
| - # Network Drives |
88 |
| - ["/mnt/C"]="//$DM/C" # C: 1 |
89 |
| - ["/mnt/emby/anime/1"]="//$DM/E/Downloads/Torrents/Movies-Shows/Anime" # E: 1 |
90 |
| - ["/mnt/emby/anime/2"]="//$DM/F/Torrents/Movies-TV/Anime" # F: 1 |
91 |
| - ["/mnt/emby/movies/1"]="//$DM/E/Downloads/Torrents/Movies-Shows/Movies" # E: 2 |
92 |
| - ["/mnt/emby/movies/2"]="//$DM/F/Torrents/Movies-TV/Movies" # F: 2 |
93 |
| - ["/mnt/emby/movies/3"]="//$DM/R/Torrents/Movies-TV/Movies" # R: 1 |
94 |
| - ["/mnt/emby/tv/1"]="//$DM/E/Downloads/Torrents/Movies-Shows/TV-Shows" # E: 3 |
95 |
| - ["/mnt/emby/tv/2"]="//$DM/F/Torrents/Movies-TV/TV-Shows" # F: 3 |
96 |
| - ["/mnt/emby/tv/3"]="//$DM/R/Torrents/Movies-TV/TV-Shows" # R: 2 |
97 |
| - ["/mnt/E"]="//$DM/E" # E: 4 |
98 |
| - ["/mnt/Zero"]="//$DM/R" # R: 3 |
99 |
| - ["/mnt/G2"]="//$DM/G2" # G: 1 |
100 |
| - ["/mnt/Se7en"]="//$DM/J" # J: 1 |
101 |
| - ["/mnt/Purple"]="//$DM/I" # I: 1 |
102 |
| - ["/mnt/Jellyfin"]="//$DM/O" # O: 1 |
103 |
| - # Local Drives |
104 |
| - ["/mnt/Ronin"]="UUID=d9363f2a-dce6-4156-a4f6-97dbc56da0f2" # X: 1 |
105 |
| - ["/mnt/Kingston"]="UUID=a85b3ded-84d3-4b24-9cd0-4d3fddc3681a" # Y: 1 |
106 |
| - # # Total 17 |
107 |
| - # # C E F G I J O R X Y |
108 |
| -) |
109 |
| - |
110 |
| -# Mount all drives |
111 |
| -for MOUNTPOINT in "${!drives[@]}"; do |
112 |
| - DRIVE="${drives[$MOUNTPOINT]}" |
113 |
| - echo "- Processing drive $DRIVE..." |
114 |
| - mount_drive $DRIVE $MOUNTPOINT $credentials |
115 |
| -done |
116 |
| -echo "✅ All drives processed" |
117 |
| -echo " " |
118 |
| -echo "List drives" |
119 |
| -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}" |
120 |
| -echo "❇️ Restart complete" |
121 |
| -echo "✳️ Script Execution Complete" |
122 |
| -if command -v ntfy >/dev/null 2>&1; then |
123 |
| - # ntfy is installed, proceed with sending the message |
124 |
| - curl -d "AutoMountNFS: Execution complete" "$NTFY:$NTFYPORT/automount_nfs" |
125 |
| - else |
126 |
| - # Handle the case where ntfy is not installed, if necessary |
127 |
| - echo "ntfy is not installed." |
| 1 | +#!/bin/zsh |
| 2 | +# FDirSize.sh |
| 3 | +# Can't do $(whoami) or $HOME since mounting requires root and $(whoami) will return root |
| 4 | +# unless you read through this... https://rhodesmill.org/brandon/2010/mounting-windows-shares-in-linux-userspace/ |
| 5 | +# Change your username below |
| 6 | +HOME="/home/phoenix" |
| 7 | +if [ -d "$HOME/mnt/FDirSize" ] |
| 8 | +then |
| 9 | + echo "Directory $HOME/mnt/FDirSize exists." |
| 10 | +else |
| 11 | + mkdir -p $HOME/mnt/FDirSize |
128 | 12 | fi
|
| 13 | +mdir=$1 |
| 14 | +bn="${1##*/}" |
| 15 | +mfds="mnt/FDirSize" |
| 16 | +lgf="$HOME/$mfds/$bn.files-directory.log" |
| 17 | +pnt="$HOME/$mfds/$bn.FDirSize.F.log" |
| 18 | +du -abcx $1 --exclude /proc --exclude /sys --exclude /dev --exclude /mnt | sort -nr > $HOME/$mfds/$bn.files-directory.log |
| 19 | +awk '{sum=0} {sum=sum+$1} {printf $1" ""%s ",$0" \n"}' $HOME/$mfds/$bn.files-directory.log | sed -e 's/^[ \t]*//' | numfmt --to=iec-i | awk '{printf "%s "$2" ",$1} {$1=$2="";print "\""$0"\""}' | tr -s ' ' | sed 's/\" total\"/\"total\"/g' | sed 's/\" \/home/\"\/home/g' | sed 's/\ \"\ /\ \"/g' > $pnt |
| 20 | +echo "Sent the final log to:" |
| 21 | +echo "$pnt" |
0 commit comments