-
Notifications
You must be signed in to change notification settings - Fork 0
/
start
executable file
·114 lines (104 loc) · 4.12 KB
/
start
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
#!/bin/bash
# First configure Plex by editing ./conf
# then run ./start to start Plex (this file)
# run ./stop to stop Plex
set -e
source ./conf
media_vols=()
for m in "${media_folders[@]}"
do
dir="${!m}"
[ -d "$dir" ] && media_vols+=(-v "$dir:/$m")
done
[ "$media_vols" = "" ] && echo "No media directories, please edit conf file" && exit 1
config=${config:-"$(pwd)/database/config"}
[ -d "$config" ] || mkdir -pv "$config"
transcode=${transcode:-"$(pwd)/database/transcode"}
[ -d "$transcode" ] || mkdir -pv "$transcode"
# if plex is running in a nat'd VM, then localip will be the VM's ip address and all traffic to Plex will appear to come from localip
# in that scenario, set hostip in conf and ensure that $port is forwarded from the host to the VM
localip=$(ip route get 8.8.8.8 || echo "0.0.0.0")
if [ "$localip" = "0.0.0.0" ]
then
[ "$hostip" = "" ] && echo -e "\nfailed to get host ip, please set hostip manually in conf" && exit 1
localip="$hostip"
else
localip=$(awk <<<$localip '{gsub(".*src",""); print $1; exit}')
fi
hostip=${hostip:-"$localip"}
allowed_networks=" "
advertise_ip=" "
if [ "$mode" = "host" ]
then
port=32400
network_args=(--network "host")
[ "$plexlogin" != true ] && allowed_networks="$localip/24"
else
network_args=(-p "$port:32400/tcp")
if [ "$mode" = "bridged" ]
then
network_args+=( \
-p 3005:3005/tcp \
-p 8324:8324/tcp \
-p 32469:32469/tcp \
-p 1900:1900/udp \
-p 32410:32410/udp \
-p 32412:32412/udp \
-p 32413:32413/udp \
-p 32414:32414/udp)
fi
[ "$plexlogin" != true ] && allowed_networks="$localip/24,$docker_network"
[ "$plexlogin" = true ] && advertise_ip="http://$hostip:$port/"
fi
network_args+=(--env ALLOWED_NETWORKS="$allowed_networks" --env ADVERTISE_IP="$advertise_ip")
[ "$hardware_transcoding_device" != "" ] && hardware_transcoding_device="--device $hardware_transcoding_device"
[ "$plexlogin" = true ] && [ "$plex_claim_token" != "" ] && plex_claim_token="--env PLEX_CLAIM=$plex_claim_token"
set -x
docker run -d \
--name "$containername" \
--hostname "$servername" \
--restart "$restart_policy" \
"${media_vols[@]}" \
-v "$config:/config" \
-v "$transcode:/transcode" \
"${network_args[@]}" \
--env TZ="$tz" \
--env PLEX_UID="$uid" \
--env PLEX_GID="$gid" \
$hardware_transcoding_device \
$plex_claim_token \
"$image"
set +x
# https://unix.stackexchange.com/a/470629/338467
wait() {
local LOGLINE
while IFS= read -r LOGLINE || [[ -n "$LOGLINE" ]]; do
printf '%s\n' "$LOGLINE"
[[ "${LOGLINE}" == "$2" ]] && return 0
done < <(timeout "$1" $3)
return 0
}
wait 30 "Starting Plex Media Server." "docker logs -f $containername"
echo -e "\n$servername started in container $containername ($mode mode) at http://$hostip:$port/web"
echo "First time setup (see https://github.com/wpwoodjr/plex-docker#initial-startup-tips for more info):"
echo -e " o Using an incognito browser on the Docker host machine,\n do initial setup at http://localhost:$port/web"
# Remote Access settings page
[ "$plexlogin" = true ] && echo -e " o On the Remote Access settings page,\n specify public port as $port (or another port of your choosing)"
# Network settings page
[ "$mode" != "host" ] && [ "$plexlogin" = true ] \
&& echo -e " o If you are a Plex Pass subscriber, on the Network settings page\n set LAN Networks to $localip/24,$docker_network"
# Plex running in VM
[ "$hostip" != "$localip" ] && echo -e " o Plex appears to be running in a VM\n ensure that port $port is forwarded from the host to the VM"
if [ "$slideshow_speed_ms" != "default" ]
then
docker exec "$containername" \
/bin/bash -c \
"sed -i -e 's/this.onSlideShowAdvance,5e3/this.onSlideShowAdvance,$slideshow_speed_ms/g' \
/usr/lib/plexmediaserver/Resources/Plug-ins*/WebClient.bundle/Contents/Resources/js/chunk*.js"
docker exec "$containername" \
/bin/bash -c \
"grep -q 'this.onSlideShowAdvance,$slideshow_speed_ms' \
/usr/lib/plexmediaserver/Resources/Plug-ins*/WebClient.bundle/Contents/Resources/js/chunk*.js" \
|| { echo "Slideshow speed not set!"; exit 1; }
echo "Slideshow speed set to $slideshow_speed_ms milliseconds"
fi