From d3bf0f968d7e88f3ea7b7987f0cb88db54d8eb07 Mon Sep 17 00:00:00 2001 From: Ben Alman Date: Thu, 11 May 2023 15:08:37 -0400 Subject: [PATCH] Add in more debug info, minor tweaks --- update-plex.sh | 56 ++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 41 insertions(+), 15 deletions(-) diff --git a/update-plex.sh b/update-plex.sh index ca3271f..22d9a7a 100755 --- a/update-plex.sh +++ b/update-plex.sh @@ -1,11 +1,14 @@ #!/usr/bin/env bash +script_args=("$@") +script_version='(in-development)' # auto-generated during release + function help() { cat <&2; } function fail() { fail_reason="$@"; echo "FAIL: $@"; exit 1; } @@ -33,7 +34,7 @@ function process_args() { exit ;; -v|--version) - version + echo "$script_version" exit ;; --plex-pass) @@ -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 } @@ -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() { @@ -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)" @@ -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" } @@ -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 } @@ -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...'