diff --git a/plexupdate-core b/plexupdate-core index 70310cc..8ea4fc4 100755 --- a/plexupdate-core +++ b/plexupdate-core @@ -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 diff --git a/plexupdate.sh b/plexupdate.sh index b0a138d..987827e 100755 --- a/plexupdate.sh +++ b/plexupdate.sh @@ -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