Merge pull request #105 from ChuckPa/chuckpa/UpdateDBRepair

v1.01.00 -  Add self-update capability
This commit is contained in:
Chuck 2023-10-16 16:42:04 -07:00 committed by GitHub
commit 2958fb5c26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 168 additions and 124 deletions

View File

@ -2,12 +2,12 @@
#########################################################################
# Plex Media Server database check and repair utility script. #
# Maintainer: ChuckPa #
# Version: v1.0.13 #
# Date: 23-Sep-2023 #
# Version: v1.01.00 #
# Date: 16-Oct-2023 #
#########################################################################
# Version for display purposes
Version="v1.0.13"
Version="v1.01.00"
# Flag when temp files are to be retained
Retain=0
@ -303,6 +303,13 @@ RestoreSaved() {
done
}
# Return only the digits in the given version string
VersionDigits() {
local ver
ver=$(echo "$1" | tr -d [v\.] )
echo $ver
}
# Get the size of the given DB in MB
GetSize() {
@ -1430,40 +1437,50 @@ DoOptions() {
done
}
##### UpdateTimestamp
# UpdateTimestamp
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")
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')
LatestVersion="$(echo "$Response" | grep -oP '"name":\s*"\K[^"]*' | sed -n '1p' | tr -d '[v\.]')"
else
LatestVersion=$Version
LatestVersion="$Version"
fi
}
# Download and update script
DownloadAndUpdate() {
url="$1"
filename="$2"
Url="$1"
Filename="$2"
# Download the file and check if the download was successful
if curl -s "$url" --output "$filename"; then
if curl -s "$Url" --output "${Filename}.tmp"; then
# Check if the file was written to and at least 50000 bytes
if [ -f "${Filename}.tmp" ]; then
if [ $(stat $STATFMT $STATBYTES "${Filename}.tmp") -gt 50000 ]; then
Output "Update downloaded successfully"
# Check if the file was written to
if [ -f "$filename" ]; then
Output "Update written successfully"
mv "$Filename" "${Filename}.bak"
mv "${Filename}.tmp" "$Filename"
chmod +x "$Filename"
return 0
else
Output "Error: File not written"
Output "Error: Downloaded file incomplete."
rm -f "${Filename}.tmp"
fi
else
Output "Error: Download failed"
Output "Error: Unable to download update."
rm -f "${Filename}.tmp"
fi
else
Output "Error: Download failed."
rm -f "${Filename}.tmp"
fi
return 1
}
#############################################################
@ -1471,7 +1488,7 @@ DownloadAndUpdate() {
#############################################################
# Set Script Path
ScriptPath="$( readlink -f "$0")"
ScriptPath="$(readlink -f "$0")"
ScriptName="$(basename "$ScriptPath")"
ScriptWorkingDirectory="$(dirname "$ScriptPath")"
@ -1588,24 +1605,24 @@ do
echo ""
echo "Select"
echo ""
[ $HaveStartStop -gt 0 ] && echo " 1 - 'stop' - Stop PMS"
[ $HaveStartStop -eq 0 ] && echo " 1 - 'stop' - (Not available. Stop manually)"
echo " 2 - 'automatic' - database check, repair/optimize, and reindex in one step."
echo " 3 - 'check' - Perform integrity check of database"
echo " 4 - 'vacuum' - Remove empty space from database"
echo " 5 - 'repair' - Repair/Optimize databases"
echo " 6 - 'reindex' - Rebuild database database indexes"
[ $HaveStartStop -gt 0 ] && echo " 1 - 'stop' - Stop PMS."
[ $HaveStartStop -eq 0 ] && echo " 1 - 'stop' - (Not available. Stop manually.)"
echo " 2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step."
echo " 3 - 'check' - Perform integrity check of database."
echo " 4 - 'vacuum' - Remove empty space from database without optimizing."
echo " 5 - 'repair' - Repair/Optimize databases."
echo " 6 - 'reindex' - Rebuild database database indexes."
[ $HaveStartStop -gt 0 ] && echo " 7 - 'start' - Start PMS"
[ $HaveStartStop -eq 0 ] && echo " 7 - 'start' - (Not available. Start manually)"
echo ""
echo " 8 - 'import' - Import watch history from another database independent of Plex. (risky)"
echo " 9 - 'replace' - Replace current databases with newest usable backup copy (interactive)"
echo " 10 - 'show' - Show logfile"
echo " 11 - 'status' - Report status of PMS (run-state and databases)"
echo " 12 - 'undo' - Undo last successful command"
echo " 8 - 'import' - Import watch history from another database independent of Plex. (risky)."
echo " 9 - 'replace' - Replace current databases with newest usable backup copy (interactive)."
echo " 10 - 'show' - Show logfile."
echo " 11 - 'status' - Report status of PMS (run-state and databases)."
echo " 12 - 'undo' - Undo last successful command."
echo ""
echo " 88 - 'update' - Check for script update"
echo " 88 - 'update' - Check for updates."
echo " 99 - 'quit' - Quit immediately. Keep all temporary files."
echo " 'exit' - Exit with cleanup options."
fi
@ -1910,29 +1927,33 @@ do
88|upda*)
DoUpdate=0
Output "Checking for script update"
Output "Checking for update"
GetLatestRelease
if [ $LatestVersion != $Version ] && ([ $Scripted -eq 1 ] || ConfirmYesNo "Download and update script?"); then
DoUpdate=1
Output "Version update available"
if [ $(VersionDigits $LatestVersion) -gt $(VersionDigits $Version) ]; then
[ $Scripted -eq 1 ] && DoUpdate=1
[ ConfirmYesNo "Download $Latest and update?" ] && DoUpdate=1
else
Output "No update available or user declined update"
Output "No update available."
fi
# Check if script path is writable
if [ $DoUpdate -eq 1 ]; then
if [ -w "$ScriptWorkingDirectory" ]; then
Output "Performing update"
Output "Updating from $Version to $LatestVersion"
DownloadAndUpdate "https://raw.githubusercontent.com/ChuckPa/PlexDBRepair/master/DBRepair.sh" "$ScriptWorkingDirectory/$ScriptName"
Result=$?
if [ $Result -eq 0 ]; then
chmod +x "$ScriptWorkingDirectory/$ScriptName"
Output "Restart to launch updated DBRepair.sh ($LatestVersion)"
WriteLog "Update - Updated to version $LatestVersion."
exit 0
fi
else
Output "Script path is not writable."
Output "Script path '${ScriptName}' is not writable."
fi
fi
if [ $Scripted -eq 1 ]; then
exit 0
fi
[ $Scripted -eq 1 ] && [ $DoUpdate -eq 1 ] && exit 0
;;
# Quit

177
README.md
View File

@ -50,24 +50,27 @@ If sufficient privleges exist (root), and supported by the environment, the opti
```
Plex Media Server Database Repair Utility (_host_configuration_name_)
Version v1.0
Version v1.01.00
Select
1 - 'stop' PMS (if available)
2 - 'automatic' database check, repair/optimize, and reindex in one step.
3 - 'check' database
4 - 'vacuum' database
5 - 'repair' / 'optimize' database
6 - 'reindex' database
7 - 'start' PMS (if available)
8 - 'import' viewstate (Watch history) from another PMS database
9 - 'replace' current database with newest usable backup copy (interactive)
10 - 'show' logfile
11 - 'status' of PMS (Stop/Run and databases)
12 - 'undo' - Undo last successful command
1 - 'stop' - Stop PMS.
2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step.
3 - 'check' - Perform integrity check of database.
4 - 'vacuum' - Remove empty space from database without optimizing.
5 - 'repair' - Repair/Optimize databases.
6 - 'reindex' - Rebuild database database indexes.
7 - 'start' - Start PMS
99 - exit
8 - 'import' - Import watch history from another database independent of Plex. (risky).
9 - 'replace' - Replace current databases with newest usable backup copy (interactive).
10 - 'show' - Show logfile.
11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command.
88 - 'update' - Check for updates.
99 - 'quit' - Quit immediately. Keep all temporary files.
'exit' - Exit with cleanup options.
Enter command # -or- command name (4 char min) :
@ -294,27 +297,29 @@ bash-4.4# ./DBRepair.sh
Plex Media Server Database Repair Utility (Synology (DSM 7))
Version v1.0.0
Plex Media Server Database Repair Utility (Ubuntu 20.04.6 LTS)
Version v1.01.00
Select
1 - 'stop' - Stop PMS
2 - 'automatic' - database check, repair/optimize, and reindex in one step.
3 - 'check' - Perform integrity check of database
4 - 'vacuum' - Remove empty space from database
5 - 'repair' - Repair/Optimize databases
6 - 'reindex' - Rebuild database database indexes
1 - 'stop' - Stop PMS.
2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step.
3 - 'check' - Perform integrity check of database.
4 - 'vacuum' - Remove empty space from database without optimizing.
5 - 'repair' - Repair/Optimize databases.
6 - 'reindex' - Rebuild database database indexes.
7 - 'start' - Start PMS
8 - 'import' - Import watch history from another database independent of Plex. (risky)
9 - 'replace' - Replace current databases with newest usable backup copy (interactive)
10 - 'show' - Show logfile
11 - 'status' - Report status of PMS (run-state and databases)
12 - 'undo' - Undo last successful command
8 - 'import' - Import watch history from another database independent of Plex. (risky).
9 - 'replace' - Replace current databases with newest usable backup copy (interactive).
10 - 'show' - Show logfile.
11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command.
99 - exit
88 - 'update' - Check for updates.
99 - 'quit' - Quit immediately. Keep all temporary files.
'exit' - Exit with cleanup options.
Enter command # -or- command name (4 char min) : 1
@ -323,21 +328,23 @@ Stopped PMS.
Select
1 - 'stop' - Stop PMS
2 - 'automatic' - database check, repair/optimize, and reindex in one step.
3 - 'check' - Perform integrity check of database
4 - 'vacuum' - Remove empty space from database
5 - 'repair' - Repair/Optimize databases
6 - 'reindex' - Rebuild database database indexes
1 - 'stop' - Stop PMS.
2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step.
3 - 'check' - Perform integrity check of database.
4 - 'vacuum' - Remove empty space from database without optimizing.
5 - 'repair' - Repair/Optimize databases.
6 - 'reindex' - Rebuild database database indexes.
7 - 'start' - Start PMS
8 - 'import' - Import watch history from another database independent of Plex. (risky)
9 - 'replace' - Replace current databases with newest usable backup copy (interactive)
10 - 'show' - Show logfile
11 - 'status' - Report status of PMS (run-state and databases)
12 - 'undo' - Undo last successful command
8 - 'import' - Import watch history from another database independent of Plex. (risky).
9 - 'replace' - Replace current databases with newest usable backup copy (interactive).
10 - 'show' - Show logfile.
11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command.
99 - exit
88 - 'update' - Check for updates.
99 - 'quit' - Quit immediately. Keep all temporary files.
'exit' - Exit with cleanup options.
Enter command # -or- command name (4 char min) : auto
@ -372,19 +379,23 @@ Automatic Check,Repair/optimize,Index successful.
Select
1 - 'stop' PMS
2 - 'automatic' database check, repair/optimize, and reindex in one step.
3 - 'check' database
4 - 'vacuum' database
5 - 'repair' / 'optimize' database
6 - 'reindex' database
7 - 'start' PMS
8 - 'import' viewstate (Watch history) from another PMS database
9 - 'replace' current database with newest usable backup copy (interactive)
10 - 'show' logfile
11 - 'status' of PMS (Stop/Run and databases)
12 - 'undo' - Undo last successful command
99 - exit
1 - 'stop' - Stop PMS.
2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step.
3 - 'check' - Perform integrity check of database.
4 - 'vacuum' - Remove empty space from database without optimizing.
5 - 'repair' - Repair/Optimize databases.
6 - 'reindex' - Rebuild database database indexes.
7 - 'start' - Start PMS
8 - 'import' - Import watch history from another database independent of Plex. (risky).
9 - 'replace' - Replace current databases with newest usable backup copy (interactive).
10 - 'show' - Show logfile.
11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command.
88 - 'update' - Check for updates.
99 - 'quit' - Quit immediately. Keep all temporary files.
'exit' - Exit with cleanup options.
Enter command # -or- command name (4 char min) : start
@ -393,19 +404,23 @@ Started PMS
Select
1 - 'stop' PMS
2 - 'automatic' database check, repair/optimize, and reindex in one step.
3 - 'check' database
4 - 'vacuum' database
5 - 'repair' / 'optimize' database
6 - 'reindex' database
7 - 'start' PMS
8 - 'import' viewstate (Watch history) from another PMS database
9 - 'replace' current database with newest usable backup copy (interactive)
10 - 'show' logfile
11 - 'status' of PMS (Stop/Run and databases)
12 - 'undo' - Undo last successful command
99 - exit
1 - 'stop' - Stop PMS.
2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step.
3 - 'check' - Perform integrity check of database.
4 - 'vacuum' - Remove empty space from database without optimizing.
5 - 'repair' - Repair/Optimize databases.
6 - 'reindex' - Rebuild database database indexes.
7 - 'start' - Start PMS
8 - 'import' - Import watch history from another database independent of Plex. (risky).
9 - 'replace' - Replace current databases with newest usable backup copy (interactive).
10 - 'show' - Show logfile.
11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command.
88 - 'update' - Check for updates.
99 - 'quit' - Quit immediately. Keep all temporary files.
'exit' - Exit with cleanup options.
Enter command # -or- command name (4 char min) : stat
@ -417,19 +432,23 @@ Status report: Sat Feb 25 04:38:50 PM EST 2023
Select
1 - 'stop' PMS
2 - 'automatic' database check, repair/optimize, and reindex in one step.
3 - 'check' database
4 - 'vacuum' database
5 - 'repair' / 'optimize' database
6 - 'reindex' database
7 - 'start' PMS
8 - 'import' viewstate (Watch history) from another PMS database
9 - 'replace' current database with newest usable backup copy (interactive)
10 - 'show' logfile
11 - 'status' of PMS (Stop/Run and databases)
12 - 'undo' - Undo last successful command
99 - exit
1 - 'stop' - Stop PMS.
2 - 'automatic' - Check, Repair/Optimize, and Reindex Database in one step.
3 - 'check' - Perform integrity check of database.
4 - 'vacuum' - Remove empty space from database without optimizing.
5 - 'repair' - Repair/Optimize databases.
6 - 'reindex' - Rebuild database database indexes.
7 - 'start' - Start PMS
8 - 'import' - Import watch history from another database independent of Plex. (risky).
9 - 'replace' - Replace current databases with newest usable backup copy (interactive).
10 - 'show' - Show logfile.
11 - 'status' - Report status of PMS (run-state and databases).
12 - 'undo' - Undo last successful command.
88 - 'update' - Check for updates.
99 - 'quit' - Quit immediately. Keep all temporary files.
'exit' - Exit with cleanup options.
Enter command # -or- command name (4 char min) : exit

View File

@ -8,6 +8,10 @@
![Maintenance](https://img.shields.io/badge/Maintained-Yes-green.svg)
# Release Info:
v1.01.00
- Adds ability to self download and install latest version of DBRepair.sh
- Slightly changes numbering style to accommodate future updates with new update capability.
v1.0.13