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

102 lines
3.2 KiB
Text
Raw Normal View History

2016-06-30 22:59:35 +01:00
#!/usr/bin/with-contenv bash
# set no update message
#######################################################
# Update routine will not run, this is either because #
# you havent set the VERSION variable or have set #
# $ADVANCED_DISABLEUPDATES, for more information, see #
# <link not placed yet> #
#######################################################
# test for no version set or opt out for autoupdates
[[ "$ADVANCED_DISABLEUPDATES" ]] || && \
2016-08-22 12:44:21 +01:00
exit 0
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. #
#####################################################
2016-07-02 20:15:50 +01:00
EOFTOKEN
2016-08-22 09:39:27 +01:00
echo "$(cat /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 12:44:21 +01:00
echo "$(cat /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
2016-08-22 12:44:21 +01:00
[ "$PLEXPASS" ] && \
echo "PLEXPASS is deprecated, please use VERSION"
2016-07-02 20:15:50 +01:00
if [[ -z $VERSION && "$PLEXPASS" == "1" || $VERSION = "plexpass" ]]; then echo "VERSION=plexpass is depricated please use version latest"; fi
2016-04-07 08:40:31 +02:00
if [[ "$VERSION" = latest || "$VERSION" = plexpass ]]; then
VERSION=$(curl -s "${PLEX_URL}/latest/1?channel=8&build=linux-ubuntu-x86_64&distro=ubuntu&X-Plex-Token=$PLEX_TOKEN"| cut -d "/" -f 5 )
echo "Target version: $VERSION set by: latest\plexpass"
elif [[ "$VERSION" = public ]]; then
VERSION=$(curl -s "${PLEX_URL}/latest/1?channel=8&build=linux-ubuntu-x86_64&distro=ubuntu&X-Plex-Token="| cut -d "/" -f 5 )
echo "Target version: $VERSION set by: public"
elif [[ -z "$VERSION" ]]; then
2016-04-07 08:51:22 +02:00
echo "Target version: Version not set, Defaulting to supplied version"
2015-08-28 12:36:53 +02:00
else
echo "Target version: $VERSION set by: manually"
2015-05-10 10:50:00 +02:00
fi
2015-08-28 12:36:53 +02:00
last=130
if [[ "$VERSION" == "" ]]; then
2016-08-22 12:44:21 +01:00
echo "VERSION variable not set, current installed version $INSTALLED"
elif [[ "$VERSION" != "$INSTALLED" ]]; then
2016-08-22 12:44:21 +01:00
echo "Upgrading from version: $INSTALLED to version: $VERSION"
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=$?
2015-08-28 12:46:13 +02:00
done
2016-08-22 12:44:21 +01:00
[[ ! -e /tmp/plexmediaserver_"${VERSION}"_amd64.deb ]] && \
exit 0
apt-get remove --purge -y \
plexmediaserver
dpkg -i /tmp/plexmediaserver_"${VERSION}"_amd64.deb
2015-08-28 12:46:13 +02:00
else
2015-09-24 09:25:27 +02:00
echo "No need to update!"
2015-08-28 12:46:13 +02:00
fi
2016-07-02 20:15:50 +01:00
cp -v /defaults/plexmediaserver /etc/default/plexmediaserver
2016-06-30 22:59:35 +01:00