Manual mode - Initial commit

This commit is contained in:
ChuckPa 2024-05-01 02:02:32 -04:00
parent ee8556d0f9
commit 852fdfc0d5
No known key found for this signature in database
GPG Key ID: 3CE28A0F6BC31B5B
3 changed files with 146 additions and 43 deletions

View File

@ -2,15 +2,12 @@
######################################################################### #########################################################################
# Plex Media Server database check and repair utility script. # # Plex Media Server database check and repair utility script. #
# Maintainer: ChuckPa # # Maintainer: ChuckPa #
# Version: v1.05.02 # # Version: v1.06.00 #
# Date: 26-Mar-2024 # # Date: 01-May-2024 #
######################################################################### #########################################################################
# Version for display purposes # Version for display purposes
Version="v1.05.02" Version="v1.06.00"
# Flag when temp files are to be retained
Retain=0
# Have the databases passed integrity checks # Have the databases passed integrity checks
CheckedDB=0 CheckedDB=0
@ -39,6 +36,7 @@ CPPL=com.plexapp.plugins.library
TimeStamp="$(date "+%Y-%m-%d_%H.%M.%S")" TimeStamp="$(date "+%Y-%m-%d_%H.%M.%S")"
# Initialize global runtime variables # Initialize global runtime variables
ManualConfig=0
CheckedDB=0 CheckedDB=0
Damaged=0 Damaged=0
DbPageSize=0 DbPageSize=0
@ -49,6 +47,15 @@ LOG_TOOL="echo"
ShowMenu=1 ShowMenu=1
Exit=0 Exit=0
# On all hosts except Mac
PIDOF="pidof"
STATFMT="-c"
STATBYTES="%s"
STATPERMS="%a"
# On all hosts except QNAP
DFFLAGS="-m"
# Universal output function # Universal output function
Output() { Output() {
if [ $Scripted -gt 0 ]; then if [ $Scripted -gt 0 ]; then
@ -363,6 +370,15 @@ HostConfig() {
# On all hosts except QNAP # On all hosts except QNAP
DFFLAGS="-m" DFFLAGS="-m"
# Manual Config
if [ $ManualConfig -eq 1 ]; then
CacheDir="$DBDIR/../../Cache"
Logfile="$DBDIR/DBRepair.log"
HostType="MANUAL"
return 0
fi
# Synology (DSM 7) # Synology (DSM 7)
if [ -d /var/packages/PlexMediaServer ] && \ if [ -d /var/packages/PlexMediaServer ] && \
[ -d "/var/packages/PlexMediaServer/shares/PlexMediaServer/AppData/Plex Media Server" ]; then [ -d "/var/packages/PlexMediaServer/shares/PlexMediaServer/AppData/Plex Media Server" ]; then
@ -1095,7 +1111,6 @@ DoRepair() {
Output "Repair has failed. No files changed" Output "Repair has failed. No files changed"
WriteLog "Repair - $TimeStamp - FAIL" WriteLog "Repair - $TimeStamp - FAIL"
CheckedDB=0 CheckedDB=0
Retain=1
return 1 return 1
fi fi
} }
@ -1529,16 +1544,10 @@ DoStop(){
} }
# Do command line switches # Do command line switches
DoOptions() { #DoOptions() {
for i in $@
do #}
Opt="$(echo $i | cut -c1-2 | tr [A-Z] [a-z])"
[ "$Opt" = "-i" ] && IgnoreErrors=1 && WriteLog "Opt: Database error checking ignored."
[ "$Opt" = "-f" ] && IgnoreErrors=1 && WriteLog "Opt: Database error checking ignored."
[ "$Opt" = "-p" ] && RemoveDuplicates=1 && WriteLog "Opt: Remove duplidate watch history viewstates."
done
}
# UpdateTimestamp # UpdateTimestamp
DoUpdateTimestamp() { DoUpdateTimestamp() {
@ -1644,16 +1653,76 @@ ScriptWorkingDirectory="$(dirname "$ScriptPath")"
# Initialize LastName LastTimestamp # Initialize LastName LastTimestamp
SetLast "" "" SetLast "" ""
# Process any given command line options in the ugliest manner possible :P~~
while [ "$(echo $1 | cut -c1)" = "-" ] && [ "$1" != "" ]
do
Opt="$(echo $1 | awk '{print $1'} | tr [A-Z] [a-z])"
[ "$Opt" = "-i" ] && shift
[ "$Opt" = "-f" ] && shift
[ "$Opt" = "-p" ] && shift
# Manual configuration options (running outside of container)
if [ "$Opt" = "--sqlite" ]; then
# Manually specify path to where Plex SQLite is installed.
if [ -d "$2" ] && [ -f "$2/Plex SQLite" ]; then
PLEX_SQLITE="$2/Plex SQLite"
ManualConfig=1
else
Output "Given directory path ('$1') for Plex SQLite is invalid. Ignoring."
fi
shift 2
fi
# Manual path to databases
if [ "$Opt" = "--databases" ]; then
# Manually specify path to where the databases reside
if [ -d "$2" ] && [ -f "$2"/com.plexapp.plugins.library.db ]; then
DBDIR="$2"
ManualConfig=1
LOGFILE="$DBDIR/DBRepair.log"
AppSuppDir="$( dirname "$(dirname "$(dirname "$db")))")")"
else
Output "Given directory path ('$1') for Plex databases is invalid. Ignoring."
fi
shift 2
fi
done
# Confirm completed manual config
if [ $ManualConfig -eq 1 ]; then
if [ "$DBDIR" = "" ] || [ "$PLEX_SQLITE" = "" ]; then
Output "Error: Both 'Plex SQLite' and Databases directory paths must be specified with Manual configuration."
WriteLog "Manual configuration incomplete. One of the required arguments was missing."
exit 2
fi
# Performing logging here
[ $IgnoreErrors -eq 1 ] && WriteLog "Opt: Database error checking ignored."
[ $RemoveDuplicates -eq 1 ] && WriteLog "Opt: Remove duplidate watch history viewstates."
WriteLog "Plex SQLite = '$PLEX_SQLITE'"
WriteLog "Databases = '$DBDIR'"
# Final configuration
HostType="User Defined"
fi
# Are we scripted (command line args) # Are we scripted (command line args)
Scripted=0 Scripted=0
[ "$1" != "" ] && Scripted=1 [ "$1" != "" ] && Scripted=1
# Identify this host # Identify this host
if ! HostConfig; then if [ $ManualConfig -eq 0 ] && ! HostConfig; then
Output 'Error: Unknown host. Current supported hosts are: QNAP, Syno, Netgear, Mac, ASUSTOR, WD (OS5), Linux wkstn/svr, SNAP' Output 'Error: Unknown host. Current supported hosts are: QNAP, Syno, Netgear, Mac, ASUSTOR, WD (OS5), Linux wkstn/svr, SNAP'
Output ' Current supported container images: Plexinc, LinuxServer, HotIO, & BINHEX' Output ' Current supported container images: Plexinc, LinuxServer, HotIO, & BINHEX'
Output ' ' Output ' '
Output 'Are you trying to run the tool from outside the container environment ?' Output 'Are you trying to run the tool from outside the container environment? Manual mode is available. Please see documentation.'
exit 1 exit 1
fi fi
@ -1676,13 +1745,6 @@ echo " "
WriteLog "============================================================" WriteLog "============================================================"
WriteLog "Session start: Host is $HostType" WriteLog "Session start: Host is $HostType"
# Command line hidden options must come before commands
while [ "$(echo $1 | cut -c1)" = "-" ]
do
DoOptions "$1"
shift
done
# Make sure we have a logfile # Make sure we have a logfile
touch "$LOGFILE" touch "$LOGFILE"
@ -1743,6 +1805,13 @@ do
echo " Version $Version" echo " Version $Version"
echo " " echo " "
# Print info if Manual
if [ $ManualConfig -eq 1 ]; then
WriteLog "Manual SQLite path: '$PLEX_SQLITE'
WriteLog "Manual Database path: '$DBDIR'
Output " PlexSQLite = '$PLEX_SQLITE'"
Output " Databases = '$DBDIR'"
fi
Choice=0; Exit=0; NullCommands=0 Choice=0; Exit=0; NullCommands=0
@ -1785,24 +1854,9 @@ do
if [ $Scripted -eq 0 ]; then if [ $Scripted -eq 0 ]; then
echo "" echo ""
printf "Enter command # -or- command name (4 char min) : " printf "Enter command # -or- command name (4 char min) : "
else
Input="$1"
# If end of line then force exit # Read next command from user
if [ "$Input" = "" ]; then read Input
Input="exit"
Exit=1
Output "Unexpected EOF / End of command line options. Exiting. Keeping temp files."
fi
fi
# Watch for null command whether scripted or not.
if [ "$1" != "" ]; then
Input="$1"
# echo "$1"
shift
else
[ $Scripted -eq 0 ] && read Input
# Handle EOF/forced exit # Handle EOF/forced exit
if [ "$Input" = "" ] ; then if [ "$Input" = "" ] ; then
@ -1817,6 +1871,18 @@ do
else else
NullCommands=0 NullCommands=0
fi fi
else
# Scripted
Input="$1"
# If end of line then force exit
if [ "$Input" = "" ]; then
Input="exit"
else
shift
fi
fi fi
# Update timestamp # Update timestamp

View File

@ -293,6 +293,8 @@ Attention:
This executes: Stop PMS, Automatic (Check, Repair, Reindex), Start PMS, and Exit commands This executes: Stop PMS, Automatic (Check, Repair, Reindex), Start PMS, and Exit commands
Beginning with v1.06.00, the 'exit' command is optional when scripted.
## Exiting ## Exiting
@ -850,6 +852,21 @@ root@lizum:/sata/plex/Plex Media Server/Plug-in Support/Databases#
# #
``` ```
# Special considerations - MANUAL CONFIGURATION
Manual configuration is enabled by supplying two command line arguments.
These must precede all other options or commands on the command line.
Scripted Example:
DBRepair.sh --sqlite /usr/lib/plexmediaserver --databases /real/host/directory/...../Databases auto prune
Interactive Example:
DBRepair.sh --sqlite /usr/lib/plexmediaserver --databases /real/host/directory/...../Databases
# Special considerations - Synology DSM 7 # Special considerations - Synology DSM 7
Using DBRepair on Synology DSM 7 systems with Task Scheduler requires special handling. Using DBRepair on Synology DSM 7 systems with Task Scheduler requires special handling.

View File

@ -8,9 +8,29 @@
![Maintenance](https://img.shields.io/badge/Maintained-Yes-green.svg) ![Maintenance](https://img.shields.io/badge/Maintained-Yes-green.svg)
# Release Info: # Release Info:
v1.06.00
1. Manual configuration - You may now run DBRepair from outside container environments.
This provides a method for running DBRepair when container healthcheck prevents it.
The directories to both:
a. Where Plex SQLite can be found: ( --sqlite "/real/host/path/to/plexmediaserver/Directory" )
b. Where the databases can be found: ( --databases "/real/host/path/to/Plugin Support/Databases" )
If used, these options MUST precede all other command line options
WARNING: The host MUST provide all standard commands AND support "stat -c" option. Bash commands will NOT autoconfigure.
2. "Exit" when scripted: The previously annoyance which required "exit" to be specified on the command line (scripted) has been fixed.
"exit" is no longer required in this use.
"exit" or "quit" is still required in interactive use.
v1.05.02 v1.05.02
1 HOTIO image paths HOTIO images have again changed PMS executable location. This update 1. HOTIO image paths HOTIO images have again changed PMS executable location. This update
adds support for the lastest location. adds support for the lastest location.
v1.05.01 v1.05.01