Merge pull request #70 from ChuckPa/chuckpa/quit-exit-menu

Fix Quit / Exit behavior
This commit is contained in:
Chuck 2023-05-16 20:49:25 -04:00 committed by GitHub
commit b810055546
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 31 deletions

View File

@ -3,7 +3,7 @@
# Plex Media Server database check and repair utility script. # # Plex Media Server database check and repair utility script. #
# Maintainer: ChuckPa # # Maintainer: ChuckPa #
# Version: v1.0.5 # # Version: v1.0.5 #
# Date: 04-May-2023 # # Date: 16-May-2023 #
######################################################################### #########################################################################
# Version for display purposes # Version for display purposes
@ -37,6 +37,7 @@ HaveStartStop=0
HostType="" HostType=""
LOG_TOOL="echo" LOG_TOOL="echo"
ShowMenu=1 ShowMenu=1
Exit=0
# Universal output function # Universal output function
Output() { Output() {
@ -254,11 +255,20 @@ ConfirmYesNo() {
read Input read Input
# EOF = No # EOF = No
[ "$Input" = "" ] && Answer=N ; [ "$Input" = "n" ] && Answer=N ; [ "$Input" = "N" ] && Answer=N case "$Input" in
[ "$Input" = "y" ] && Answer=Y ; [ "$Input" = "Y" ] && Answer=Y YES|YE|Y|yes|ye|y)
Answer=Y
;;
NO|N|no|n)
Answer=N
;;
*)
Answer=""
;;
esac
# Unrecognized # Unrecognized
if [ "$Answer" != "Y" ] && [ "$Answer" != "N" ]; then if [ "$Answer" != "Y" ] || [ "$Answer" != "N" ]; then
printf "$Input" was not a valid reply. Please try again. printf "$Input" was not a valid reply. Please try again.
continue continue
fi fi
@ -1468,8 +1478,8 @@ do
echo " 11 - 'status' - Report status of PMS (run-state and databases)" echo " 11 - 'status' - Report status of PMS (run-state and databases)"
echo " 12 - 'undo' - Undo last successful command" echo " 12 - 'undo' - Undo last successful command"
echo "" echo ""
echo " 99 - 'quit' - Quit immediately. Keep all temporary files."
echo " 99 - exit" echo " 'exit' - Exit with cleanup options."
fi fi
if [ $Scripted -eq 0 ]; then if [ $Scripted -eq 0 ]; then
@ -1481,7 +1491,8 @@ do
# If end of line then force exit # If end of line then force exit
if [ "$Input" = "" ]; then if [ "$Input" = "" ]; then
Input="exit" Input="exit"
Output "Unexpected EOF / End of command line options, Exiting" Exit=1
Output "Unexpected EOF / End of command line options. Exiting. Keeping temp files."
fi fi
fi fi
@ -1496,7 +1507,7 @@ do
# Handle EOF/forced exit # Handle EOF/forced exit
if [ "$Input" = "" ] ; then if [ "$Input" = "" ] ; then
if [ $NullCommands -gt 4 ]; then if [ $NullCommands -gt 4 ]; then
Output "Unexpected EOF / End of command line options, Exiting" Output "Unexpected EOF / End of command line options. Exiting. Keeping temp files. "
Input="exit" && Exit=1 Input="exit" && Exit=1
else else
NullCommands=$(($NullCommands + 1)) NullCommands=$(($NullCommands + 1))
@ -1768,20 +1779,32 @@ do
DoUndo DoUndo
;; ;;
# Quit
99|quit)
# Quit/Exit Output "Retaining all temporary work files."
99|exit|quit) WriteLog "Exit - Retain temp files."
exit 0
;;
# if cmd line mode, exit clean # Orderly Exit
exit)
# If forced exit set, exit and retain
if [ $Exit -eq 1 ]; then
Output "Unexpected exit command. Keeping all temporary work files."
WriteLog "EOFExit - Retain temp files."
exit 1
fi
# If cmd line mode, exit clean without asking
if [ $Scripted -eq 1 ]; then if [ $Scripted -eq 1 ]; then
rm -rf $TMPDIR rm -rf $TMPDIR
WriteLog "Exit - Delete temp files." WriteLog "Exit - Delete temp files."
else else
# Ask questions on interactive exit # Ask questions on interactive exit
if [ $Exit -eq 0 ]; then if ConfirmYesNo "Ok to remove temporary databases/workfiles for this session?" ; then
# Ask if the user wants to remove the DBTMP directory and all backups thus far
if [ "$Input" = "exit" ] && ConfirmYesNo "Ok to remove temporary databases/workfiles for this session?" ; then
# There it goes # There it goes
Output "Deleting all temporary work files." Output "Deleting all temporary work files."
WriteLog "Exit - Delete temp files." WriteLog "Exit - Delete temp files."
@ -1790,10 +1813,6 @@ do
Output "Retaining all temporary work files." Output "Retaining all temporary work files."
WriteLog "Exit - Retain temp files." WriteLog "Exit - Retain temp files."
fi fi
else
Output "Unexpected exit command. Keeping all temporary work files."
WriteLog "EOFExit - Retain temp files."
fi
fi fi
WriteLog "Session end. $(date)" WriteLog "Session end. $(date)"

View File

@ -131,16 +131,16 @@ If sufficient privleges exist (root), and supported by the environment, the opti
### EXAMPLE: To install & launch on Synology DSM 6 / DSM 7 ### EXAMPLE: To install & launch on Synology DSM 6 / DSM 7
cd /volume1/Plex (/volume1/PlexMediaServer on DSM 7) cd /volume1/Plex # use /volume1/PlexMediaServer on DSM 7
sudo bash sudo bash
tar xf PlexDBRepair-x.y.z.tar.gz tar xf PlexDBRepair-x.y.z.tar.gz
cd PlexDBRepair-x.y.z cd PlexDBRepair-x.y.z
chmod +x DBRepair.sh chmod +x DBRepair.sh
./DBRepair.sh ./DBRepair.sh
### EXAMPLE: Using DBRepair inside containers (manual start/stop included) ### EXAMPLE: Using DBRepair inside containers (manual start/stop included)
#### (Select containers allow stopping/starting PMS from the menu. See menu for details) #### (Select containers allow stopping/starting PMS from the menu. See menu for details)
@ -214,7 +214,7 @@ These examples
1. (3) Check - Confirm there is no database damage 1. (3) Check - Confirm there is no database damage
2. (5) Repair - You are not really repairing. You are rebuilding the DB in perfect sorted order. 2. (5) Repair - You are not really repairing. You are rebuilding the DB in perfect sorted order.
3. (6) Reindex - Rebuild Indexes. 3. (6) Reindex - Rebuild Indexes.
4. Exit - (Option 9) 4. (99) Exit
E. Undo E. Undo
Undo is a special case where you need the utility to backup ONE step. Undo is a special case where you need the utility to backup ONE step.
@ -234,8 +234,29 @@ Special considerations:
3. When satisfied, Exit the utility. 3. When satisfied, Exit the utility.
- There is no harm in keeping the database temp files (except for space used) - There is no harm in keeping the database temp files (except for space used)
- ALL database temps are named with date-time stamps in the name to avoid confusion. - ALL database temps are named with date-time stamps in the name to avoid confusion.
4. The Logfile ('show' command) shows all actions performed WITH timestamp so you can locate intermediate databases 4. The Logfile ('show' command) shows all actions performed WITH timestamp so you can locate
if desired for special / manual recovery cases. intermediate databases if desired for special / manual recovery cases.
Attention:
The behavior of command "99" is different than command "Exit"
This is intentional.
"99" is the "Get out now, Keep all intermediate/temp files.
-- This is for when DB operations keep getting worse and you don't know what to do.
"99" is an old 'Get Smart' TV series reference where agent 99 would try to save agent 86 from harm.
"99" was originally going to be "Quit immediately save all files" but development feedback
resulted in this configuration
"Exit" is the preferred method to leave.
"Quit" was desired instead of "99" but there are those who didn't understand the difference or references.
If community feedback wants both "Quit. save temps" and "Exit, delete temps", behavior is easily changed.
Also please be aware the script understands interactive versus scripted mode.
## Scripting support ## Scripting support
@ -243,7 +264,7 @@ Special considerations:
Certain platforms don't provide for each command line access. Certain platforms don't provide for each command line access.
To support those products, this utility can be operated by adding command line arguments. To support those products, this utility can be operated by adding command line arguments.
Another use of this feature is to automate Plex Database maintenance Another use of this feature is to automate Plex Database maintenance44
( Stop Plex, Run this sequence, Start Plex ) at a time when the server isn't busy ( Stop Plex, Run this sequence, Start Plex ) at a time when the server isn't busy

View File

@ -11,7 +11,8 @@
v1.0.5 v1.0.5
- Add Arch Linux Support - Add Arch Linux Support
- Put system override processing in funtion - Put system override processing in function
- Separate Quit (99) and Exit functionality to reduce confusion about temp file removal.
v1.0.4 v1.0.4
- Correct Start/Stop problem on some hosts - Correct Start/Stop problem on some hosts