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

95 lines
2.9 KiB
Text
Raw Normal View History

2016-06-30 22:59:35 +01:00
#!/usr/bin/with-contenv bash
# copy config on first run, regardless of update status
[[ ! -e /etc/default/plexmediaserver ]] && \
cp /defaults/plexmediaserver /etc/default/plexmediaserver
# set no update message
[[ -e /tmp/no-version.nfo ]] && \
rm /tmp/no-version.nfo
NOVERSION_SET='/tmp/no-version.nfo'
cat > "${NOVERSION_SET}" <<-EOFVERSION
#######################################################
# Update routine will not run because you havent set #
# the VERSION variable, for more information checkout #
#  https://github.com/linuxserver/docker-plex #
#######################################################
EOFVERSION
# test for no version set or opt out for autoupdates
2016-08-22 20:41:24 +01:00
if [[ -z "$VERSION" ]] || [[ "$VERSION" == "0" ]] || [[ ! -z "$ADVANCED_DISABLEUPDATES" ]]; then
printf "%s\n\n\n" "$(</tmp/no-version.nfo)"
exit 0
fi
2016-07-02 20:15:50 +01:00
# set header for no preferences/token message
2016-08-22 12:44:21 +01:00
[[ -e /tmp/no-token.nfo ]] && \
rm /tmp/no-token.nfo
2016-07-02 20:15:50 +01:00
NOTOKEN_SET='/tmp/no-token.nfo'
cat > "${NOTOKEN_SET}" <<-EOFTOKEN
2015-08-28 12:36:53 +02:00
2016-07-02 20:15:50 +01:00
#####################################################
2016-07-02 20:28:43 +01:00
# Login via the webui at http://<ip>:32400/web #
# and restart the docker, because there was no #
2016-07-02 20:15:50 +01:00
EOFTOKEN
2016-07-02 20:15:50 +01:00
# if preferences files doesn't exist, exit out
if [ ! -e "/config/Library/Application Support/Plex Media Server/Preferences.xml" ]; then
cat >> "${NOTOKEN_SET}" <<-EOFTOKEN
# preference file found, possibly first startup. #
#####################################################
EOFTOKEN
2016-08-22 20:41:24 +01:00
printf "%s\n\n\n" "$(</tmp/no-token.nfo)"
2016-07-02 20:15:50 +01:00
exit 0
fi
# attempt to read plex token
PLEX_TOKEN=$( sed -n 's/.*PlexOnlineToken="//p' \
2016-08-22 12:44:21 +01:00
"/config/Library/Application Support/Plex Media Server/Preferences.xml" \
| sed "s/\".*//")
2016-07-02 20:15:50 +01:00
# if plex token isn't found, exit out
if [ -z "$PLEX_TOKEN" ]; then
cat >> "${NOTOKEN_SET}" <<-EOFTOKEN
2016-07-02 20:28:43 +01:00
# plex token found in the preference file #
2016-07-02 20:15:50 +01:00
#####################################################
EOFTOKEN
2016-08-22 20:41:24 +01:00
printf "%s\n\n\n" "$(</tmp/no-token.nfo)"
2016-07-02 20:15:50 +01:00
exit 0
fi
# determine installed version of plex
INSTALLED=$(dpkg-query -W -f='${Version}' plexmediaserver)
2015-08-28 12:36:53 +02:00
2016-07-02 20:15:50 +01:00
# start update routine
if [[ "$VERSION" = latest ]] || [[ "$VERSION" = plexpass ]] || [[ "$PLEXPASS" == "1" ]]; then
PLEX_TOKEN="${PLEX_TOKEN}"
2015-08-28 12:36:53 +02:00
else
PLEX_TOKEN=""
2015-05-10 10:50:00 +02:00
fi
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 )
2015-08-28 12:36:53 +02:00
if [[ "$VERSION" == "$INSTALLED" ]]; then
echo "No update required"
exit 0
fi
echo "Atempting to upgrade to: $VERSION"
2015-08-28 12:36:53 +02:00
last=130
while [[ $last -ne "0" ]]; do
rm -f /tmp/plexmediaserver_*.deb
curl -o /tmp/plexmediaserver_"${VERSION}"_amd64.deb -L \
2016-08-22 12:44:21 +01:00
"${PLEX_URL}/plex-media-server/$VERSION/plexmediaserver_${VERSION}_amd64.deb"
last=$?
done
2016-08-22 12:44:21 +01:00
apt-get remove --purge -y \
plexmediaserver
dpkg -i /tmp/plexmediaserver_"${VERSION}"_amd64.deb
rm -f /tmp/plexmediaserver_*.deb
2016-07-02 20:15:50 +01:00
# recopy config file in case update overwrites our copy
cp -v /defaults/plexmediaserver /etc/default/plexmediaserver