forked from dannyti/seedbox-from-scratch
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcreatePlexUserInstall
executable file
·69 lines (56 loc) · 2.83 KB
/
createPlexUserInstall
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
#!/bin/bash
# Hellish Tech
# No commercial usage without authorization
# createPlexUserInstall -u USERNAME -pt PLEXTOKEN -pp yes/no
exec 1> >(logger -s -t $(basename $0)) 2>&1
while [[ $# -gt 1 ]]
do
key="$1"
case $key in
-u|--username)
USERNAME="$2"
shift # past argument
;;
-pt|--plextoken)
PLEXTOKEN="$2"
shift # past argument
;;
-pp|--plexpass)
PLEXPASS="$2"
shift # past argument
;;
*)
# unknown option
;;
esac
shift # past argument or value
done
SYSTEMHOSTNAME=`cat /etc/seedbox-from-scratch/hostname.info`
PLEXPORT=$(/etc/seedbox-from-scratch/sfsgetAvailablePort -sp 32401 -ep 32500)
USERPASSWORD=$(echo "$(cat /etc/seedbox-from-scratch/users/${USERNAME}.info)" | grep "Password: " | head -n1 | awk '{print $2}')
OLDPLEXPORT=$(grep -o 'ManualPortMappingPort.*' /home/${USERNAME}/plex/config/Library/Application\ Support/Plex\ Media\ Server/Preferences.xml | cut -d \" -f2)
docker pull plexinc/pms-docker:latest
docker pull plexinc/pms-docker:plexpass
if [[ (${PLEXPASS} == "yes") ]]; then
docker run --restart=always -d --name ${USERNAME}_plex -h ${SYSTEMHOSTNAME} -e PLEX_CLAIM="${PLEXTOKEN}" -e ADVERTISE_IP="https://${SYSTEMHOSTNAME}:${PLEXPORT}/" --dns=$(grep nameserver /etc/resolv.conf|tail -1|cut -d ' ' -f 2) -v /home/${USERNAME}/media:/data -v /home/${USERNAME}/downloads/manual:/download -v /home/${USERNAME}/plex/config:/config -p ${PLEXPORT}:32400 plexinc/pms-docker:plexpass
fi
if [[ (${PLEXPASS} == "no") ]]; then
docker run --restart=always -d --name ${USERNAME}_plex -h ${SYSTEMHOSTNAME} -e PLEX_CLAIM="${PLEXTOKEN}" -e ADVERTISE_IP="https://${SYSTEMHOSTNAME}:${PLEXPORT}/" --dns=$(grep nameserver /etc/resolv.conf|tail -1|cut -d ' ' -f 2) -v /home/${USERNAME}/media:/data -v /home/${USERNAME}/downloads/manual:/download -v /home/${USERNAME}/plex/config:/config -p ${PLEXPORT}:32400 plexinc/pms-docker:latest
fi
sleep 5
CHECKIFRUNNING=$(/etc/seedbox-from-scratch/sfsRunningUserDockerInfo -u ${USERNAME} -d plex | tr -cd '[[:alnum:]]._-' )
if [[ (${CHECKIFRUNNING} == "STOPPED") || (${CHECKIFRUNNING} == "RUNNING") ]]; then
echo "SERVICE: PLEX" > /home/${USERNAME}/private/plex.serviceinfo
echo "USERNAME: $USERNAME" >> /home/${USERNAME}/private/plex.serviceinfo
echo "ACCESSURL: https://$SYSTEMHOSTNAME:$PLEXPORT/web" >> /home/${USERNAME}/private/plex.serviceinfo
echo "ACCESSURL: http://$SYSTEMHOSTNAME:$PLEXPORT/web" >> /home/${USERNAME}/private/plex.serviceinfo
echo "PLEXPORT: $PLEXPORT" >> /home/${USERNAME}/private/plex.serviceinfo
chown www-data:www-data /home/${USERNAME}/private/*.serviceinfo
fi
if ((${OLDPLEXPORT} >= 1000)); then
sudo perl -pi -e "s/${OLDPLEXPORT}/${PLEXPORT}/g" /home/${USERNAME}/plex/config/Library/Application\ Support/Plex\ Media\ Server/Preferences.xml
fi
if [[ -n $1 ]]; then
echo "Last line of file specified as non-opt/last argument:"
tail -1 $1
fi