From 7e4d16d01819ac412690e13a6da072eb7b910ca8 Mon Sep 17 00:00:00 2001 From: causefx Date: Thu, 28 Sep 2023 11:54:53 -0700 Subject: [PATCH 1/4] Add update check and download to script --- DBRepair.sh | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/DBRepair.sh b/DBRepair.sh index eac7899..3b6affe 100755 --- a/DBRepair.sh +++ b/DBRepair.sh @@ -1435,10 +1435,45 @@ DoUpdateTimestamp() { TimeStamp="$(date "+%Y-%m-%d_%H.%M.%S")" } +# Get latest version from Github +GetLatestRelease() { + response=$(curl -s "https://api.github.com/repos/ChuckPa/PlexDBRepair/tags") + if [ $? -eq 0 ]; then + LatestVersion=$(echo "$response" | grep -oP '"name":\s*"\K[^"]*' | sed -n '1p') + else + LatestVersion=$Version + fi + +} + +# Download and update script +DownloadAndUpdate() { + url="$1" + filename="$2" + # Download the file and check if the download was successful + if curl -s "$url" --output "$filename"; then + Output "Update downloaded successfully" + + # Check if the file was written to + if [ -f "$filename" ]; then + Output "Update written successfully" + else + Output "Error: File not written" + fi + else + Output "Error: Download failed" + fi +} + ############################################################# # Main utility begins here # ############################################################# +# Set Script Path +ScriptPath="$( readlink -f "$0")" +ScriptName="$(basename "$ScriptPath")" +ScriptWorkingDirectory="$(dirname "$ScriptPath")" + # Initialize LastName LastTimestamp SetLast "" "" @@ -1569,6 +1604,7 @@ do echo " 11 - 'status' - Report status of PMS (run-state and databases)" echo " 12 - 'undo' - Undo last successful command" echo "" + echo " 00 - 'update' - Check for script update" echo " 99 - 'quit' - Quit immediately. Keep all temporary files." echo " 'exit' - Exit with cleanup options." fi @@ -1870,6 +1906,24 @@ do DoUndo ;; + 00|update) + + Output "Checking for script update" + GetLatestRelease + if [ $LatestVersion != $Version ]; then + Output "Version update available" + if ConfirmYesNo "Download and update script?"; then + DownloadAndUpdate "https://raw.githubusercontent.com/ChuckPa/PlexDBRepair/master/DBRepair.sh" "$ScriptWorkingDirectory/$ScriptName" + exit 0 + else + Output "Download aborted" + fi + + else + Output "No update available" + fi + ;; + # Quit 99|quit) From be485fac83db2586ac01c80820a3a647beb8f2e6 Mon Sep 17 00:00:00 2001 From: causefx Date: Thu, 28 Sep 2023 14:50:40 -0700 Subject: [PATCH 2/4] Update DBRepair.sh --- DBRepair.sh | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/DBRepair.sh b/DBRepair.sh index 3b6affe..abed3ee 100755 --- a/DBRepair.sh +++ b/DBRepair.sh @@ -1450,6 +1450,13 @@ GetLatestRelease() { DownloadAndUpdate() { url="$1" filename="$2" + + # Check if script path is writable + if [ ! -w "$ScriptWorkingDirectory" ]; then + Output "Script path is not writable." + exit 2 + fi + # Download the file and check if the download was successful if curl -s "$url" --output "$filename"; then Output "Update downloaded successfully" @@ -1604,7 +1611,7 @@ do echo " 11 - 'status' - Report status of PMS (run-state and databases)" echo " 12 - 'undo' - Undo last successful command" echo "" - echo " 00 - 'update' - Check for script update" + echo " 98 - 'update' - Check for script update" echo " 99 - 'quit' - Quit immediately. Keep all temporary files." echo " 'exit' - Exit with cleanup options." fi @@ -1906,22 +1913,27 @@ do DoUndo ;; - 00|update) + 98|upda*) - Output "Checking for script update" - GetLatestRelease - if [ $LatestVersion != $Version ]; then - Output "Version update available" - if ConfirmYesNo "Download and update script?"; then + DoUpdate=0 + Output "Checking for script update" + GetLatestRelease + if [ $LatestVersion != $Version ] && ([ $Scripted -eq 1 ] || ConfirmYesNo "Download and update script?"); then + DoUpdate=1 + Output "Version update available" + else + Output "No update available" + fi + + if [ $DoUpdate -eq 1 ]; then + Output "Performing update" DownloadAndUpdate "https://raw.githubusercontent.com/ChuckPa/PlexDBRepair/master/DBRepair.sh" "$ScriptWorkingDirectory/$ScriptName" exit 0 - else - Output "Download aborted" fi - - else - Output "No update available" - fi + + if [ $Scripted -eq 1 ]; then + exit 0 + fi ;; # Quit From cfddb949c47021a156272a693faf75526ede222a Mon Sep 17 00:00:00 2001 From: causefx Date: Wed, 11 Oct 2023 08:54:22 -0700 Subject: [PATCH 3/4] change 98 to 88 on update --- DBRepair.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DBRepair.sh b/DBRepair.sh index abed3ee..6b62fa7 100755 --- a/DBRepair.sh +++ b/DBRepair.sh @@ -1611,7 +1611,7 @@ do echo " 11 - 'status' - Report status of PMS (run-state and databases)" echo " 12 - 'undo' - Undo last successful command" echo "" - echo " 98 - 'update' - Check for script update" + echo " 88 - 'update' - Check for script update" echo " 99 - 'quit' - Quit immediately. Keep all temporary files." echo " 'exit' - Exit with cleanup options." fi @@ -1913,7 +1913,7 @@ do DoUndo ;; - 98|upda*) + 88|upda*) DoUpdate=0 Output "Checking for script update" From e63b7552bb2335df670a5e56c93922796d2679e8 Mon Sep 17 00:00:00 2001 From: causefx Date: Wed, 11 Oct 2023 20:31:04 -0700 Subject: [PATCH 4/4] Update DBRepair.sh --- DBRepair.sh | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/DBRepair.sh b/DBRepair.sh index 6b62fa7..07bf564 100755 --- a/DBRepair.sh +++ b/DBRepair.sh @@ -1451,12 +1451,6 @@ DownloadAndUpdate() { url="$1" filename="$2" - # Check if script path is writable - if [ ! -w "$ScriptWorkingDirectory" ]; then - Output "Script path is not writable." - exit 2 - fi - # Download the file and check if the download was successful if curl -s "$url" --output "$filename"; then Output "Update downloaded successfully" @@ -1922,15 +1916,20 @@ do DoUpdate=1 Output "Version update available" else - Output "No update available" + Output "No update available or user declined update" fi + # Check if script path is writable if [ $DoUpdate -eq 1 ]; then - Output "Performing update" - DownloadAndUpdate "https://raw.githubusercontent.com/ChuckPa/PlexDBRepair/master/DBRepair.sh" "$ScriptWorkingDirectory/$ScriptName" - exit 0 + if [ -w "$ScriptWorkingDirectory" ]; then + Output "Performing update" + DownloadAndUpdate "https://raw.githubusercontent.com/ChuckPa/PlexDBRepair/master/DBRepair.sh" "$ScriptWorkingDirectory/$ScriptName" + exit 0 + else + Output "Script path is not writable." + fi fi - + if [ $Scripted -eq 1 ]; then exit 0 fi