Moved common functionality to another file.

Also added support for building image from a raw URL for PMS.
This commit is contained in:
Graham Booker 2017-01-12 11:20:25 -06:00
parent f35feabd2d
commit 51695ec3e1
No known key found for this signature in database
GPG Key ID: 7FA620B73BAFAB5B
4 changed files with 57 additions and 44 deletions

View File

@ -44,6 +44,7 @@ ENV CHANGE_CONFIG_DIR_OWNERSHIP="true" \
HOME="/config"
ARG TAG=plexpass
ARG URL=
COPY root/ /

View File

@ -5,6 +5,8 @@ if [ "${DEBUG,,}" = "true" ]; then
set -x
fi
. /plex-common.sh
function getPref {
local key="$1"
@ -37,22 +39,8 @@ if [ "${versionToInstall}" = "${installedVersion}" ]; then
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
getVersionInfo "${versionToInstall}" "${token}" remoteVersion remoteFile
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
@ -64,16 +52,5 @@ if [ "${remoteVersion}" = "${installedVersion}" ]; then
fi
# Do update process
echo "Atempting to upgrade to: ${remoteVersion}"
rm -f /tmp/plexmediaserver*.deb
curl -J -L -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
echo "Attempting to upgrade to: ${remoteVersion}"
installFromUrl "${remoteFile}"

View File

@ -1,26 +1,19 @@
#!/bin/bash
. /plex-common.sh
echo "${TAG}" > /version.txt
if [ "${TAG}" != "plexpass" ] && [ "${TAG}" != "public" ]; then
versionInfo="$(curl -s "https://plex.tv/downloads/details/1?build=linux-ubuntu-x86_64&channel=8&distro=ubuntu&X-Plex-Token=${token}&version=${TAG}")"
remoteVersion=$(echo "${versionInfo}" | sed -n 's/.*Release.*version="\([^"]*\)".*/\1/p')
remoteFile=$(echo "${versionInfo}" | sed -n 's/.*file="\([^"]*\)".*/\1/p')
if [ ! -z "${URL}" ]; then
echo "Attempting to install from URL: ${URL}"
installFromRawUrl "${URL}"
elif [ "${TAG}" != "plexpass" ] && [ "${TAG}" != "public" ]; then
getVersionInfo "${TAG}" "" remoteVersion remoteFile
if [ -z "${remoteVersion}" ] || [ -z "${remoteFile}" ]; then
echo "Could not get install version"
exit 1
fi
echo "Atempting to install: ${remoteVersion}"
curl -J -L -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 1
fi
dpkg -i --force-confold /tmp/plexmediaserver.deb
rm -f /tmp/plexmediaserver.deb
echo "Attempting to install: ${remoteVersion}"
installFromUrl "${remoteFile}"
fi

42
root/plex-common.sh Executable file
View File

@ -0,0 +1,42 @@
#!/bin/bash
function getVersionInfo {
local version="$1"
local token="$2"
declare -n remoteVersion=$3
declare -n remoteFile=$4
local versionInfo
if [ "${version,,}" = "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 [ "${version,,}" = "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=${version}")"
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')
}
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
}