From 2064fb2744d9432f48b4e648eedc0820a685fd80 Mon Sep 17 00:00:00 2001 From: Alex Malinovich Date: Tue, 28 Feb 2017 11:34:08 -0800 Subject: [PATCH] Use local vars in functions and fix getRemoteSHA --- plexupdate-core | 13 ++++++++----- plexupdate.sh | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/plexupdate-core b/plexupdate-core index 91f9706..aafb8ec 100755 --- a/plexupdate-core +++ b/plexupdate-core @@ -91,9 +91,9 @@ getPlexServerToken() { # GPW getPlexWebToken() { - FILE_POSTDATA=$(mktemp /tmp/plexupdate.postdata.XXXX) - FILE_RAW=$(mktemp /tmp/plexupdate.raw.XXXX) - FILE_FAILCAUSE=$(mktemp /tmp/plexupdate.failcause.XXXX) + local FILE_POSTDATA=$(mktemp /tmp/plexupdate.postdata.XXXX) + local FILE_RAW=$(mktemp /tmp/plexupdate.raw.XXXX) + local FILE_FAILCAUSE=$(mktemp /tmp/plexupdate.failcause.XXXX) # Fields we need to submit for login to work # @@ -114,7 +114,7 @@ getPlexWebToken() { wget --header "X-Plex-Client-Identifier: 4a745ae7-1839-e44e-1e42-aebfa578c865" --header "X-Plex-Product: Plex SSO" "${URL_LOGIN}" --post-file="${FILE_POSTDATA}" -q -S -O "${FILE_FAILCAUSE}" 2>"${FILE_RAW}" # Provide some details to the end user - RESULTCODE=$(head -n1 "${FILE_RAW}" | grep -oe '[1-5][0-9][0-9]') + local RESULTCODE=$(head -n1 "${FILE_RAW}" | grep -oe '[1-5][0-9][0-9]') if [ $RESULTCODE -eq 401 ]; then error "Username and/or password incorrect" elif [ $RESULTCODE -ne 201 ]; then @@ -166,7 +166,10 @@ trimQuotes() { } getRemoteSHA() { - (wget -q "$1" -O - 2>/dev/null || return 1) | sha1sum | cut -f1 -d" " + # these two lines can't be combined. `local RESULT=` will gobble up the return + local RESULT + RESULT=$(wget -q "$1" -O - 2>/dev/null) || return 1 + sha1sum <<< "$RESULT" | cut -f1 -d" " } getLocalSHA() { diff --git a/plexupdate.sh b/plexupdate.sh index 74c8838..6597978 100755 --- a/plexupdate.sh +++ b/plexupdate.sh @@ -339,7 +339,7 @@ if [ "${PUBLIC}" = "no" -a -z "$TOKEN" ]; then [ -f "$TO_SOURCE" ] && source $TO_SOURCE if ! getPlexToken; then error "Unable to get Plex token, falling back to public release" - PUBLiC="yes" + PUBLIC="yes" fi fi