-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy path02-plex.sh
145 lines (124 loc) · 4.39 KB
/
02-plex.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
#!/bin/bash
source vars
# Download and Install Plex
wget https://downloads.plex.tv/plex-media-server/1.3.3.3148-b38628e/plexmediaserver_1.3.3.3148-b38628e_amd64.deb
dpkg -i plex*.deb
rm plex*.deb
mkdir -p /etc/systemd/system/plexmediaserver.service.d
tee "/etc/systemd/system/plexmediaserver.service.d/local.conf" > /dev/null <<EOF
[Unit]
Description= Start Plexmediaserver as our user, and don't do it until our mount script has finished.
After=rcloneMount.service
[Service]
User=$username
Group=$username
EOF
chown -R $username:$username /var/lib/plexmediaserver
# Start Plex and enable on boot
systemctl daemon-reload
systemctl start plexmediaserver
systemctl enable plexmediaserver
# Open port
ufw allow 32400
cat << EOF
## ON LOCAL MACHINE - incognito works best for some reason
## otherwise Plex may tell you that it "can't save the settings"
## When you try to login via port forwarding.
# ssh $username@$ipaddr -L 8888:localhost:32400
# open `localhost:8888/web` in a browser
# login with your previously created Plex account.
# if you don't have one, create one now.
# Now enable remote access:
# Remote Access-->Enable
# Open IPADDRESS:32400/web
EOF
echo ''
echo "You need to manually enable remote management for Plex."
echo "Issue the following command on your LOCAL machine:"
echo "ssh $username@$ipaddr -L 8888:localhost:32400"
echo "open `localhost:8888/web` in a browser"
echo "Either login or create a new Plex account."
echo "Now enable remote access: Remote Access ->> Enable"
echo ''
echo "You should now be able to access plex at: $ipaddr:32400/web"
echo "Have you enabled remote access?"
select yn in "Yes" "No"; do
case $yn in
Yes ) ufw allow 8181; echo ''; echo "Cool, moving along."; echo ''; break;;
No ) echo "You should really do that before continuing."; exit;;
esac
done
# Install PlexPy
git clone https://github.com/JonnyWong16/plexpy.git /opt/plexpy/
chown -R $username:$username /opt/plexpy
# Add Systemd Service File
tee "/etc/systemd/system/plexpy.service" > /dev/null <<EOF
[Unit]
Description=PlexPy - Stats for Plex Media Server usage
After=plexmediaserver.service
[Service]
ExecStart=/opt/plexpy/PlexPy.py --quiet --daemon --nolaunch --config /opt/plexpy/config.ini --datadir /opt/plexpy
GuessMainPID=no
Type=forking
User=$username
Group=$username
[Install]
WantedBy=multi-user.target
EOF
# Start Plexpy and enable on boot
systemctl daemon-reload
systemctl start plexpy
systemctl enable plexpy
echo ''
echo "Do you want to allow remote access to PlexPy?"
echo "If so, you need to tell UFW to open the port."
echo "Otherwise, you can use SSH port forwarding."
echo ''
echo "Would you like us to open the port in UFW?"
select yn in "Yes" "No"; do
case $yn in
Yes ) ufw allow 8181; echo ''; echo "Port 8181 open, PlexPy is now available over the internet."; echo ''; break;;
No ) echo "Port 8181 left closed. You can still access it on your local machine by issuing the following command: ssh $username@$ipaddr -L 8181:localhost:8181"; echo "and then open localhost:8181 on your browser."; exit;;
esac
done
# Install Plex Requests
exec sudo -i -u $username /bin/bash - << eof
curl "https://install.meteor.com/?release=1.2.1" | sh
git clone https://github.com/lokenx/plexrequests-meteor.git /opt/plexrequests/
cd /opt/plexrequests
meteor &
PID=$!
sleep 10m
kill $PID
eof
# Add Systemd Service File
tee "/etc/systemd/system/plexrequest.service" > /dev/null <<EOF
[Unit]
Description=PlexRequest
After=plexmediaserver.service
[Service]
User=$username
Type=simple
WorkingDirectory=/opt/plexrequests
ExecStart=/usr/local/bin/meteor
KillMode=process
Restart=always
[Install]
WantedBy=multi-user.target
EOF
# Start PlexRequests and enable on boot
systemctl daemon-reload
systemctl start plexrequest
systemctl enable plexrequest
echo ''
echo "Do you want to allow remote access to PlexRequests?"
echo "If so, you need to tell UFW to open the port."
echo "Otherwise, you can use SSH port forwarding."
echo ''
echo "Would you like us to open the port in UFW?"
select yn in "Yes" "No"; do
case $yn in
Yes ) ufw allow 3000; echo ''; echo "Port 3000 open, PlexRequests is now available over the internet."; echo ''; break;;
No ) echo "Port 3000 left closed. You can still access it on your local machine by issuing the following command: ssh $username@$ipaddr -L 3000:localhost:3000"; echo "and then open localhost:3000 on your browser."; exit;;
esac
done