Merge pull request #9 from 2bits/2bits/support-mac

Changes to support MacOS
This commit is contained in:
Chuck 2022-11-16 01:02:31 -05:00 committed by GitHub
commit 972b03c575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 54 additions and 8 deletions

View File

@ -246,7 +246,7 @@ RestoreSaved() {
# Get the size of the given DB in MB # Get the size of the given DB in MB
GetSize() { GetSize() {
Size=$(stat -c %s "$1") Size=$(stat $STATFMT $STATBYTES "$1")
Size=$(expr $Size / 1048576) Size=$(expr $Size / 1048576)
[ $Size -eq 0 ] && Size=1 [ $Size -eq 0 ] && Size=1
echo $Size echo $Size
@ -255,6 +255,11 @@ GetSize() {
# Determine which host we are running on and set variables # Determine which host we are running on and set variables
HostConfig() { HostConfig() {
# On all hosts except Mac
PIDOF="pidof"
STATFMT="-c"
STATBYTES="%s"
# 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
@ -419,6 +424,35 @@ HostConfig() {
HostType="Western Digital" HostType="Western Digital"
return 0 return 0
# Apple Mac
elif [ -d "/Applications/Plex Media Server.app" ] && \
[ -d "$HOME/Library/Application Support/Plex Media Server" ]; then
# Where is the software
PLEX_SQLITE="/Applications/Plex Media Server.app/Contents/MacOS/Plex SQLite"
AppSuppDir="$HOME/Library/Application Support"
DBDIR="$AppSuppDir/Plex Media Server/Plug-in Support/Databases"
PID_FILE="$DBDIR/dbtmp/plexmediaserver.pid"
LOGFILE="$DBDIR/DBRepair.log"
LOG_TOOL="logger"
# MacOS uses pgrep and uses different stat options
PIDOF="pgrep"
STATFMT="-f"
STATBYTES="%z"
# make the TMP directory in advance to store plexmediaserver.pid
mkdir -p "$DBDIR/dbtmp"
# Remove stale PID file if it exists
[ -f "$PID_FILE" ] && rm "$PID_FILE"
# If PMS is running create plexmediaserver.pid
PIDVALUE=$($PIDOF "Plex Media Server")
[ $PIDVALUE ] && echo $PIDVALUE > "$PID_FILE"
HostType="Mac"
return 0
fi fi
# Unknown / currently unsupported host # Unknown / currently unsupported host
@ -448,7 +482,7 @@ SetLast "" ""
# Identify this host # Identify this host
HostType="" ; LOG_TOOL="echo" HostType="" ; LOG_TOOL="echo"
if ! HostConfig; then if ! HostConfig; then
Output 'Error: Unknown host. Currently supported hosts are: QNAP, Synology, Netgear, ASUSTOR, WD (OS5) and Linux Workstation/Server' Output 'Error: Unknown host. Currently supported hosts are: QNAP, Synology, Netgear, Mac, ASUSTOR, WD (OS5) and Linux Workstation/Server'
exit 1 exit 1
fi fi
@ -497,7 +531,7 @@ while true
do do
# Is PMS already running? # Is PMS already running?
if [ -f "$PID_FILE" ] && [ "$(pidof 'Plex Media Server')" != "" ] ; then if [ -f "$PID_FILE" ] && [ "$($PIDOF 'Plex Media Server')" != "" ] ; then
Output "Plex Media Server is currently running, cannot continue." Output "Plex Media Server is currently running, cannot continue."
Output "Please stop Plex Media Server and restart this utility." Output "Please stop Plex Media Server and restart this utility."
WriteLog "PMS running. Could not continue." WriteLog "PMS running. Could not continue."
@ -728,7 +762,7 @@ do
fi fi
# Check size # Check size
Size=$(stat -c '%s' $CPPL.db) Size=$(stat $STATFMT $STATBYTES $CPPL.db)
# Exit if not valid # Exit if not valid
if [ $Size -lt 300000 ]; then if [ $Size -lt 300000 ]; then
@ -743,7 +777,7 @@ do
Fail=0 Fail=0
# Get the owning UID/GID before we proceed so we can restore # Get the owning UID/GID before we proceed so we can restore
Owner="$(stat -c '%u:%g' $CPPL.db)" Owner="$(stat $STATFMT '%u:%g' $CPPL.db)"
# Attempt to export main db to SQL file (Step 1) # Attempt to export main db to SQL file (Step 1)
printf 'Export: (main)..' printf 'Export: (main)..'
@ -1044,7 +1078,7 @@ do
done done
Output "Undo complete." Output "Undo complete."
WriteLog "Undo - Undo $LastName , TimeStamp $LastTimestamp" WriteLog "Undo - Undo ${LastName}, TimeStamp $LastTimestamp"
SetLast "Undo" "" SetLast "Undo" ""
fi fi
@ -1068,7 +1102,7 @@ do
continue continue
fi fi
WriteLog "Import - Attempting to import watch history from '$Input' " WriteLog "Import - Attempting to import watch history from '$Input' "
# Confirm our databases are intact # Confirm our databases are intact
if ! CheckDatabases; then if ! CheckDatabases; then
@ -1086,7 +1120,7 @@ do
# Make a backup # Make a backup
Output "Backing up databases" Output "Backing up databases"
if ! MakeBackups "Import "; then if ! MakeBackups "Import "; then
Output "Error making backups. Cannot continue." Output "Error making backups. Cannot continue."
WriteLog "Import - MakeBackups - FAIL" WriteLog "Import - MakeBackups - FAIL"
Fail=1 Fail=1

View File

@ -38,6 +38,7 @@ It is a simple menu-driven utility with a command line backend.
5. Synology (DSM 6 & DSM 7) 5. Synology (DSM 6 & DSM 7)
6. Docker (via 'docker exec' command line) 6. Docker (via 'docker exec' command line)
7. Western Digital (OS5) 7. Western Digital (OS5)
8. Apple (MacOS)
## How to install ## How to install
@ -55,6 +56,7 @@ It is a simple menu-driven utility with a command line backend.
Western Digital | Public | /mnt/HD/HD_a2/Public (Does not support 'MyCloudHome' series) Western Digital | Public | /mnt/HD/HD_a2/Public (Does not support 'MyCloudHome' series)
Docker | N/A | Container root (adjacent /config) Docker | N/A | Container root (adjacent /config)
Linux (wkstn/svr) | N/A | Anywhere Linux (wkstn/svr) | N/A | Anywhere
Apple | Downloads | ~/Downloads
``` ```
### To install & launch: ### To install & launch:
1. Place the tar/zip/sh file in the appropriate directory 1. Place the tar/zip/sh file in the appropriate directory
@ -89,6 +91,16 @@ It is a simple menu-driven utility with a command line backend.
./DBRepair.sh ./DBRepair.sh
``` ```
### To launch in MacOS (on the administrator account)
```
osascript -e 'quit app "Plex Media Server"'
cd ~/Downloads
tar xvf PlexDBRepair-0.3.4.tar.gz
cd PlexDBRepair-0.3.4
chmod +x DBRepair.sh
./DBRepair.sh
```
## The menu ## The menu
Plex Media Server Database Repair Utility Plex Media Server Database Repair Utility