mirror of
https://github.com/mrworf/plexupdate.git
synced 2025-08-19 12:59:40 -07:00
Improve version handling to prevent inadvertent downgrades (#226)
* Improve version handling to prevent inadvertent downgrades * Add verbose output for version checking * Improved git branch handling for testing * Stay on current branch unless BRANCHNAME is set * Add verbose output for in-use check
This commit is contained in:
parent
17cac380b1
commit
293e6d5ecb
2 changed files with 65 additions and 21 deletions
|
@ -198,6 +198,7 @@ running() {
|
||||||
# Get a total count of active media (MediaContainer size), then deduct one for every paused stream.
|
# Get a total count of active media (MediaContainer size), then deduct one for every paused stream.
|
||||||
# If all streams are paused, we consider the server to not be active.
|
# If all streams are paused, we consider the server to not be active.
|
||||||
local mediacount="$(awk -F'"' '/<MediaContainer size="[0-9]+">/ {count+=$2}; /<Player[^>]* state="paused"/ {count--}; END {print count}' <<< "${DATA}")"
|
local mediacount="$(awk -F'"' '/<MediaContainer size="[0-9]+">/ {count+=$2}; /<Player[^>]* state="paused"/ {count--}; END {print count}' <<< "${DATA}")"
|
||||||
|
[ "$VERBOSE" = "yes" ] && printf 'Activity check reports a count of %i, based on return data of:\n%s\n\n' "${mediacount}" "${DATA}" >&2
|
||||||
[ $mediacount -gt 0 ] && return 0
|
[ $mediacount -gt 0 ] && return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
@ -209,6 +210,53 @@ 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
|
||||||
|
}
|
||||||
|
|
||||||
|
parseVersion() {
|
||||||
|
if [ "${REDHAT}" = "yes" ]; then
|
||||||
|
cut -f2- -d- <<< "$1" | cut -f1-4 -d.
|
||||||
|
else
|
||||||
|
cut -f2 -d_ <<< "$1"
|
||||||
|
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
|
||||||
|
parseVersion "$rpmtemp"
|
||||||
|
else
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
error "Unknown OS, exiting."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
verboseOutput() {
|
||||||
|
if [ "$VERBOSE" = "yes" ]; then
|
||||||
|
for i in $@; do
|
||||||
|
info "$i=${!i}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Shared functions
|
# Shared functions
|
||||||
|
|
||||||
# SHARED
|
# SHARED
|
||||||
|
|
|
@ -228,8 +228,13 @@ if [ "${AUTOUPDATE}" = "yes" ]; then
|
||||||
elif ! git diff --quiet; then
|
elif ! git diff --quiet; then
|
||||||
warn "You have made changes to the plexupdate files, cannot auto update"
|
warn "You have made changes to the plexupdate files, cannot auto update"
|
||||||
else
|
else
|
||||||
|
if [ -z "${BRANCHNAME}" ]; then
|
||||||
|
BRANCHNAME="$(git symbolic-ref -q --short HEAD)"
|
||||||
|
elif [ "${BRANCHNAME}" != "$(git symbolic-ref -q --short HEAD)" ]; then
|
||||||
|
git checkout "${BRANCHNAME}"
|
||||||
|
fi
|
||||||
# Force FETCH_HEAD to point to the correct branch (for older versions of git which don't default to current branch)
|
# Force FETCH_HEAD to point to the correct branch (for older versions of git which don't default to current branch)
|
||||||
if git fetch origin ${BRANCHNAME:-master} --quiet && ! git diff --quiet FETCH_HEAD; then
|
if git fetch origin ${BRANCHNAME} --quiet && ! git diff --quiet FETCH_HEAD; then
|
||||||
info "Auto-updating..."
|
info "Auto-updating..."
|
||||||
|
|
||||||
# Use an associative array to store permissions. If you're running bash < 4, the declare will fail and we'll
|
# Use an associative array to store permissions. If you're running bash < 4, the declare will fail and we'll
|
||||||
|
@ -385,11 +390,7 @@ RELEASE=$(grep -ioe '"label"[^}]*' <<<"${wgetresults}" | grep -i "\"distro\":\"$
|
||||||
DOWNLOAD=$(echo ${RELEASE} | grep -m1 -ioe 'https://[^\"]*')
|
DOWNLOAD=$(echo ${RELEASE} | grep -m1 -ioe 'https://[^\"]*')
|
||||||
CHECKSUM=$(echo ${RELEASE} | grep -ioe '\"checksum\"\:\"[^\"]*' | sed 's/\"checksum\"\:\"//')
|
CHECKSUM=$(echo ${RELEASE} | grep -ioe '\"checksum\"\:\"[^\"]*' | sed 's/\"checksum\"\:\"//')
|
||||||
|
|
||||||
if [ "$VERBOSE" = "yes" ]; then
|
verboseOutput RELEASE DOWNLOAD CHECKSUM
|
||||||
for i in RELEASE DOWNLOAD CHECKSUM; do
|
|
||||||
info "$i=${!i}"
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "${DOWNLOAD}" ]; then
|
if [ -z "${DOWNLOAD}" ]; then
|
||||||
if [ "$DISTRO" = "ubuntu" -a "$BUILD" = "linux-ubuntu-armv7l" ]; then
|
if [ "$DISTRO" = "ubuntu" -a "$BUILD" = "linux-ubuntu-armv7l" ]; then
|
||||||
|
@ -423,30 +424,25 @@ 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="$(parseVersion "${FILENAME}")"
|
||||||
INSTALLED_VERSION=$(dpkg-query -s plexmediaserver 2>/dev/null | grep -Po 'Version: \K.*')
|
verboseOutput INSTALLED_VERSION FILE_VERSION
|
||||||
else
|
|
||||||
if [ "${AUTOINSTALL}" = "yes" -a "${AUTOSTART}" = "no" ]; then
|
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."
|
warn "Your distribution may require the use of the AUTOSTART [-s] option for the service to start after the upgrade completes."
|
||||||
fi
|
fi
|
||||||
INSTALLED_VERSION=$(rpm -qv plexmediaserver 2>/dev/null)
|
|
||||||
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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue