docker-plex-wireguard/root/etc/cont-init.d/30-plex-update
2016-07-02 20:15:50 +01:00

84 lines
2.7 KiB
Text
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/with-contenv bash
# opt out for autoupdates
[ "$ADVANCED_DISABLEUPDATES" ] && exit 0
# set header for no preferences/token message
[[ -e /tmp/no-token.nfo ]] && rm /tmp/no-token.nfo
NOTOKEN_SET='/tmp/no-token.nfo'
cat > "${NOTOKEN_SET}" <<-EOFTOKEN
#####################################################
# Login via webui and restart, because there was no #
EOFTOKEN
# 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
less /tmp/no-token.nfo
exit 0
fi
# attempt to read plex token
PLEX_TOKEN=$( sed -n 's/.*PlexOnlineToken="//p' \
"/config/Library/Application Support/Plex Media Server/Preferences.xml" \
| sed "s/\".*//")
# if plex token isn't found, exit out
if [ -z "$PLEX_TOKEN" ]; then
cat >> "${NOTOKEN_SET}" <<-EOFTOKEN
# plex token in the preferences file in config #
#####################################################
EOFTOKEN
less /tmp/no-token.nfo
exit 0
fi
# determine installed version of plex
INSTALLED=$(dpkg-query -W -f='${Version}' plexmediaserver)
# start update routine
[ "$PLEXPASS" ] && echo "PLEXPASS is deprecated, please use VERSION"
if [[ -z $VERSION && "$PLEXPASS" == "1" || $VERSION = "plexpass" ]]; then echo "VERSION=plexpass is depricated please use version latest"; fi
if [[ "$VERSION" = latest || "$VERSION" = plexpass ]]; then
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 )
echo "Target version: $VERSION set by: latest\plexpass"
elif [[ "$VERSION" = public ]]; then
VERSION=$(curl -s "https://plex.tv/downloads/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
echo "Target version: Version not set, Defaulting to supplied version"
else
echo "Target version: $VERSION set by: manually"
fi
last=130
if [[ "$VERSION" == "" ]]; then
echo "ERROR: No version found, running installed version $INSTALLED"
elif [[ "$VERSION" != "$INSTALLED" ]]; then
echo "Upgrading from version: $INSTALLED to version: $VERSION"
while [[ $last -ne "0" ]]; do
rm -f /tmp/plexmediaserver_*.deb
wget -P /tmp "https://downloads.plex.tv/plex-media-server/$VERSION/plexmediaserver_${VERSION}_amd64.deb"
last=$?
done
apt-get remove --purge -y plexmediaserver
dpkg -i /tmp/plexmediaserver_"${VERSION}"_amd64.deb
else
echo "No need to update!"
fi
cp -v /defaults/plexmediaserver /etc/default/plexmediaserver