Skip to content

Commit b34d77d

Browse files
committed
refine update script, attempt at better error control
1 parent 3233217 commit b34d77d

2 files changed

Lines changed: 37 additions & 13 deletions

File tree

Dockerfile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ MAINTAINER Stian Larsen, sparklyballs
33

44
# package version
55
ENV PLEX_URL="https://plex.tv/downloads"
6-
ARG PLEX_WWW="${PLEX_URL}/latest/1?channel=8&build=linux-ubuntu-x86_64&distro=ubuntu"
6+
ENV PLEX_INSTALL="${PLEX_URL}/latest/1?channel=8&build=linux-ubuntu-x86_64&distro=ubuntu"
77

88
# global environment settings
99
ENV DEBIAN_FRONTEND="noninteractive"
1010
ENV HOME="/config"
11+
ENV PLEX_WWW="${PLEX_INSTALL}&X-Plex-Token=$PLEX_TOKEN"
1112

1213
# install packages
1314
RUN \
@@ -20,7 +21,7 @@ RUN \
2021
# install plex
2122
curl -o \
2223
/tmp/plexmediaserver.deb -L \
23-
"${PLEX_WWW}" && \
24+
"${PLEX_INSTALL}" && \
2425
dpkg -i /tmp/plexmediaserver.deb && \
2526

2627
# cleanup

root/etc/cont-init.d/50-plex-update

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@ cat > "${NOVERSION_SET}" <<-EOFVERSION
1717
#######################################################
1818
EOFVERSION
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
2135
if [[ -z "$VERSION" ]] || [[ "$VERSION" == "0" ]] || [[ ! -z "$ADVANCED_DISABLEUPDATES" ]]; then
2236
printf "\n\n\n%s\n\n\n" "$(</tmp/no-version.nfo)"
@@ -59,33 +73,42 @@ exit 0
5973
fi
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
6579
if [[ "$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
6882
PLEX_TOKEN=""
83+
REMOTE_VERSION=$(curl -s "${PLEX_WWW}"| cut -d "/" -f 5 )
84+
else
85+
REMOTE_VERSION="${VERSION}"
6986
fi
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
7389
echo "No update required"
7490
exit 0
7591
fi
7692

77-
echo "Atempting to upgrade to: $VERSION"
93+
echo "Atempting to upgrade to: $REMOTE_VERSION"
7894
last=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=$?
84103
done
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
88107
rm -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
91114
cp -v /defaults/plexmediaserver /etc/default/plexmediaserver

0 commit comments

Comments
 (0)