@@ -17,6 +17,20 @@ cat > "${NOVERSION_SET}" <<-EOFVERSION
1717#######################################################
1818EOFVERSION
1919
20+ # set update failed message
21+ [[ -e /tmp/update_fail.nfo ]] && \
22+ rm /tmp/update_fail.nfo
23+ UPGRADE_FAIL='/tmp/update_fail.nfo'
24+ cat > "${UPGRADE_FAIL}" <<-EOFFAIL
25+ ########################################################
26+ # Upgrade attempt failed, this could be because either #
27+ # plex update site is down, local network issues, or #
28+ # you were trying to get a version that simply doesn't #
29+ # exist, check over the VERSION variable thoroughly & #
30+ # correct it or try again later. #
31+ ########################################################
32+ EOFFAIL
33+
2034# test for no version set or opt out for autoupdates
2135if [[ -z "$VERSION" ]] || [[ "$VERSION" == "0" ]] || [[ ! -z "$ADVANCED_DISABLEUPDATES" ]]; then
2236printf "\n\n\n%s\n\n\n" "$(</tmp/no-version.nfo)"
@@ -59,33 +73,42 @@ exit 0
5973fi
6074
6175# determine installed version of plex
62- INSTALLED =$(dpkg-query -W -f='${Version}' plexmediaserver)
76+ INSTALLED_VERSION =$(dpkg-query -W -f='${Version}' plexmediaserver)
6377
6478# start update routine
6579if [[ "$VERSION" = latest ]] || [[ "$VERSION" = plexpass ]] || [[ "$PLEXPASS" == "1" ]]; then
66- PLEX_TOKEN= "${PLEX_TOKEN}"
67- else
80+ REMOTE_VERSION=$(curl -s "${PLEX_WWW}"| cut -d "/" -f 5 )
81+ elif [[ "$VERSION" = public ]]; then
6882PLEX_TOKEN=""
83+ REMOTE_VERSION=$(curl -s "${PLEX_WWW}"| cut -d "/" -f 5 )
84+ else
85+ REMOTE_VERSION="${VERSION}"
6986fi
70- VERSION=$(curl -s "https://plex.tv/downloads/latest/1?channel=8&build=linux-ubuntu-x86_64&distro=ubuntu&X-Plex-Token=$PLEX_TOKEN"| cut -d "/" -f 5 )
7187
72- if [[ "$VERSION " == "$INSTALLED " ]]; then
88+ if [[ "$REMOTE_VERSION " == "$INSTALLED_VERSION " ]]; then
7389echo "No update required"
7490exit 0
7591fi
7692
77- echo "Atempting to upgrade to: $VERSION "
93+ echo "Atempting to upgrade to: $REMOTE_VERSION "
7894last=130
79- while [[ $last -ne "0" ]]; do
95+ down_tries=3
96+ if curl --output /dev/null --silent --head --fail "${PLEX_URL}/plex-media-server/$REMOTE_VERSION/plexmediaserver_${REMOTE_VERSION}_amd64.deb"; then
97+ while [[ $last -ne "0" ]] || [[ down_tries -gt 0 ]]; do
8098 rm -f /tmp/plexmediaserver_*.deb
81- curl -o /tmp/plexmediaserver_"${VERSION}"_amd64.deb -L \
82- "${PLEX_URL}/plex-media-server/$VERSION/plexmediaserver_${VERSION}_amd64.deb"
83- last=$?
99+ curl -o /tmp/plexmediaserver_"${REMOTE_VERSION}"_amd64.deb -L \
100+ "${PLEX_URL}/plex-media-server/$REMOTE_VERSION/plexmediaserver_${REMOTE_VERSION}_amd64.deb"
101+ down_tries=$((down_tries-1))
102+ last=$?
84103done
85104 apt-get remove --purge -y \
86105 plexmediaserver
87- dpkg -i /tmp/plexmediaserver_"${VERSION }"_amd64.deb
106+ dpkg -i /tmp/plexmediaserver_"${REMOTE_VERSION }"_amd64.deb
88107rm -f /tmp/plexmediaserver_*.deb
108+ else
109+ printf "\n\n\n%s\n\n\n" "$(</tmp/update_fail.nfo)"
110+ exit 0
111+ fi
89112
90113# recopy config file in case update overwrites our copy
91114cp -v /defaults/plexmediaserver /etc/default/plexmediaserver
0 commit comments