pms-docker/root/etc/cont-init.d/50-plex-update
Graham Booker b2c4f8109a Changed latest->plexpass to allow latest to be tagged to a version.
Also the updater always behaves how the image was tagged at build.
2016-12-12 10:41:27 -06:00

81 lines
2.7 KiB
Plaintext
Executable File

#!/usr/bin/with-contenv bash
# If we are debugging, enable trace
if [ "${DEBUG,,}" = "true" ]; then
set -x
fi
function getPref {
local key="$1"
xmlstarlet sel -T -t -m "/Preferences" -v "@${key}" -n "${prefFile}"
}
# Get token
[ -f /etc/default/plexmediaserver ] && . /etc/default/plexmediaserver
pmsApplicationSupportDir="${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR:-${HOME}/Library/Application Support}"
prefFile="${pmsApplicationSupportDir}/Plex Media Server/Preferences.xml"
token="$(getPref "PlexOnlineToken")"
# Determine current version
if (dpkg --get-selections plexmediaserver 2> /dev/null | grep -wq "install"); then
installedVersion=$(dpkg-query -W -f='${Version}' plexmediaserver 2> /dev/null)
else
installedVersion="none"
fi
# Read set version
versionToInstall="$(cat /version.txt)"
if [ -z "${versionToInstall}" ]; then
echo "No version specified in install. Broken image"
exit 1
fi
# Short-circuit test of version before remote check to see if it's already installed.
if [ "${versionToInstall}" = "${installedVersion}" ]; then
exit 0
fi
# Get updated version number
if [ "${versionToInstall,,}" = "plexpass" ]; then
versionInfo="$(curl -s "https://plex.tv/downloads/details/1?build=linux-ubuntu-x86_64&channel=8&distro=ubuntu&X-Plex-Token=${token}")"
elif [ "${versionToInstall,,}" = "public" ]; then
versionInfo="$(curl -s "https://plex.tv/downloads/details/1?build=linux-ubuntu-x86_64&channel=16&distro=ubuntu")"
else
versionInfo="$(curl -s "https://plex.tv/downloads/details/1?build=linux-ubuntu-x86_64&channel=8&distro=ubuntu&X-Plex-Token=${token}&version=${versionToInstall}")"
fi
if [ -z "${versionInfo}" ]; then
echo "Could not get any update information"
exit 0
fi
# Get update info from the XML. Note: This could countain multiple updates when user specifies an exact version with the lowest first, so we'll use first always.
remoteVersion=$(echo "${versionInfo}" | sed -n 's/.*Release.*version="\([^"]*\)".*/\1/p')
remoteFile=$(echo "${versionInfo}" | sed -n 's/.*file="\([^"]*\)".*/\1/p')
if [ -z "${remoteVersion}" ] || [ -z "${remoteFile}" ]; then
echo "Could not get update version"
exit 0
fi
# Check if there's no update required
if [ "${remoteVersion}" = "${installedVersion}" ]; then
exit 0
fi
# Do update process
echo "Atempting to upgrade to: ${remoteVersion}"
rm -f /tmp/plexmediaserver*.deb
wget -nv --show-progress --progress=bar:force:noscroll -O /tmp/plexmediaserver.deb \
"https://plex.tv/${remoteFile}"
last=$?
# test if deb file size is ok, or if download failed
if [[ "$last" -gt "0" ]] || [[ $(stat -c %s /tmp/plexmediaserver.deb) -lt 10000 ]]; then
echo "Failed to fetch update"
exit 0
fi
dpkg -i --force-confold /tmp/plexmediaserver.deb
rm -f /tmp/plexmediaserver.deb