2
0
mirror of https://github.com/spritsail/plex-media-server.git synced 2024-12-20 11:34:36 +00:00
plex-media-server/claim-server.sh
Joe Groocock f01f4950ab
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

Restructure build into multiple distinct Docker build stages to better
leverage caching and significantly improve build time on multicore
systems with BuildKit, particularly with LTO enabled.

Changes for this release include:
- 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-05-28 10:12:19 +00:00

63 lines
1.9 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="$(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