forked from tom472/mediabox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mediabox.sh
executable file
·327 lines (304 loc) · 12.4 KB
/
mediabox.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
#!/bin/bash
# Check that script was run not as root or with sudo
if [ "$EUID" -eq 0 ]
then echo "Please do not run this script as root or using sudo"
exit
fi
# set -x
# See if we need to check GIT for updates
if [ -e .env ]; then
# Stash any local changes to the base files
git stash > /dev/null 2>&1
printf "Updating your local copy of Mediabox.\\n\\n"
# Pull the latest files from Git
git pull
# Check to see if this script "mediabox.sh" was updated and restart it if necessary
changed_files="$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)"
check_run() {
echo "$changed_files" | grep --quiet "$1" && eval "$2"
}
# Provide a message once the Git check/update is complete
if [ -z "$changed_files" ]; then
printf "Your Mediabox is current - No Update needed.\\n\\n"
else
printf "Mediabox Files Update complete.\\n\\nThis script will restart if necessary\\n\\n"
fi
# Rename the .env file so this check fails if mediabox.sh needs to re-launch
mv .env 1.env
read -r -p "Press any key to continue... " -n1 -s
printf "\\n\\n"
# Run exec mediabox.sh if mediabox.sh changed
check_run mediabox.sh "exec ./mediabox.sh"
fi
# After update collect some current known variables
if [ -e 1.env ]; then
# Grab the CouchPotato, NBZGet, & PIA usernames & passwords to reuse
daemonun=$(grep CPDAEMONUN 1.env | cut -d = -f2)
daemonpass=$(grep CPDAEMONPASS 1.env | cut -d = -f2)
piauname=$(grep PIAUNAME 1.env | cut -d = -f2)
piapass=$(grep PIAPASS 1.env | cut -d = -f2)
dldirectory=$(grep DLDIR 1.env | cut -d = -f2)
tvdirectory=$(grep TVDIR 1.env | cut -d = -f2)
moviedirectory=$(grep MOVIEDIR 1.env | cut -d = -f2)
musicdirectory=$(grep MUSICDIR 1.env | cut -d = -f2)
# Echo back the media directioies, and other info to see if changes are needed
printf "These are the Media Directory paths currently configured.\\n"
printf "Your DOWNLOAD Directory is: %s \\n" "$dldirectory"
printf "Your TV Directory is: %s \\n" "$tvdirectory"
printf "Your MOVIE Directory is: %s \\n" "$moviedirectory"
printf "Your MUSIC Directory is: %s \\n" "$musicdirectory"
read -r -p "Are these directiores still correct? (y/n) " diranswer `echo \n`
read -r -p "Do you need to change your PIA Credentials? (y/n) " piaanswer `echo \n`
# Now we need ".env" to exist again so we can stop just the Medaibox containers
mv 1.env .env
# Stop the current Mediabox stack
printf "\\n\\nStopping Current Mediabox containers.\\n\\n"
docker-compose stop
# Make a datestampted copy of the existing .env file
mv .env "$(date +"%Y-%m-%d_%H:%M").env"
fi
# Get local Username
localuname=$(id -u -n)
# Get PUID
PUID=$(id -u "$localuname")
# Get GUID
PGID=$(id -g "$localuname")
# Get Docker Group Number
DOCKERGRP=$(grep docker /etc/group | cut -d ':' -f 3)
# Get Hostname
thishost=$(hostname)
# Get IP Address
locip=$(hostname -I | awk '{print $1}')
# Get Time Zone
time_zone=$(cat /etc/timezone)
# Get CIDR Address
slash=$(ip a | grep "$locip" | cut -d ' ' -f6 | awk -F '/' '{print $2}')
lannet=$(awk -F"." '{print $1"."$2"."$3".0"}'<<<$locip)/$slash
# Get Private Internet Access Info
if [ -z "$piaanswer" ]; then
read -r -p "What is your PIA Username?: " piauname
read -r -s -p "What is your PIA Password? (Will not be echoed): " piapass
printf "\\n\\n"
fi
if [ "$piaanswer" == "y" ]; then
read -r -p "What is your New PIA Username?: " piauname
read -r -s -p "What is your New PIA Password? (Will not be echoed): " piapass
printf "\\n\\n"
fi
# Get info needed for PLEX Official image
read -r -p "Which PLEX release do you want to run? By default 'public' will be used. (latest, public, plexpass): " pmstag
read -r -p "If you have PLEXPASS what is your Claim Token from https://www.plex.tv/claim/ (Optional): " pmstoken
# If not set - set PMS Tag to Public:
if [ -z "$pmstag" ]; then
pmstag=public
fi
# Get the info for the style of Portainer to use
read -r -p "Which style of Portainer do you want to use? By default 'No Auth' will be used. (noauth, auth): " portainerstyle
if [ -z "$portainerstyle" ]; then
portainerstyle=--no-auth
elif [ "$portainerstyle" == "noauth" ]; then
portainerstyle=--no-auth
elif [ "$portainerstyle" == "auth" ]; then
portainerstyle=
fi
# Ask user if they already have TV, Movie, and Music directories
if [ -z "$diranswer" ]; then
printf "\\n\\n"
printf "If you already have TV - Movie - Music directories you want to use you can enter them next.\\n"
printf "If you want Mediabox to generate it's own directories just press enter to these questions."
printf "\\n\\n"
read -r -p "Where do you store your DOWNLOADS? (Please use full path - /path/to/downloads ): " dldirectory
read -r -p "Where do you store your TV media? (Please use full path - /path/to/tv ): " tvdirectory
read -r -p "Where do you store your MOVIE media? (Please use full path - /path/to/movies ): " moviedirectory
read -r -p "Where do you store your MUSIC media? (Please use full path - /path/to/music ): " musicdirectory
fi
if [ "$diranswer" == "n" ]; then
read -r -p "Where do you store your DOWNLOADS? (Please use full path - /path/to/downloads ): " dldirectory
read -r -p "Where do you store your TV media? (Please use full path - /path/to/tv ): " tvdirectory
read -r -p "Where do you store your MOVIE media? (Please use full path - /path/to/movies ): " moviedirectory
read -r -p "Where do you store your MUSIC media? (Please use full path - /path/to/music ): " musicdirectory
fi
# Create the directory structure
if [ -z "$dldirectory" ]; then
mkdir -p content/completed
mkdir -p content/incomplete
dldirectory="$PWD/content"
else
mkdir -p "$dldirectory"/completed
mkdir -p "$dldirectory"/incomplete
fi
if [ -z "$tvdirectory" ]; then
mkdir -p content/tv
tvdirectory="$PWD/content/tv"
fi
if [ -z "$moviedirectory" ]; then
mkdir -p content/movies
moviedirectory="$PWD/content/movies"
fi
if [ -z "$musicdirectory" ]; then
mkdir -p content/music
musicdirectory="$PWD/content/music"
fi
# Adjust for Container name changes
[ -d "sickrage/" ] && mv sickrage/ sickchill # Switch from Sickrage to SickChill
mkdir -p couchpotato
mkdir -p delugevpn
mkdir -p delugevpn/config/openvpn
mkdir -p duplicati
mkdir -p duplicati/backups
mkdir -p headphones
mkdir -p historical/env_files
mkdir -p jackett
mkdir -p jellyfin
mkdir -p lidarr
mkdir -p minio
mkdir -p muximux
mkdir -p nzbget
mkdir -p ombi
mkdir -p "plex/Library/Application Support/Plex Media Server/Logs"
mkdir -p portainer
mkdir -p radarr
mkdir -p sickchill
mkdir -p sonarr
mkdir -p tautulli
# Create menu - Select and Move the PIA VPN files
echo "The following PIA Servers are avialable that support port-forwarding (for DelugeVPN); Please select one:"
PS3="Use a number to select a Server File or 'c' to cancel: "
# List the ovpn files
select filename in ovpn/*.ovpn
do
# leave the loop if the user says 'c'
if [[ "$REPLY" == c ]]; then break; fi
# complain if no file was selected, and loop to ask again
if [[ "$filename" == "" ]]
then
echo "'$REPLY' is not a valid number"
continue
fi
# now we can use the selected file
echo "$filename selected"
cp "$filename" delugevpn/config/openvpn/ > /dev/null 2>&1
vpnremote=$(grep "remote" "$filename" | cut -d ' ' -f2 | head -1)
# it'll ask for another unless we leave the loop
break
done
# TODO - Add a default server selection if none selected ..
cp ovpn/*.crt delugevpn/config/openvpn/ > /dev/null 2>&1
cp ovpn/*.pem delugevpn/config/openvpn/ > /dev/null 2>&1
# Create the .env file
echo "Creating the .env file with the values we have gathered"
printf "\\n"
cat << EOF > .env
### ------------------------------------------------
### M E D I A B O X C O N F I G S E T T I N G S
### ------------------------------------------------
### The values configured here are applied during
### $ docker-compose up
### -----------------------------------------------
### DOCKER-COMPOSE ENVIRONMENT VARIABLES BEGIN HERE
### -----------------------------------------------
###
EOF
{
echo "LOCALUSER=$localuname"
echo "HOSTNAME=$thishost"
echo "IP_ADDRESS=$locip"
echo "PUID=$PUID"
echo "PGID=$PGID"
echo "DOCKERGRP=$DOCKERGRP"
echo "PWD=$PWD"
echo "DLDIR=$dldirectory"
echo "TVDIR=$tvdirectory"
echo "MOVIEDIR=$moviedirectory"
echo "MUSICDIR=$musicdirectory"
echo "PIAUNAME=$piauname"
echo "PIAPASS=$piapass"
echo "CIDR_ADDRESS=$lannet"
echo "TZ=$time_zone"
echo "PMSTAG=$pmstag"
echo "PMSTOKEN=$pmstoken"
echo "PORTAINERSTYLE=$portainerstyle"
echo "VPN_REMOTE=$vpnremote"
} >> .env
echo ".env file creation complete"
printf "\\n\\n"
# Adjust for the Switch to linuxserver/sickchill
docker rm -f sickchill > /dev/null 2>&1
# Adjust for the Tautulli replacement of PlexPy
docker rm -f plexpy > /dev/null 2>&1
# Adjust for the Ouroboros replacement of Watchtower
docker rm -f watchtower > /dev/null 2>&1
# Adjust for old uhttpd web container - Noted in issue #47
docker rm -f uhttpd > /dev/null 2>&1
[ -d "www/" ] && mv www/ historical/www/
# Move back-up .env files
mv 20*.env historical/env_files/ > /dev/null 2>&1
mv historical/20*.env historical/env_files/ > /dev/null 2>&1
# Download & Launch the containers
echo "The containers will now be pulled and launched"
echo "This may take a while depending on your download speed"
read -r -p "Press any key to continue... " -n1 -s
printf "\\n\\n"
docker-compose up -d --remove-orphans
printf "\\n\\n"
# Configure the access to the Deluge Daemon
# The same credentials can be used for NZBGet's webui
if [ -z "$daemonun" ]; then
echo "You need to set a username and password for a of the programs - including."
echo "The Deluge daemon, NZBGet's API & web interface, and Minio."
read -r -p "What would you like to use as the access username?: " daemonun
read -r -p "What would you like to use as the access password?: " daemonpass
printf "\\n\\n"
fi
# Finish up the config
printf "Configuring DelugeVPN, NZBGet, Muximux, and Permissions \\n"
printf "This may take a few minutes...\\n\\n"
# Configure DelugeVPN: Set Daemon access on, delete the core.conf~ file
while [ ! -f delugevpn/config/core.conf ]; do sleep 1; done
docker stop delugevpn > /dev/null 2>&1
rm delugevpn/config/core.conf~ > /dev/null 2>&1
perl -i -pe 's/"allow_remote": false,/"allow_remote": true,/g' delugevpn/config/core.conf
perl -i -pe 's/"move_completed": false,/"move_completed": true,/g' delugevpn/config/core.conf
docker start delugevpn > /dev/null 2>&1
# Configure NZBGet
[ -d "content/nbzget" ] && mv content/nbzget/* content/ && rmdir content/nbzget
while [ ! -f nzbget/nzbget.conf ]; do sleep 1; done
docker stop nzbget > /dev/null 2>&1
perl -i -pe "s/ControlUsername=nzbget/ControlUsername=$daemonun/g" nzbget/nzbget.conf
perl -i -pe "s/ControlPassword=tegbzn6789/ControlPassword=$daemonpass/g" nzbget/nzbget.conf
perl -i -pe "s/{MainDir}\/intermediate/{MainDir}\/incomplete/g" nzbget/nzbget.conf
docker start nzbget > /dev/null 2>&1
# Push the Deluge Daemon, NZBGet Access, and Minio info the to Auth file and the .env file
echo "$daemonun":"$daemonpass":10 >> ./delugevpn/config/auth
{
echo "CPDAEMONUN=$daemonun"
echo "CPDAEMONPASS=$daemonpass"
echo "NZBGETUN=$daemonun"
echo "NZBGETPASS=$daemonpass"
} >> .env
# Configure Muximux settings and files
while [ ! -f muximux/www/muximux/settings.ini.php-example ]; do sleep 1; done
docker stop muximux > /dev/null 2>&1
cp settings.ini.php muximux/www/muximux/settings.ini.php
cp mediaboxconfig.php muximux/www/muximux/mediaboxconfig.php
sed '/^PIA/d' < .env > muximux/www/muximux/env.txt # Pull PIA creds from the displayed .env file
perl -i -pe "s/locip/$locip/g" muximux/www/muximux/settings.ini.php
perl -i -pe "s/locip/$locip/g" muximux/www/muximux/mediaboxconfig.php
perl -i -pe "s/daemonun/$daemonun/g" muximux/www/muximux/mediaboxconfig.php
perl -i -pe "s/daemonpass/$daemonpass/g" muximux/www/muximux/mediaboxconfig.php
docker start muximux > /dev/null 2>&1
# If PlexPy existed - copy plexpy.db to Tautulli
if [ -e plexpy/plexpy.db ]; then
docker stop tautulli > /dev/null 2>&1
mv tautulli/tautulli.db tautulli/tautulli.db.orig
cp plexpy/plexpy.db tautulli/tautulli.db
mv plexpy/plexpy.db plexpy/plexpy.db.moved
docker start tautulli > /dev/null 2>&1
mv plexpy/ historical/plexpy/
fi
if [ -e plexpy/plexpy.db.moved ]; then # Adjust for missed moves
mv plexpy/ historical/plexpy/
fi
printf "Setup Complete - Open a browser and go to: \\n\\n"
printf "http://%s \\nOR http://%s If you have appropriate DNS configured.\\n\\n" "$locip" "$thishost"
printf "Start with the MEDIABOX Icon for settings and configuration info.\\n"