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:
Alex Malinovich 2018-04-14 20:42:23 -07:00 committed by GitHub
commit 293e6d5ecb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 65 additions and 21 deletions

View file

@ -198,6 +198,7 @@ running() {
# 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.
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
fi
@ -209,6 +210,53 @@ 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
}
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