mirror of
https://github.com/mrworf/plexupdate.git
synced 2025-08-19 12:59:40 -07:00
Implement checksum checking
This commit is contained in:
parent
482f1d2c5a
commit
858a429362
1 changed files with 44 additions and 18 deletions
|
@ -51,6 +51,7 @@ PLEXSERVER=
|
||||||
# Defaults
|
# Defaults
|
||||||
# (aka "Advanced" settings, can be overriden with config file)
|
# (aka "Advanced" settings, can be overriden with config file)
|
||||||
FORCE=no
|
FORCE=no
|
||||||
|
FORCEALL=no
|
||||||
PUBLIC=no
|
PUBLIC=no
|
||||||
AUTOINSTALL=no
|
AUTOINSTALL=no
|
||||||
AUTODELETE=no
|
AUTODELETE=no
|
||||||
|
@ -142,7 +143,8 @@ usage() {
|
||||||
echo " -c Cron mode, only fatal errors return non-zero cronexit code"
|
echo " -c Cron mode, only fatal errors return non-zero cronexit code"
|
||||||
echo " -d Auto delete after auto install"
|
echo " -d Auto delete after auto install"
|
||||||
echo " -f Force download even if it's the same version or file"
|
echo " -f Force download even if it's the same version or file"
|
||||||
echo " already exists"
|
echo " already exists unless checksum passes"
|
||||||
|
echo " -F Force download always"
|
||||||
echo " -h This help"
|
echo " -h This help"
|
||||||
echo " -l List available builds and distros"
|
echo " -l List available builds and distros"
|
||||||
echo " -p Public Plex Media Server version"
|
echo " -p Public Plex Media Server version"
|
||||||
|
@ -157,7 +159,7 @@ usage() {
|
||||||
|
|
||||||
# Parse commandline
|
# Parse commandline
|
||||||
ALLARGS=( "$@" )
|
ALLARGS=( "$@" )
|
||||||
optstring="acCdfhlpqrSsuU"
|
optstring="acCdfFhlpqrSsuU"
|
||||||
getopt -T >/dev/null
|
getopt -T >/dev/null
|
||||||
if [ $? -eq 4 ]; then
|
if [ $? -eq 4 ]; then
|
||||||
optstring="-o $optstring"
|
optstring="-o $optstring"
|
||||||
|
@ -172,6 +174,7 @@ do
|
||||||
(-C) echo "ERROR: CRON option has changed, please review README.md" >&2; cronexit 255;;
|
(-C) echo "ERROR: CRON option has changed, please review README.md" >&2; cronexit 255;;
|
||||||
(-d) AUTODELETE=yes;;
|
(-d) AUTODELETE=yes;;
|
||||||
(-f) FORCE=yes;;
|
(-f) FORCE=yes;;
|
||||||
|
(-F) FORCEALL=yes;;
|
||||||
(-l) LISTOPTS=yes;;
|
(-l) LISTOPTS=yes;;
|
||||||
(-p) PUBLIC=yes;;
|
(-p) PUBLIC=yes;;
|
||||||
(-q) QUIET=yes;;
|
(-q) QUIET=yes;;
|
||||||
|
@ -429,8 +432,9 @@ fi
|
||||||
echo -n "Finding download URL to download..."
|
echo -n "Finding download URL to download..."
|
||||||
|
|
||||||
# Set "X-Plex-Token" to the auth token, if no token is specified or it is invalid, the list will return public downloads by default
|
# Set "X-Plex-Token" to the auth token, if no token is specified or it is invalid, the list will return public downloads by default
|
||||||
DOWNLOAD=$(wget --header "X-Plex-Token:"${TOKEN}"" --load-cookies /tmp/kaka --save-cookies /tmp/kaka --keep-session-cookies "${URL_DOWNLOAD}" -O - 2>/dev/null | grep -ioe '"label"[^}]*' | grep -i "\"distro\":\"${DISTRO}\"" | grep -i "\"build\":\"${BUILD}\"" | grep -m1 -ioe 'https://[^\"]*' )
|
RELEASE=$(wget --header "X-Plex-Token:"${TOKEN}"" --load-cookies /tmp/kaka --save-cookies /tmp/kaka --keep-session-cookies "${URL_DOWNLOAD}" -O - 2>/dev/null | grep -ioe '"label"[^}]*' | grep -i "\"distro\":\"${DISTRO}\"" | grep -i "\"build\":\"${BUILD}\"")
|
||||||
|
DOWNLOAD=$(echo ${RELEASE} | grep -m1 -ioe 'https://[^\"]*')
|
||||||
|
CHECKSUM=$(echo ${RELEASE} | grep -ioe '\"checksum\"\:\"[^\"]*' | sed 's/\"checksum\"\:\"//')
|
||||||
echo "OK"
|
echo "OK"
|
||||||
|
|
||||||
if [ -z "${DOWNLOAD}" ]; then
|
if [ -z "${DOWNLOAD}" ]; then
|
||||||
|
@ -444,6 +448,8 @@ if [ $? -ne 0 ]; then
|
||||||
cronexit 3
|
cronexit 3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "${CHECKSUM} ${FILENAME}" >${DOWNLOADDIR}/${FILENAME}.sha
|
||||||
|
|
||||||
if [ "${PRINT_URL}" = "yes" ]; then
|
if [ "${PRINT_URL}" = "yes" ]; then
|
||||||
if [ "${QUIET}" = "yes" ]; then
|
if [ "${QUIET}" = "yes" ]; then
|
||||||
echo "${DOWNLOAD}" >&3
|
echo "${DOWNLOAD}" >&3
|
||||||
|
@ -465,32 +471,50 @@ else
|
||||||
fi
|
fi
|
||||||
INSTALLED_VERSION=$(rpm -qv plexmediaserver 2>/dev/null)
|
INSTALLED_VERSION=$(rpm -qv plexmediaserver 2>/dev/null)
|
||||||
fi
|
fi
|
||||||
if [[ $FILENAME == *$INSTALLED_VERSION* ]] && [ "${FORCE}" != "yes" ] && [ ! -z "${INSTALLED_VERSION}" ]; then
|
|
||||||
|
if [[ $FILENAME == *$INSTALLED_VERSION* ]] && [ "${FORCE}" != "yes" -a "${FORCEALL}" != "yes" ] && [ ! -z "${INSTALLED_VERSION}" ]; then
|
||||||
echo "Your OS reports the latest version of Plex ($INSTALLED_VERSION) is already installed. Use -f to force download."
|
echo "Your OS reports the latest version of Plex ($INSTALLED_VERSION) is already installed. Use -f to force download."
|
||||||
cronexit 5
|
cronexit 5
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -f "${DOWNLOADDIR}/${FILENAME}" -a "${FORCE}" != "yes" ]; then
|
if [ -f "${DOWNLOADDIR}/${FILENAME}" ]; then
|
||||||
echo "File already exists (${FILENAME}), won't download."
|
if [ "${FORCE}" != "yes" -a "${FORCEALL}" != "yes" ]; then
|
||||||
if [ "${AUTOINSTALL}" != "yes" ]; then
|
echo "File already exists (${FILENAME}), won't download."
|
||||||
cronexit 2
|
if [ "${AUTOINSTALL}" != "yes" ]; then
|
||||||
fi
|
cronexit 2
|
||||||
SKIP_DOWNLOAD="yes"
|
fi
|
||||||
|
SKIP_DOWNLOAD="yes"
|
||||||
|
elif [ "${FORCEALL}" == "yes" ]; then
|
||||||
|
echo "Note! File exists, but asked to overwrite with new copy"
|
||||||
|
else
|
||||||
|
sha1sum --status -c "${DOWNLOADDIR}/${FILENAME}.sha"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Note! File exists but fails checksum. Redownloading."
|
||||||
|
else
|
||||||
|
echo "File exists and checksum passes, won't redownload."
|
||||||
|
if [ "${AUTOINSTALL}" != "yes" ]; then
|
||||||
|
cronexit 2
|
||||||
|
fi
|
||||||
|
SKIP_DOWNLOAD="yes"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${SKIP_DOWNLOAD}" = "no" ]; then
|
if [ "${SKIP_DOWNLOAD}" = "no" ]; then
|
||||||
if [ -f "${DOWNLOADDIR}/${FILENAME}" ]; then
|
|
||||||
echo "Note! File exists, but asked to overwrite with new copy"
|
|
||||||
fi
|
|
||||||
|
|
||||||
echo -ne "Downloading release \"${FILENAME}\"..."
|
echo -ne "Downloading release \"${FILENAME}\"..."
|
||||||
ERROR=$(wget --load-cookies /tmp/kaka --save-cookies /tmp/kaka --keep-session-cookies "${DOWNLOAD}" -O "${DOWNLOADDIR}/${FILENAME}" 2>&1)
|
ERROR=$(wget --load-cookies /tmp/kaka --save-cookies /tmp/kaka --keep-session-cookies "${DOWNLOAD}" -O "${DOWNLOADDIR}/${FILENAME}" 2>&1)
|
||||||
CODE=$?
|
CODE=$?
|
||||||
if [ ${CODE} -ne 0 ]; then
|
if [ ${CODE} -ne 0 ]; then
|
||||||
echo -e "\n !! Download failed with code ${CODE}, \"${ERROR}\""
|
echo -e "\n !! Download failed with code ${CODE}, \"${ERROR}\""
|
||||||
cronexit ${CODE}
|
cronexit ${CODE}
|
||||||
fi
|
fi
|
||||||
echo "OK"
|
echo "OK"
|
||||||
|
fi
|
||||||
|
|
||||||
|
sha1sum --status -c "${DOWNLOADDIR}/${FILENAME}.sha"
|
||||||
|
if [ $? -ne 0 ]; then
|
||||||
|
echo "Downloaded file corrupt. Try again."
|
||||||
|
cronexit 4
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z "${PLEXSERVER}" -a "${AUTOINSTALL}" = "yes" ]; then
|
if [ ! -z "${PLEXSERVER}" -a "${AUTOINSTALL}" = "yes" ]; then
|
||||||
|
@ -508,6 +532,8 @@ fi
|
||||||
if [ "${AUTODELETE}" = "yes" ]; then
|
if [ "${AUTODELETE}" = "yes" ]; then
|
||||||
if [ "${AUTOINSTALL}" = "yes" ]; then
|
if [ "${AUTOINSTALL}" = "yes" ]; then
|
||||||
rm -rf "${DOWNLOADDIR}/${FILENAME}"
|
rm -rf "${DOWNLOADDIR}/${FILENAME}"
|
||||||
|
# Also delete the SHA1 file
|
||||||
|
rm -rf "${DOWNLOADDIR}/${FILENAME}.sha"
|
||||||
echo "Deleted \"${FILENAME}\""
|
echo "Deleted \"${FILENAME}\""
|
||||||
else
|
else
|
||||||
echo "Will not auto delete without [-a] auto install"
|
echo "Will not auto delete without [-a] auto install"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue