Fix various shellcheck concerns

Signed-off-by: Eric Nemchik <eric@nemchik.com>
This commit is contained in:
Eric Nemchik 2024-01-08 21:17:32 -06:00
parent 4b79b7759e
commit 56562f4956
No known key found for this signature in database
5 changed files with 83 additions and 68 deletions

View file

@ -1,7 +1,8 @@
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
# If docker manages versioning exit
if [ "${VERSION}" ] && [ "${VERSION}" == 'docker' ]; then
if [[ -n "${VERSION}" ]] && [[ "${VERSION}" == "docker" ]]; then
echo "Docker is used for versioning skip update check"
exit 0
fi
@ -12,19 +13,20 @@ if (dpkg --get-selections plexmediaserver | grep -wq "install"); then
else
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" && \
"${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
fi
# set no update message
[[ -e /tmp/no-version.nfo ]] && \
if [[ -e /tmp/no-version.nfo ]]; then
rm /tmp/no-version.nfo
fi
NOVERSION_SET='/tmp/no-version.nfo'
cat > "${NOVERSION_SET}" <<-EOFVERSION
cat >"${NOVERSION_SET}" <<-EOFVERSION
#######################################################
# Update routine will not run because you havent set #
# Update routine will not run because you haven't set #
# the VERSION variable or you opted out of updates. #
# For more information checkout :- #
# https://github.com/linuxserver/docker-plex #
@ -32,10 +34,11 @@ cat > "${NOVERSION_SET}" <<-EOFVERSION
EOFVERSION
# set update failed message
[[ -e /tmp/update_fail.nfo ]] && \
if [[ -e /tmp/update_fail.nfo ]]; then
rm /tmp/update_fail.nfo
fi
UPGRADE_FAIL='/tmp/update_fail.nfo'
cat > "${UPGRADE_FAIL}" <<-EOFFAIL
cat >"${UPGRADE_FAIL}" <<-EOFFAIL
########################################################
# Upgrade attempt failed, this could be because either #
# plex update site is down, local network issues, or #
@ -45,25 +48,27 @@ cat > "${UPGRADE_FAIL}" <<-EOFFAIL
########################################################
EOFFAIL
# test for no version set or opt out for autoupdates
if [[ -z "$VERSION" ]] || [[ "$VERSION" == "0" ]] || [[ -n "$ADVANCED_DISABLEUPDATES" ]]; then
# test for no version set or opt out for auto updates
if [[ -z "${VERSION}" ]] || [[ "${VERSION}" == "0" ]] || [[ -n "${ADVANCED_DISABLEUPDATES}" ]]; then
printf '\n\n\n%s\n\n\n' "$(</tmp/no-version.nfo)"
exit 0
fi
# set header for no preferences/token message
[[ -e /tmp/no-token.nfo ]] && \
if [[ -e /tmp/no-token.nfo ]]; then
rm /tmp/no-token.nfo
fi
NOTOKEN_SET='/tmp/no-token.nfo'
cat > "${NOTOKEN_SET}" <<-EOFTOKEN
cat >"${NOTOKEN_SET}" <<-EOFTOKEN
#####################################################
# Login via the webui at http://<ip>:32400/web #
# and restart the container, 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
PLEX_MEDIA_SERVER_PREFERENCES="${PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR}/Plex Media Server/Preferences.xml"
if [[ ! -e "${PLEX_MEDIA_SERVER_PREFERENCES}" ]]; then
cat >>"${NOTOKEN_SET}" <<-EOFTOKEN
# preference file found, possibly first startup. #
#####################################################
EOFTOKEN
@ -72,13 +77,13 @@ EOFTOKEN
fi
# attempt to read plex token
PLEX_TOKEN=$( sed -n 's/.*PlexOnlineToken="//p' \
"/config/Library/Application Support/Plex Media Server/Preferences.xml" \
| sed "s/\".*//")
PLEX_TOKEN=$(sed -n 's/.*PlexOnlineToken="//p' \
"${PLEX_MEDIA_SERVER_PREFERENCES}" |
sed "s/\".*//")
# if plex token isn't found, exit out
if [ -z "$PLEX_TOKEN" ]; then
cat >> "${NOTOKEN_SET}" <<-EOFTOKEN
if [[ -z "${PLEX_TOKEN}" ]]; then
cat >>"${NOTOKEN_SET}" <<-EOFTOKEN
# plex token found in the preference file #
#####################################################
EOFTOKEN
@ -90,22 +95,22 @@ fi
INSTALLED_VERSION=$(dpkg-query -W -f='${Version}' plexmediaserver)
# start update routine
if [[ "${VERSION,,}" = latest ]] || [[ "${VERSION,,}" = plexpass ]] || [[ "$PLEXPASS" == "1" ]]; then
if [[ "${PLEX_ARCH}" = amd64 ]]; then
if [[ "${VERSION,,}" == "latest" ]] || [[ "${VERSION,,}" == "plexpass" ]] || [[ "${PLEXPASS}" == "1" ]]; then
if [[ "${PLEX_ARCH}" == "amd64" ]]; then
PLEX_URL_ARCH="x86_64"
elif [[ "${PLEX_ARCH}" = armhf ]]; then
elif [[ "${PLEX_ARCH}" == "armhf" ]]; then
PLEX_URL_ARCH="armv7hf_neon"
elif [[ "${PLEX_ARCH}" = arm64 ]]; then
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 )
elif [[ "${VERSION,,}" = public ]]; then
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)
elif [[ "${VERSION,,}" == "public" ]]; then
REMOTE_VERSION=$(curl -s 'https://plex.tv/api/downloads/5.json' | jq -r '.computer.Linux.version')
else
REMOTE_VERSION="${VERSION}"
fi
if [[ "$REMOTE_VERSION" == "$INSTALLED_VERSION" ]]; then
if [[ "${REMOTE_VERSION}" == "${INSTALLED_VERSION}" ]]; then
echo "No update required"
exit 0
fi
@ -115,18 +120,18 @@ if [[ -z "${REMOTE_VERSION}" ]]; then
exit 0
fi
echo "Atempting to upgrade to: $REMOTE_VERSION"
echo "Attempting to upgrade to: ${REMOTE_VERSION}"
rm -f /tmp/plexmediaserver_*.deb
wget -nv -P /tmp \
"${PLEX_DOWNLOAD}/${REMOTE_VERSION}/debian/plexmediaserver_${REMOTE_VERSION}_${PLEX_ARCH}.deb"
last=$?
# test if deb file size is ok, or if download failed
if [[ "$last" -gt "0" ]] || [[ $(stat -c %s /tmp/plexmediaserver_"${REMOTE_VERSION}"_${PLEX_ARCH}.deb) -lt 10000 ]]; then
if [[ "${last}" -gt "0" ]] || [[ $(stat -c %s "/tmp/plexmediaserver_${REMOTE_VERSION}_${PLEX_ARCH}.deb") -lt 10000 ]]; then
printf '\n\n\n%s\n\n\n' "$(</tmp/update_fail.nfo)"
exit 0
# if ok, try to install it.
else
dpkg -i --force-confold /tmp/plexmediaserver_"${REMOTE_VERSION}"_${PLEX_ARCH}.deb
dpkg -i --force-confold "/tmp/plexmediaserver_${REMOTE_VERSION}_${PLEX_ARCH}.deb"
rm -f /tmp/plexmediaserver_*.deb
fi