Improve version handling to prevent inadvertent downgrades

This commit is contained in:
Alex Malinovich 2018-03-08 23:48:12 -08:00
commit 45198ae46f
No known key found for this signature in database
GPG key ID: F3327D1AA93CF5F0
2 changed files with 42 additions and 17 deletions

View file

@ -209,6 +209,37 @@ verifyToken() {
wget -qO /dev/null "https://plex.tv/api/resources?X-Plex-Token=${TOKEN}"
}
isNewerVersion() {
# Returns true ONLY if 1 > 2.
[ -z "$1" ] && return 1
[ -z "$2" ] && return
[ "$1" = "$2" ] && return 1
if hash dpkg 2>/dev/null; then
dpkg --compare-versions "$1" gt "$2"
elif sort -V --version &>/dev/null; then
[ "$(printf "$1\n$2" | sort -Vr | head -n1)" = "$1" ]
else
# sort has had -V since at least 2009, so nobody should ever see this
warn "Unable to compare version numbers, assuming '$1' is newer."
fi
}
getPlexVersion() {
if [ "${REDHAT}" != "yes" ]; then
dpkg-query --showformat='${Version}' --show plexmediaserver 2>/dev/null
elif hash rpm 2>/dev/null; then
local rpmtemp
if rpmtemp=$(rpm -q plexmediaserver); then
cut -f2 -d_ <<< "$rpmtemp"
else
return 1
fi
else
error "Unknown OS, exiting."
exit 1
fi
}
# Shared functions
# SHARED

View file

@ -423,32 +423,26 @@ fi
# By default, try downloading
SKIP_DOWNLOAD="no"
# Installed version detection
if [ "${REDHAT}" != "yes" ]; then
INSTALLED_VERSION=$(dpkg-query -s plexmediaserver 2>/dev/null | grep -Po 'Version: \K.*')
else
if [ "${AUTOINSTALL}" = "yes" -a "${AUTOSTART}" = "no" ]; then
warn "Your distribution may require the use of the AUTOSTART [-s] option for the service to start after the upgrade completes."
fi
INSTALLED_VERSION=$(rpm -qv plexmediaserver 2>/dev/null)
INSTALLED_VERSION="$(getPlexVersion)" || warn "Unable to detect installed version, first time?"
FILE_VERSION="$(cut -f2 -d_ <<< "${FILENAME}")"
if [ "${REDHAT}" = "yes" -a "${AUTOINSTALL}" = "yes" -a "${AUTOSTART}" = "no" ]; then
warn "Your distribution may require the use of the AUTOSTART [-s] option for the service to start after the upgrade completes."
fi
if [ "${CHECKONLY}" = "yes" ]; then
if [ -z "${INSTALLED_VERSION}" ]; then
warn "Unable to detect installed version, first time?"
elif [[ $FILENAME != *$INSTALLED_VERSION* ]]; then
AVAIL="$(echo "${FILENAME}" | sed -nr 's/^[^0-9]+([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+\-[^_]+).*/\1/pg')"
info "Your OS reports Plex $INSTALLED_VERSION installed, newer version is available (${AVAIL})"
if [ -n "${INSTALLED_VERSION}" ] && isNewerVersion "$FILE_VERSION" "$INSTALLED_VERSION" then
info "Your OS reports Plex $INSTALLED_VERSION installed, newer version is available (${FILE_VERSION})"
exit 7
else
elif [ -n "${INSTALLED_VERSION}" ]; then
info "You are running the latest version of Plex (${INSTALLED_VERSION})"
fi
exit 0
fi
if [[ $FILENAME == *$INSTALLED_VERSION* ]] && [ "${FORCE}" != "yes" ] && [ ! -z "${INSTALLED_VERSION}" ]; then
info "Your OS reports the latest version of Plex ($INSTALLED_VERSION) is already installed. Use -f to force download."
exit 0
if ! isNewerVersion "$FILE_VERSION" "$INSTALLED_VERSION" && [ "${FORCE}" != "yes" ]; then
info "Your OS reports the latest version of Plex ($INSTALLED_VERSION) is already installed. Use -f to force download."
exit 0
fi
if [ -f "${DOWNLOADDIR}/${FILENAME}" ]; then