Skip to content

Commit

Permalink
Add in more debug info, minor tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
cowboy committed May 11, 2023
1 parent 5dfd3db commit d3bf0f9
Showing 1 changed file with 41 additions and 15 deletions.
56 changes: 41 additions & 15 deletions update-plex.sh
@@ -1,11 +1,14 @@
#!/usr/bin/env bash

script_args=("$@")
script_version='(in-development)' # auto-generated during release

function help() { cat <<HELP
Auto Update Plex Media Server on Synology NAS
Version $(version)
Version $script_version
Download latest release from
https://github.com/cowboy/synology-update-plex
https://github.com/cowboy/synology-update-plex/releases
Adapted from work first published at
https://forums.plex.tv/t/script-to-auto-update-plex-on-synology-nas-rev4/479748
Expand All @@ -19,8 +22,6 @@ Options:
HELP
}

function version() { echo "(in-development)"; } # value auto-generated during release

function header() { echo -e "\n[ $@ ]"; }
function warn() { echo "WARN: $@" >&2; }
function fail() { fail_reason="$@"; echo "FAIL: $@"; exit 1; }
Expand All @@ -33,7 +34,7 @@ function process_args() {
exit
;;
-v|--version)
version
echo "$script_version"
exit
;;
--plex-pass)
Expand All @@ -47,19 +48,43 @@ function process_args() {
done
}

function dump_vars() {
vars=(
script_args
script_version
plex_pass
pms_dir
dsm_major_version
available_version
installed_version
tmp_dir
package_file
debug_json
)
header 'Debugging info'
for var in "${vars[@]}"; do
(set -o posix ; set | grep ${var}= || true)
done
echo
}

function cleanup() {
code=$?
if [[ -d "$tmp_dir" ]]; then
if [[ -d "${tmp_dir-}" ]]; then
header 'Cleaning up'
echo "Removing $tmp_dir"
rm -rf $tmp_dir
fi
echo
if [[ $code == 0 ]]; then
echo
echo 'Done!'
else
notify_failure
dump_vars
echo 'Done, with errors!'
echo
echo 'If this problem persists, please file an issue here, and include the output from this script:'
echo 'https://github.com/cowboy/synology-update-plex/issues'
fi
}

Expand All @@ -79,7 +104,7 @@ function notify_success() {
}

function notify_failure() {
notify UpgradePkgFail FAILED_REASON "$fail_reason"
notify UpgradePkgFail FAILED_REASON "${fail_reason-}"
}

function retrieve_dsm_version() {
Expand All @@ -99,13 +124,13 @@ function retrieve_dsm_version() {
function build_downloads_url() {
downloads_url='https://plex.tv/api/downloads/5.json'

if [[ "$plex_pass" ]]; then
if [[ "${plex_pass-}" ]]; then
header "Enabling Plex Pass releases"

if [ "$pms_package_name" = "PlexMediaServer" ]; then
local pms_dir="$(echo "/var/packages/PlexMediaServer/home/Plex Media Server")"
pms_dir='/var/packages/PlexMediaServer/home/Plex Media Server'
else
local pms_dir="$(echo /volume*"/Plex/Library/Application Support/Plex Media Server")"
pms_dir="$(echo /volume*"/Plex/Library/Application Support/Plex Media Server")"
fi
if [[ ! -d "$pms_dir" ]]; then
pms_dir="$(find /volume* -type d -name 'Plex Media Server' -execdir test -e "{}/Preferences.xml" \; -print -quit)"
Expand Down Expand Up @@ -140,6 +165,10 @@ function retrieve_version_data() {

function set_available_version() {
available_version=$(jq -r '.nas["'"$json_dsm_pattern"'"].version' <<< "$downloads_json")
if [[ "$available_version" == null ]]; then
debug_json="$downloads_json"
fail 'Unable to retrieve version data'
fi
echo "Available version: $available_version"
}

Expand Down Expand Up @@ -204,6 +233,7 @@ function find_release() {
local arch=$(get_arch "$machine" "$hw_version")
release_json="$(jq '.nas["'"$json_dsm_pattern"'"].releases[] | select(.build == "linux-'$arch'")' <<< "$downloads_json")"
if [[ -z "$release_json" ]]; then
debug_json="$downloads_json"
fail "Unable to find release for $hw_version/$machine/$arch"
fi
}
Expand Down Expand Up @@ -248,12 +278,8 @@ function main() {

shopt -s nullglob

fail_reason=

plex_pass=
process_args "$@"

tmp_dir=
trap cleanup EXIT

echo 'Checking for a Plex Media Server update...'
Expand Down

0 comments on commit d3bf0f9

Please sign in to comment.