|
| 1 | +#!/usr/bin/with-contenv bash |
| 2 | + |
| 3 | +# copy config on first run, regardless of update status |
| 4 | +[[ ! -e /etc/default/plexmediaserver ]] && \ |
| 5 | + cp /defaults/plexmediaserver /etc/default/plexmediaserver |
| 6 | + |
| 7 | +# test if plex is installed and try re-pulling latest if not |
| 8 | +if dpkg -s plexmediaserver > /dev/null 2>&1 ; then |
| 9 | +: |
| 10 | +else echo "for some reason plex doesn't appear to be installed, pulling a new copy and exiting out of update script" |
| 11 | +curl -o /tmp/plexmediaserver.deb -L \ |
| 12 | + "${PLEX_INSTALL}" && \ |
| 13 | +dpkg -i --force-confold /tmp/plexmediaserver.deb |
| 14 | +rm -f /tmp/plexmediaserver.deb |
| 15 | +exit 0 |
| 16 | +fi |
| 17 | + |
| 18 | +# set no update message |
| 19 | +[[ -e /tmp/no-version.nfo ]] && \ |
| 20 | + rm /tmp/no-version.nfo |
| 21 | +NOVERSION_SET='/tmp/no-version.nfo' |
| 22 | +cat > "${NOVERSION_SET}" <<-EOFVERSION |
| 23 | +####################################################### |
| 24 | +# Update routine will not run because you havent set # |
| 25 | +# the VERSION variable or you opted out of updates. # |
| 26 | +# For more information checkout :- # |
| 27 | +# https://github.com/linuxserver/docker-plex # |
| 28 | +####################################################### |
| 29 | +EOFVERSION |
| 30 | + |
| 31 | +# set update failed message |
| 32 | +[[ -e /tmp/update_fail.nfo ]] && \ |
| 33 | + rm /tmp/update_fail.nfo |
| 34 | +UPGRADE_FAIL='/tmp/update_fail.nfo' |
| 35 | +cat > "${UPGRADE_FAIL}" <<-EOFFAIL |
| 36 | +######################################################## |
| 37 | +# Upgrade attempt failed, this could be because either # |
| 38 | +# plex update site is down, local network issues, or # |
| 39 | +# you were trying to get a version that simply doesn't # |
| 40 | +# exist, check over the VERSION variable thoroughly & # |
| 41 | +# correct it or try again later. # |
| 42 | +######################################################## |
| 43 | +EOFFAIL |
| 44 | + |
| 45 | +# test for no version set or opt out for autoupdates |
| 46 | +if [[ -z "$VERSION" ]] || [[ "$VERSION" == "0" ]] || [[ ! -z "$ADVANCED_DISABLEUPDATES" ]]; then |
| 47 | +printf "\n\n\n%s\n\n\n" "$(</tmp/no-version.nfo)" |
| 48 | +exit 0 |
| 49 | +fi |
| 50 | + |
| 51 | +# set header for no preferences/token message |
| 52 | +[[ -e /tmp/no-token.nfo ]] && \ |
| 53 | + rm /tmp/no-token.nfo |
| 54 | +NOTOKEN_SET='/tmp/no-token.nfo' |
| 55 | +cat > "${NOTOKEN_SET}" <<-EOFTOKEN |
| 56 | +##################################################### |
| 57 | +# Login via the webui at http://<ip>:32400/web # |
| 58 | +# and restart the docker, because there was no # |
| 59 | +EOFTOKEN |
| 60 | + |
| 61 | +# if preferences files doesn't exist, exit out |
| 62 | +if [ ! -e "/config/Library/Application Support/Plex Media Server/Preferences.xml" ]; then |
| 63 | +cat >> "${NOTOKEN_SET}" <<-EOFTOKEN |
| 64 | +# preference file found, possibly first startup. # |
| 65 | +##################################################### |
| 66 | +EOFTOKEN |
| 67 | +printf "\n\n\n%s\n\n\n" "$(</tmp/no-token.nfo)" |
| 68 | +exit 0 |
| 69 | +fi |
| 70 | + |
| 71 | +# attempt to read plex token |
| 72 | +PLEX_TOKEN=$( sed -n 's/.*PlexOnlineToken="//p' \ |
| 73 | + "/config/Library/Application Support/Plex Media Server/Preferences.xml" \ |
| 74 | + | sed "s/\".*//") |
| 75 | + |
| 76 | +# if plex token isn't found, exit out |
| 77 | +if [ -z "$PLEX_TOKEN" ]; then |
| 78 | +cat >> "${NOTOKEN_SET}" <<-EOFTOKEN |
| 79 | +# plex token found in the preference file # |
| 80 | +##################################################### |
| 81 | +EOFTOKEN |
| 82 | +printf "\n\n\n%s\n\n\n" "$(</tmp/no-token.nfo)" |
| 83 | +exit 0 |
| 84 | +fi |
| 85 | + |
| 86 | +# determine installed version of plex |
| 87 | +INSTALLED_VERSION=$(dpkg-query -W -f='${Version}' plexmediaserver) |
| 88 | + |
| 89 | +# start update routine |
| 90 | +if [[ "$VERSION" = latest ]] || [[ "$VERSION" = plexpass ]] || [[ "$PLEXPASS" == "1" ]]; then |
| 91 | +REMOTE_VERSION=$(curl -s "${PLEX_INSTALL}&X-Plex-Token=$PLEX_TOKEN"| cut -d "/" -f 5 ) |
| 92 | +elif [[ "$VERSION" = public ]]; then |
| 93 | +PLEX_TOKEN="" |
| 94 | +REMOTE_VERSION=$(curl -s "${PLEX_INSTALL}&X-Plex-Token=$PLEX_TOKEN"| cut -d "/" -f 5 ) |
| 95 | +else |
| 96 | +REMOTE_VERSION="${VERSION}" |
| 97 | +fi |
| 98 | + |
| 99 | +if [[ "$REMOTE_VERSION" == "$INSTALLED_VERSION" ]]; then |
| 100 | +echo "No update required" |
| 101 | +exit 0 |
| 102 | +fi |
| 103 | + |
| 104 | +echo "Atempting to upgrade to: $REMOTE_VERSION" |
| 105 | +rm -f /tmp/plexmediaserver_*.deb |
| 106 | +wget -nv -P /tmp \ |
| 107 | +"${PLEX_DOWNLOAD}/$REMOTE_VERSION/plexmediaserver_${REMOTE_VERSION}_amd64.deb" |
| 108 | +last=$? |
| 109 | + |
| 110 | +# test if deb file size is ok, or if download failed |
| 111 | +if [[ "$last" -gt "0" ]] || [[ $(stat -c %s /tmp/plexmediaserver_"${REMOTE_VERSION}"_amd64.deb) -lt 10000 ]]; then |
| 112 | +printf "\n\n\n%s\n\n\n" "$(</tmp/update_fail.nfo)" |
| 113 | +exit 0 |
| 114 | +# if ok, try to install it. |
| 115 | +else |
| 116 | +dpkg -i --force-confold /tmp/plexmediaserver_"${REMOTE_VERSION}"_amd64.deb |
| 117 | +rm -f /tmp/plexmediaserver_*.deb |
| 118 | +fi |
| 119 | + |
| 120 | +# recopy config file |
| 121 | +cp /defaults/plexmediaserver /etc/default/plexmediaserver |
0 commit comments