You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
4.6 KiB
128 lines
4.6 KiB
9 years ago
|
#!/usr/bin/with-contenv bash
|
||
9 years ago
|
|
||
6 years ago
|
# If docker manages versioning exit
|
||
|
if [ "${VERSION}" ] && [ "${VERSION}" == 'docker' ]; then
|
||
2 years ago
|
echo "Docker is used for versioning skip update check"
|
||
|
exit 0
|
||
6 years ago
|
fi
|
||
|
|
||
6 years ago
|
# test if plex is installed and try re-pulling latest if not
|
||
8 years ago
|
if (dpkg --get-selections plexmediaserver | grep -wq "install"); then
|
||
2 years ago
|
:
|
||
8 years ago
|
else
|
||
2 years ago
|
echo "for some reason plex doesn't appear to be installed, pulling a new copy and exiting out of update script"
|
||
|
curl -o /tmp/plexmediaserver.deb -L \
|
||
|
"${PLEX_DOWNLOAD}/${REMOTE_VERSION}/debian/plexmediaserver_${REMOTE_VERSION}_${PLEX_ARCH}.deb" && \
|
||
|
dpkg -i --force-confold /tmp/plexmediaserver.deb
|
||
|
rm -f /tmp/plexmediaserver.deb
|
||
|
exit 0
|
||
8 years ago
|
fi
|
||
|
|
||
6 years ago
|
# set no update message
|
||
8 years ago
|
[[ -e /tmp/no-version.nfo ]] && \
|
||
2 years ago
|
rm /tmp/no-version.nfo
|
||
8 years ago
|
NOVERSION_SET='/tmp/no-version.nfo'
|
||
|
cat > "${NOVERSION_SET}" <<-EOFVERSION
|
||
8 years ago
|
#######################################################
|
||
6 years ago
|
# Update routine will not run because you havent set #
|
||
8 years ago
|
# the VERSION variable or you opted out of updates. #
|
||
|
# For more information checkout :- #
|
||
6 years ago
|
# https://github.com/linuxserver/docker-plex #
|
||
8 years ago
|
#######################################################
|
||
8 years ago
|
EOFVERSION
|
||
8 years ago
|
|
||
6 years ago
|
# set update failed message
|
||
8 years ago
|
[[ -e /tmp/update_fail.nfo ]] && \
|
||
2 years ago
|
rm /tmp/update_fail.nfo
|
||
8 years ago
|
UPGRADE_FAIL='/tmp/update_fail.nfo'
|
||
|
cat > "${UPGRADE_FAIL}" <<-EOFFAIL
|
||
|
########################################################
|
||
6 years ago
|
# Upgrade attempt failed, this could be because either #
|
||
8 years ago
|
# plex update site is down, local network issues, or #
|
||
|
# you were trying to get a version that simply doesn't #
|
||
6 years ago
|
# exist, check over the VERSION variable thoroughly & #
|
||
|
# correct it or try again later. #
|
||
8 years ago
|
########################################################
|
||
|
EOFFAIL
|
||
|
|
||
8 years ago
|
# test for no version set or opt out for autoupdates
|
||
6 years ago
|
if [[ -z "$VERSION" ]] || [[ "$VERSION" == "0" ]] || [[ -n "$ADVANCED_DISABLEUPDATES" ]]; then
|
||
2 years ago
|
printf '\n\n\n%s\n\n\n' "$(</tmp/no-version.nfo)"
|
||
|
exit 0
|
||
8 years ago
|
fi
|
||
9 years ago
|
|
||
6 years ago
|
# set header for no preferences/token message
|
||
8 years ago
|
[[ -e /tmp/no-token.nfo ]] && \
|
||
2 years ago
|
rm /tmp/no-token.nfo
|
||
9 years ago
|
NOTOKEN_SET='/tmp/no-token.nfo'
|
||
|
cat > "${NOTOKEN_SET}" <<-EOFTOKEN
|
||
|
#####################################################
|
||
9 years ago
|
# Login via the webui at http://<ip>:32400/web #
|
||
|
# and restart the docker, because there was no #
|
||
9 years ago
|
EOFTOKEN
|
||
9 years ago
|
|
||
6 years ago
|
# if preferences files doesn't exist, exit out
|
||
9 years ago
|
if [ ! -e "/config/Library/Application Support/Plex Media Server/Preferences.xml" ]; then
|
||
2 years ago
|
cat >> "${NOTOKEN_SET}" <<-EOFTOKEN
|
||
9 years ago
|
# preference file found, possibly first startup. #
|
||
|
#####################################################
|
||
|
EOFTOKEN
|
||
2 years ago
|
printf '\n\n\n%s\n\n\n' "$(</tmp/no-token.nfo)"
|
||
|
exit 0
|
||
9 years ago
|
fi
|
||
|
|
||
|
# attempt to read plex token
|
||
|
PLEX_TOKEN=$( sed -n 's/.*PlexOnlineToken="//p' \
|
||
2 years ago
|
"/config/Library/Application Support/Plex Media Server/Preferences.xml" \
|
||
|
| sed "s/\".*//")
|
||
9 years ago
|
|
||
9 years ago
|
# if plex token isn't found, exit out
|
||
|
if [ -z "$PLEX_TOKEN" ]; then
|
||
2 years ago
|
cat >> "${NOTOKEN_SET}" <<-EOFTOKEN
|
||
9 years ago
|
# plex token found in the preference file #
|
||
9 years ago
|
#####################################################
|
||
|
EOFTOKEN
|
||
2 years ago
|
printf '\n\n\n%s\n\n\n' "$(</tmp/no-token.nfo)"
|
||
|
exit 0
|
||
9 years ago
|
fi
|
||
|
|
||
|
# determine installed version of plex
|
||
8 years ago
|
INSTALLED_VERSION=$(dpkg-query -W -f='${Version}' plexmediaserver)
|
||
9 years ago
|
|
||
9 years ago
|
# start update routine
|
||
8 years ago
|
if [[ "${VERSION,,}" = latest ]] || [[ "${VERSION,,}" = plexpass ]] || [[ "$PLEXPASS" == "1" ]]; then
|
||
2 years ago
|
if [[ "${PLEX_ARCH}" = amd64 ]]; then
|
||
|
PLEX_URL_ARCH="x86_64"
|
||
|
elif [[ "${PLEX_ARCH}" = armhf ]]; then
|
||
|
PLEX_URL_ARCH="armv7hf_neon"
|
||
|
elif [[ "${PLEX_ARCH}" = arm64 ]]; then
|
||
|
PLEX_URL_ARCH="aarch64"
|
||
|
fi
|
||
|
REMOTE_VERSION=$(curl -s "https://plex.tv/downloads/details/5?distro=debian&build=linux-${PLEX_URL_ARCH}&channel=8&X-Plex-Token=$PLEX_TOKEN"| grep -oP 'version="\K[^"]+' | tail -n 1 )
|
||
8 years ago
|
elif [[ "${VERSION,,}" = public ]]; then
|
||
2 years ago
|
REMOTE_VERSION=$(curl -sX GET 'https://plex.tv/api/downloads/5.json' | jq -r '.computer.Linux.version')
|
||
8 years ago
|
else
|
||
2 years ago
|
REMOTE_VERSION="${VERSION}"
|
||
10 years ago
|
fi
|
||
9 years ago
|
|
||
8 years ago
|
if [[ "$REMOTE_VERSION" == "$INSTALLED_VERSION" ]]; then
|
||
2 years ago
|
echo "No update required"
|
||
|
exit 0
|
||
8 years ago
|
fi
|
||
|
|
||
8 years ago
|
echo "Atempting to upgrade to: $REMOTE_VERSION"
|
||
8 years ago
|
rm -f /tmp/plexmediaserver_*.deb
|
||
6 years ago
|
wget -nv -P /tmp \
|
||
2 years ago
|
"${PLEX_DOWNLOAD}/${REMOTE_VERSION}/debian/plexmediaserver_${REMOTE_VERSION}_${PLEX_ARCH}.deb"
|
||
8 years ago
|
last=$?
|
||
8 years ago
|
|
||
6 years ago
|
# test if deb file size is ok, or if download failed
|
||
6 years ago
|
if [[ "$last" -gt "0" ]] || [[ $(stat -c %s /tmp/plexmediaserver_"${REMOTE_VERSION}"_${PLEX_ARCH}.deb) -lt 10000 ]]; then
|
||
2 years ago
|
printf '\n\n\n%s\n\n\n' "$(</tmp/update_fail.nfo)"
|
||
|
exit 0
|
||
6 years ago
|
# if ok, try to install it.
|
||
8 years ago
|
else
|
||
2 years ago
|
dpkg -i --force-confold /tmp/plexmediaserver_"${REMOTE_VERSION}"_${PLEX_ARCH}.deb
|
||
|
rm -f /tmp/plexmediaserver_*.deb
|
||
8 years ago
|
fi
|