2017-01-12 17:20:25 +00:00
#!/bin/bash
2020-04-07 14:33:24 +00:00
CONT_CONF_FILE = "/version.txt"
function addVarToConf {
local variable = " $1 "
local value = " $2 "
if [ ! -z " ${ variable } " ] ; then
echo ${ variable } = ${ value } >> ${ CONT_CONF_FILE }
fi
}
function readVarFromConf {
local variable = " $1 "
declare -n value = $2
if [ ! -z " ${ variable } " ] ; then
value = " $( grep -w ${ variable } ${ CONT_CONF_FILE } | cut -d'=' -f2 | tail -n 1) "
else
value = NULL
fi
}
2017-01-12 17:20:25 +00:00
function getVersionInfo {
local version = " $1 "
local token = " $2 "
declare -n remoteVersion = $3
declare -n remoteFile = $4
2017-12-05 14:25:31 +00:00
local channel
local tokenNeeded = 1
if [ ! -z " ${ PLEX_UPDATE_CHANNEL } " ] && [ " ${ PLEX_UPDATE_CHANNEL } " > 0 ] ; then
channel = " ${ PLEX_UPDATE_CHANNEL } "
2017-12-05 18:39:35 +00:00
elif [ " ${ version ,, } " = "beta" ] ; then
2017-12-05 14:25:31 +00:00
channel = 8
2017-01-12 17:20:25 +00:00
elif [ " ${ version ,, } " = "public" ] ; then
2017-12-05 14:25:31 +00:00
channel = 16
tokenNeeded = 0
2017-01-12 17:20:25 +00:00
else
2017-12-05 14:25:31 +00:00
channel = 8
fi
2020-04-07 14:33:24 +00:00
# Read container architecture info from file created when building Docker image
readVarFromConf "plex_build" plexBuild
readVarFromConf "plex_distro" plexDistro
local url = " https://plex.tv/downloads/details/5?build= ${ plexBuild } &channel= ${ channel } &distro= ${ plexDistro } "
2017-12-05 14:25:31 +00:00
if [ ${ tokenNeeded } -gt 0 ] ; then
url = " ${ url } &X-Plex-Token= ${ token } "
2017-01-12 17:20:25 +00:00
fi
2017-12-05 14:25:31 +00:00
local versionInfo = " $( curl -s " ${ url } " ) "
2017-01-12 17:20:25 +00:00
# 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' )
}
function installFromUrl {
installFromRawUrl " https://plex.tv/ ${ 1 } "
}
function installFromRawUrl {
local remoteFile = " $1 "
curl -J -L -o /tmp/plexmediaserver.deb " ${ remoteFile } "
local 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 1
fi
dpkg -i --force-confold /tmp/plexmediaserver.deb
rm -f /tmp/plexmediaserver.deb
}