2
0
mirror of https://github.com/spritsail/plex-media-server.git synced 2025-05-05 06:22:29 +00:00
plex-media-server/claim-server.sh
Joe Groocock 32734c3aa0
Build Plex on musl, from scratch
Plex now provide a first-party musl Plex build that works without any
external dependencies whatsoever. It's built with LLVM with many
compiler and linker optimisations enabled:
https://forums.plex.tv/t/plex-media-server-forum-preview-faster-and-smaller-builds-with-new-toolchain/699575

Changes for this release include:
- Drop curl, OpenSSL and zlib; they're no longer required. libcurl and
  libssl/libcrypto are provided by Plex anyway.
- Build `FROM spritsail/alpine` instead of `FROM debian` to ensure musl
  compatibility with all compiled binaries. Use `FROM scratch` for the
  resulting image. ld-musl is provided by Plex.
- Build busybox, su-exec and tini as they're no longer provided by the
  base image.
- Build binaries/libraries with standard hardening flags, including the
  popular -flto.

Signed-off-by: Joe Groocock <me@frebib.net>
2021-03-13 17:29:51 +00:00

63 lines
2.0 KiB
Bash
Executable File

#!/bin/sh
set -e
# Contains getPref/setPref and PREF_FILE vars
. 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="$(wget -O- --post-data= \
--header "X-Plex-Client-Identifier: ${clientId}" \
--header "X-Plex-Product: Plex Media Server" \
--header "X-Plex-Version: 1.1" \
--header "X-Plex-Provides: server" \
--header "X-Plex-Platform: Linux" \
--header "X-Plex-Platform-Version: 1.0" \
--header "X-Plex-Device-Name: PlexMediaServer" \
--header "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