Add support for PLEX_CLAIM

pull/217/head
aptalca 5 years ago committed by Ryan Kuba
parent e01485d831
commit e8cd4d7e89

@ -69,6 +69,7 @@ docker create \
-e PGID=1000 \
-e VERSION=docker \
-e UMASK_SET=022 `#optional` \
-e PLEX_CLAIM= `#optional` \
-v </path/to/library>:/config \
-v <path/to/tvseries>:/tv \
-v </path/to/movies>:/movies \
@ -95,6 +96,7 @@ services:
- PGID=1000
- VERSION=docker
- UMASK_SET=022 #optional
- PLEX_CLAIM= #optional
volumes:
- </path/to/library>:/config
- <path/to/tvseries>:/tv
@ -114,6 +116,7 @@ Container images are configured using parameters passed at runtime (such as thos
| `-e PGID=1000` | for GroupID - see below for explanation |
| `-e VERSION=docker` | Set whether to update plex or not - see Application Setup section. |
| `-e UMASK_SET=022` | control permissions of files and directories created by Plex |
| `-e PLEX_CLAIM=` | Optionally you can obtain a claim token from https://plex.tv/claim and input here. Keep in mind that the claim tokens expire within 4 minutes. |
| `-v /config` | Plex library location. *This can grow very large, 50gb+ is likely for a large collection.* |
| `-v /tv` | Media goes here. Add as many as needed e.g. `/movies`, `/tv`, etc. |
| `-v /movies` | Media goes here. Add as many as needed e.g. `/movies`, `/tv`, etc. |
@ -133,7 +136,7 @@ Will set the environment variable `PASSWORD` based on the contents of the `/run/
## Optional Parameters
*Special note* - If you'd like to run Plex without requiring `--net=host` (`NOT recommended`) then you will need the following ports in your `docker create` command:
*Special note* - If you'd like to run Plex without requiring `--net=host` (`NOT recommended`) then you will need the following ports in your `docker create` command (you need to set PLEX_CLAIM to claim a server set up with bridge networking):
```
-p 32400:32400 \
@ -262,6 +265,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
## Versions
* **04.12.19:** - Add variable for setting PLEX_CLAIM.
* **06.08.19:** - Add variable for setting UMASK.
* **10.07.19:** - Fix permissions for tuner (/dev/dvb) devices.
* **20.05.19:** - Bugfix do not allow Root group for Intel QuickSync ownership rules.

@ -34,9 +34,10 @@ param_env_vars:
opt_param_usage_include_env: true
opt_param_env_vars:
- { env_var: "UMASK_SET", env_value: "022", desc: "control permissions of files and directories created by Plex"}
- { env_var: "PLEX_CLAIM", env_value: "", desc: "Optionally you can obtain a claim token from https://plex.tv/claim and input here. Keep in mind that the claim tokens expire within 4 minutes."}
optional_parameters: |
*Special note* - If you'd like to run Plex without requiring `--net=host` (`NOT recommended`) then you will need the following ports in your `docker create` command:
*Special note* - If you'd like to run Plex without requiring `--net=host` (`NOT recommended`) then you will need the following ports in your `docker create` command (you need to set PLEX_CLAIM to claim a server set up with bridge networking):
```
-p 32400:32400 \
@ -86,6 +87,7 @@ app_setup_block: |
# changelog
changelogs:
- { date: "04.12.19:", desc: "Add variable for setting PLEX_CLAIM." }
- { date: "06.08.19:", desc: "Add variable for setting UMASK." }
- { date: "10.07.19:", desc: "Fix permissions for tuner (/dev/dvb) devices." }
- { date: "20.05.19:", desc: "Bugfix do not allow Root group for Intel QuickSync ownership rules." }

@ -0,0 +1,43 @@
#!/usr/bin/with-contenv bash
if grep -qs "PlexOnlineToken" "/config/Library/Application Support/Plex Media Server/Preferences.xml" || [ -z "$PLEX_CLAIM" ]; then
exit 0
fi
if [ ! -f "/config/Library/Application Support/Plex Media Server/Preferences.xml" ]; then
UMASK_SET=${UMASK_SET:-022}
umask "$UMASK_SET"
echo "Temporarily starting Plex Media Server."
export PLEX_MEDIA_SERVER_INFO_MODEL=$(uname -m)
export PLEX_MEDIA_SERVER_INFO_PLATFORM_VERSION=$(uname -r)
s6-setuidgid abc /bin/bash -c \
'LD_LIBRARY_PATH=/usr/lib/plexmediaserver:/usr/lib/plexmediaserver/lib /usr/lib/plexmediaserver/Plex\ Media\ Server' &
echo "Waiting for Plex to generate its config"
until grep -qs "ProcessedMachineIdentifier" "/config/Library/Application Support/Plex Media Server/Preferences.xml"; do
sleep 1
done
echo "Stopping Plex to claim server"
kill $(cat "/config/Library/Application Support/Plex Media Server/plexmediaserver.pid")
wait
echo "Plex stopped"
fi
ProcessedMachineIdentifier=$(sed -n "s/^.*ProcessedMachineIdentifier=\"\([^\"]*\)\".*$/\1/p" "/config/Library/Application Support/Plex Media Server/Preferences.xml")
PlexOnlineToken="$(curl -X POST \
-H 'X-Plex-Client-Identifier: '"${ProcessedMachineIdentifier}" \
-H 'X-Plex-Product: Plex Media Server'\
-H 'X-Plex-Version: 1.1' \
-H 'X-Plex-Provides: server' \
-H 'X-Plex-Platform: Linux' \
-H 'X-Plex-Platform-Version: 1.0' \
-H 'X-Plex-Device-Name: PlexMediaServer' \
-H 'X-Plex-Device: Linux' \
"https://plex.tv/api/claim/exchange?token=${PLEX_CLAIM}" \
| sed -n 's/.*<authentication-token>\(.*\)<\/authentication-token>.*/\1/p')"
if [ -n "$PlexOnlineToken" ]; then
echo "Server claimed successfully, navigate to http://serverip:32400/web to complete plex setup."
sed -i "s/\/>/ PlexOnlineToken=\"${PlexOnlineToken}\"\/>/g" "/config/Library/Application Support/Plex Media Server/Preferences.xml"
else
echo "Unable to claim Plex server. Either manually claim by connecting to http://serverip:32400/web from the same network subnet, or recreate container with a new claim token."
fi
Loading…
Cancel
Save