@MPH_91 Try this script and let me know if it works for you:
#!/bin/bash
# restrict script execution to root
if [[ ${EUID} -ne 0 ]]; then
echo "Must be run as root. Exiting script..."
exit 1
fi
# configurable download path
TMP_DL_PATH='/tmp'
#######################################
# Reports action status and removes
# downloaded installer file.
# Globals:
# TMP_DL_PATH
# Arguments:
# Exit status, an integer
# Action, a string
# Outputs:
# Writes action and status to stdout
#######################################
check_status() {
if [[ $1 -ne 0 ]]; then
echo "$2 failed. Exiting script..."
rm -f "${TMP_DL_PATH}"/"${pms_pkg}" 2>/dev/null
exit 1
else
echo "$2 succeeded."
fi
}
# get pms path, token, and package info
pms_path=$(find / -path '*/Plex Media Server/Preferences.xml' -print -quit 2>/dev/null)
pms_token=$(sed -n 's/.*PlexOnlineToken="\([^"]*\).*/\1/p' "${pms_path}")
pms_info=$(curl -s "https://plex.tv/api/downloads/5.json?channel=plexpass&X-Plex-Token=${pms_token}")
# check if pms_token is defined
if [[ -z "${pms_token}" ]]; then
echo "Unable to locate PMS Token. Exiting script..."
exit 1
fi
# get current, new, and greater versions
cur_version=$(synopkg version "Plex Media Server")
new_version=$(jq -r '.nas.Synology.version' <<< "${pms_info}")
gtr_version=$(echo -e "${cur_version}\n${new_version}" | sort -V | tail -1)
# compare package versions
if [[ "${gtr_version}" == "${cur_version}" ]]; then
echo "Plex Media Server is up-to-date."
else
# notify new version available
echo "Plex Media Server version ${new_version} is available..."
synonotify PKGHasUpgrade '{"[%HOSTNAME%]": $(hostname), "[%OSNAME%]": "Synology", "[%PKG_HAS_UPDATE%]": "Plex", "[%COMPANY_NAME%]": "Synology"}'
# get model and cpu architecture info
model=$(cat /proc/sys/kernel/syno_hw_version)
cpu=$(uname -m)
# check if cpu architecture is armv7
if [[ "${cpu}" == "armv7"* ]]; then
# filter rules based on model definitions outlined here:
# curl -s 'https://plex.tv/api/downloads/5.json?channel=plexpass' | jq '.nas.Synology.releases[] | select(.label | contains("ARMv7"))'
if [[ ${model//[^0-9]/} =~ 1[34]$ && \
"${model}" != "DS414j"* ]] || \
[[ "${model}" =~ ^(DS115j|RS815|DS216se) ]] ; then
arch="armv7hf"
elif [[ ${model//[^0-9]/} =~ 1[5-8]$ ]]; then
arch="armv7hf_neon"
fi
# otherwise assign value of cpu to arch
else
arch="${cpu}"
fi
# get download url
pms_dl_url=$(jq -r '.nas.Synology.releases[] | select(.build=="linux-'"${arch}"'") | .url' <<< "${pms_info}")
pms_pkg="${pms_dl_url##*/}"
# check if pms_dl_url is defined
if [[ -z "${pms_dl_url}" ]]; then
echo "Download URL not defined because CPU type is ${arch}. Exiting script..."
exit 1
fi
# download file to TMP_DL_PATH
echo "Downloading ${pms_pkg}..."
mkdir -p "${TMP_DL_PATH}"
wget -P "${TMP_DL_PATH}" "${pms_dl_url}"
check_status $? "Download"
# install package
echo "Installing ${pms_pkg}..."
synopkg install "${TMP_DL_PATH}/${pms_pkg}"
check_status $? "Install"
# start plexmediaserver
echo "Starting Plex Media Server..."
synopkg start "Plex Media Server"
check_status $? "Startup"
# remove package
rm -f "${TMP_DL_PATH}/${pms_pkg}" 2>/dev/null
fi