Merge branch 'master' into pass

This commit is contained in:
Joe Groocock 2018-10-04 12:51:57 +01:00
commit 9cb19b83bf
Signed by: frebib
GPG Key ID: E0B16BEACFBB6A86
6 changed files with 103 additions and 47 deletions

View File

@ -17,8 +17,6 @@ ARG XMLSTAR_VER
ARG LIBRE_VER=2.7.4 ARG LIBRE_VER=2.7.4
ARG CURL_VER ARG CURL_VER
ARG MAKEFLAGS=-j4
RUN apt-get -y update \ RUN apt-get -y update \
&& apt-get -y install zlib1g-dev && apt-get -y install zlib1g-dev
@ -36,8 +34,8 @@ RUN git clone https://gitlab.gnome.org/GNOME/libxml2.git --branch $LIBXML2_VER -
--without-legacy \ --without-legacy \
--without-modules \ --without-modules \
--without-python \ --without-python \
&& make \ && make -j$(nproc) \
&& make DESTDIR=/prefix install && make -j$(nproc) DESTDIR=/prefix install
# Download and build libxslt # Download and build libxslt
WORKDIR /tmp/libxslt WORKDIR /tmp/libxslt
@ -48,8 +46,8 @@ RUN git clone https://gitlab.gnome.org/GNOME/libxslt.git --branch $LIBXSLT_VER -
--without-crypto \ --without-crypto \
--without-plugins \ --without-plugins \
--without-python \ --without-python \
&& make \ && make -j$(nproc) \
&& make DESTDIR=/prefix install && make -j$(nproc) DESTDIR=/prefix install
# Download and build xmlstarlet # Download and build xmlstarlet
ADD xmlstarlet-*.patch /tmp ADD xmlstarlet-*.patch /tmp
@ -62,8 +60,8 @@ RUN git clone git://git.code.sf.net/p/xmlstar/code --branch $XMLSTAR_VER --depth
--disable-build-docs \ --disable-build-docs \
--with-libxml-prefix=/prefix/usr \ --with-libxml-prefix=/prefix/usr \
--with-libxslt-prefix=/prefix/usr \ --with-libxslt-prefix=/prefix/usr \
&& make \ && make -j$(nproc) \
&& make DESTDIR=/prefix install && make -j$(nproc) DESTDIR=/prefix install
# Download and build LibreSSL as a cURL dependency # Download and build LibreSSL as a cURL dependency
WORKDIR /tmp/libressl WORKDIR /tmp/libressl
@ -71,7 +69,7 @@ RUN curl -sSL https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-${LIBRE_VER}
| tar xz --strip-components=1 \ | tar xz --strip-components=1 \
# Install to the default system directories so cURL can find it # Install to the default system directories so cURL can find it
&& ./configure --prefix=/usr \ && ./configure --prefix=/usr \
&& make install && make -j$(nproc) install
# Download and build curl # Download and build curl
WORKDIR /tmp/curl WORKDIR /tmp/curl
@ -111,8 +109,8 @@ RUN git clone https://github.com/curl/curl.git --branch $CURL_VER --depth 1 . \
--without-libpsl \ --without-libpsl \
--without-librtmp \ --without-librtmp \
--without-winidn \ --without-winidn \
&& make \ && make -j$(nproc) \
&& make DESTDIR=/prefix install && make -j$(nproc) DESTDIR=/prefix install
WORKDIR /prefix WORKDIR /prefix

View File

@ -25,7 +25,7 @@ _*last we checked_
Navigate to [plex.tv/claim](https://www.plex.tv/claim) and obtain a token in the form `claim-xxxx...` Navigate to [plex.tv/claim](https://www.plex.tv/claim) and obtain a token in the form `claim-xxxx...`
Start the container, as demonstrated below, passing the claim token via the `PLEX_CLAIM` environment variable. This only has to be present on the first run (when the configuration is generated) and can be removed for subsequent runs. _The Plex claim token is optional however it will make the server available to your account immediately._ Start the container, as demonstrated below, passing the claim token via the `PLEX_CLAIM` environment variable. This only has to be present on the first run (when the configuration is generated/if you need to re-claim the server at any time) and can be removed for subsequent runs. _The Plex claim token is optional however it will make the server available to your account immediately._
Setting the container hostname on first boot will set the Plex server name. Setting the container hostname on first boot will set the Plex server name.
@ -80,3 +80,8 @@ See also: https://support.plex.tv/articles/201543147-what-network-ports-do-i-nee
At the very least, you should expose `32400/tcp` to your network, and _port forward_ it through your router if you would like Plex access outside your home network. At the very least, you should expose `32400/tcp` to your network, and _port forward_ it through your router if you would like Plex access outside your home network.
If you wish, you can map the Plex port to any other port outside your network, just be sure to update the port in _Settings > Server > Remote Access_ (Show Advanced) under _Manually specify public port_. If you wish, you can map the Plex port to any other port outside your network, just be sure to update the port in _Settings > Server > Remote Access_ (Show Advanced) under _Manually specify public port_.
## Troubleshooting
* **Help, I accidentally logged my server out and I can no longer access it**
Just get another claim token from [plex.tv/claim](https://www.plex.tv/claim) and restart the container with it in the environment variable PLEX_CLAIM. This should re-claim your server and it'll appear in your server list once again. You can remove the claim token as soon as the server has been claimed- _they expire after 5 minutes anyway_

61
claim-server.sh Executable file
View File

@ -0,0 +1,61 @@
#!/bin/sh
set -e
# Contains getPref/setPref and PREF_FILE vars
source plex-util.sh
opts=`getopt -n "$0" -l save -l token: -l client-id: -l load-client-id -- st:c:l "$@"` || exit 1
eval set -- "$opts"
while true; do
case "$1" in
-s|--save) save=true; shift;;
-t|--token) claimToken="$2"; shift 2;;
-c|--client-id) clientId="$2"; shift 2;;
-l|--load-client-id) clientId="$(getPref "ProcessedMachineIdentifier")"; shift;;
--) shift; break;;
*) echo 'Error: getopt'; exit 1;;
esac
done
claimToken="${PLEX_CLAIM:-$claimToken}"
clientId="${PLEX_CLIENT_ID:-$clientId}"
if [ -z "${claimToken}" ]; then
>&2 echo "Error: \$PLEX_CLAIM or --token required to claim a server"
>&2 echo " Obtain one from https://plex.tv/claim"
exit 2
fi
if [ -z "${clientId}" ]; then
>&2 echo "Error: \$PLEX_CLIENT_ID or --client-id required to claim a server"
>&2 echo " This is found as 'ProcessedMachineIdentifier' in Preferences.xml"
>&2 echo " Calling this script with --load-client-id will attempt to populate this for you"
exit 3
fi
>&2 echo "Attempting to obtain server token from claim token"
loginInfo="$(curl -X POST \
-H 'X-Plex-Client-Identifier: '${clientId} \
-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=${claimToken}")"
authtoken="$(echo "$loginInfo" | sed -n 's/.*<authentication-token>\(.*\)<\/authentication-token>.*/\1/p')"
if [ -z "$authtoken" ]; then
>&2 echo "Error: Unable to obtain authentication token from Plex"
exit 10
else
>&2 echo "Token obtained successfully"
fi
if [ -n "$save" ]; then
setPref "PlexOnlineToken" "${authtoken}"
else
printf "%s" "$authtoken"
fi

View File

@ -44,11 +44,19 @@ export PREF_FILE="$CONFIG_DIR/Preferences.xml"
exec su-exec -e sh <<EOF exec su-exec -e sh <<EOF
source plex-util.sh
# Generate a default configuration on first run, including some user-specified values # Generate a default configuration on first run, including some user-specified values
if [ ! -e "\$PREF_FILE" ]; then if [ ! -e "\$PREF_FILE" ]; then
source gen-config.sh source gen-config.sh
fi fi
# Always attempt to claim an unclaimed server in case it was signed out
token="\$(getPref "PlexOnlineToken")"
if [ ! -z "\${PLEX_CLAIM}" ] && [ -z "\${token}" ]; then
claim-server.sh --load-client-id --save
fi
# Duplicate the Plex logs to stdout (docker logs) # Duplicate the Plex logs to stdout (docker logs)
tail -Fn 0 "\$CONFIG_DIR/Logs/Plex Media Server.log" 2>/dev/null & tail -Fn 0 "\$CONFIG_DIR/Logs/Plex Media Server.log" 2>/dev/null &

View File

@ -1,20 +1,8 @@
#!/bin/sh #!/bin/sh
set -e set -e
CONFIG_DIR="${CONFIG_DIR:-/config}" # Contains getPref/setPref and PREF_FILE vars
PREF_FILE="${PREF_FILE:-"$CONFIG_DIR/Preferences.xml"}" source plex-util.sh
getPref() {
xmlstarlet sel -T -t -m "/Preferences" -v "@$1" -n "${PREF_FILE}"
}
setPref() {
count="$(xmlstarlet sel -t -v "count(/Preferences/@$1)" "${PREF_FILE}")"
if [ $(($count + 0)) -gt 0 ]; then
xmlstarlet ed --inplace --update "/Preferences/@$1" -v "$2" "${PREF_FILE}" 2>/dev/null
else
xmlstarlet ed --inplace --insert "/Preferences" --type attr -n "$1" -v "$2" "${PREF_FILE}" 2>/dev/null
fi
}
# Create a default config file allowing external access # Create a default config file allowing external access
echo -e $'<?xml version="1.0" encoding="utf-8"?>\n<Preferences />' > "${PREF_FILE}" echo -e $'<?xml version="1.0" encoding="utf-8"?>\n<Preferences />' > "${PREF_FILE}"
@ -38,27 +26,9 @@ if [ -z "${clientId}" ]; then
setPref "ProcessedMachineIdentifier" "${clientId}" setPref "ProcessedMachineIdentifier" "${clientId}"
fi fi
# Get server token and only turn claim token into server token if we have former but not latter. # Claiming the PlexOnlineToken is now done in entrypoint on every boot
token="$(getPref "PlexOnlineToken")" # It can also be triggered manually at any time by running
if [ ! -z "${PLEX_CLAIM}" ] && [ -z "${token}" ]; then # $ claim-server.sh --load-client-id --save
echo "Attempting to obtain server token from claim token"
loginInfo="$(curl -X POST \
-H 'X-Plex-Client-Identifier: '${clientId} \
-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}")"
token="$(echo "$loginInfo" | sed -n 's/.*<authentication-token>\(.*\)<\/authentication-token>.*/\1/p')"
if [ "$token" ]; then
echo "Token obtained successfully"
setPref "PlexOnlineToken" "${token}"
fi
fi
test -n "${ADVERTISE_IP}" && setPref "customConnections" "${ADVERTISE_IP}" test -n "${ADVERTISE_IP}" && setPref "customConnections" "${ADVERTISE_IP}"
test -n "${ALLOWED_NETWORKS}" && setPref "allowedNetworks" "${ALLOWED_NETWORKS}" test -n "${ALLOWED_NETWORKS}" && setPref "allowedNetworks" "${ALLOWED_NETWORKS}"

14
plex-util.sh Normal file
View File

@ -0,0 +1,14 @@
CONFIG_DIR="${CONFIG_DIR:-/config}"
PREF_FILE="${PREF_FILE:-"$CONFIG_DIR/Preferences.xml"}"
getPref() {
xmlstarlet sel -T -t -m "/Preferences" -v "@$1" -n "${PREF_FILE}"
}
setPref() {
count="$(xmlstarlet sel -t -v "count(/Preferences/@$1)" "${PREF_FILE}")"
if [ $(($count + 0)) -gt 0 ]; then
xmlstarlet ed --inplace --update "/Preferences/@$1" -v "$2" "${PREF_FILE}" 2>/dev/null
else
xmlstarlet ed --inplace --insert "/Preferences" --type attr -n "$1" -v "$2" "${PREF_FILE}" 2>/dev/null
fi
}