mirror of
https://github.com/mrworf/plexupdate.git
synced 2025-08-20 21:33:16 -07:00
Improve version handling to prevent inadvertent downgrades
This commit is contained in:
parent
17cac380b1
commit
45198ae46f
2 changed files with 42 additions and 17 deletions
|
@ -209,6 +209,37 @@ verifyToken() {
|
||||||
wget -qO /dev/null "https://plex.tv/api/resources?X-Plex-Token=${TOKEN}"
|
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 functions
|
||||||
|
|
||||||
# SHARED
|
# SHARED
|
||||||
|
|
|
@ -423,32 +423,26 @@ fi
|
||||||
# By default, try downloading
|
# By default, try downloading
|
||||||
SKIP_DOWNLOAD="no"
|
SKIP_DOWNLOAD="no"
|
||||||
|
|
||||||
# Installed version detection
|
INSTALLED_VERSION="$(getPlexVersion)" || warn "Unable to detect installed version, first time?"
|
||||||
if [ "${REDHAT}" != "yes" ]; then
|
FILE_VERSION="$(cut -f2 -d_ <<< "${FILENAME}")"
|
||||||
INSTALLED_VERSION=$(dpkg-query -s plexmediaserver 2>/dev/null | grep -Po 'Version: \K.*')
|
|
||||||
else
|
if [ "${REDHAT}" = "yes" -a "${AUTOINSTALL}" = "yes" -a "${AUTOSTART}" = "no" ]; then
|
||||||
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."
|
||||||
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)
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${CHECKONLY}" = "yes" ]; then
|
if [ "${CHECKONLY}" = "yes" ]; then
|
||||||
if [ -z "${INSTALLED_VERSION}" ]; then
|
if [ -n "${INSTALLED_VERSION}" ] && isNewerVersion "$FILE_VERSION" "$INSTALLED_VERSION" then
|
||||||
warn "Unable to detect installed version, first time?"
|
info "Your OS reports Plex $INSTALLED_VERSION installed, newer version is available (${FILE_VERSION})"
|
||||||
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})"
|
|
||||||
exit 7
|
exit 7
|
||||||
else
|
elif [ -n "${INSTALLED_VERSION}" ]; then
|
||||||
info "You are running the latest version of Plex (${INSTALLED_VERSION})"
|
info "You are running the latest version of Plex (${INSTALLED_VERSION})"
|
||||||
fi
|
fi
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $FILENAME == *$INSTALLED_VERSION* ]] && [ "${FORCE}" != "yes" ] && [ ! -z "${INSTALLED_VERSION}" ]; then
|
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."
|
info "Your OS reports the latest version of Plex ($INSTALLED_VERSION) is already installed. Use -f to force download."
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "${DOWNLOADDIR}/${FILENAME}" ]; then
|
if [ -f "${DOWNLOADDIR}/${FILENAME}" ]; then
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue