ChuckPa / PlexDBRepair

Database repair utility for Plex Media Server databases
Other
867 stars 43 forks source link

Support for arch-based distributions #78

Closed Frankkz closed 1 year ago

Frankkz commented 1 year ago

Problem

Currently the bash script is hard coded to find "Arch Linux" in the os-release file https://github.com/ChuckPa/PlexDBRepair/blob/40a8873ce1922c5a6f7c0b993eb3fd635e16e6bd/DBRepair.sh#L621-L624 This creates the problem that only the official Arch Linux distribution is allowed run the script, even though it should also work on arch-based distros.

Proposal

I did some digging to maybe find a better way to identify arch-based distributions and learned about the "ID_LIKE" parameter.

https://www.freedesktop.org/software/systemd/man/os-release.html#ID_LIKE=

ID_LIKE=

A space-separated list of operating system identifiers in the same syntax as the ID= setting. It should list identifiers of operating systems that are closely related to the local operating system in regards to packaging and programming interfaces, for example listing one or more OS identifiers the local OS is a derivative from. An OS should generally only list other OS identifiers it itself is a derivative of, and not any OSes that are derived from it, though symmetric relationships are possible. Build scripts and similar should check this variable if they need to identify the local operating system and the value of ID= is not recognized. Operating systems should be listed in order of how closely the local operating system relates to the listed ones, starting with the closest. This field is optional.

Examples: for an operating system with "ID=centos", an assignment of "ID_LIKE="rhel fedora"" would be appropriate. For an operating system with "ID=ubuntu", an assignment of "ID_LIKE=debian" is appropriate.

Notes

If you are using this file to determine the OS or a specific version of it, use the ID and VERSION_ID fields, possibly with ID_LIKE as fallback for ID.

/etc/os-release files of several arch-based distros

Manjaro - https://gitlab.manjaro.org/packages/core/filesystem/-/blob/master/os-release

NAME="Manjaro Linux"
PRETTY_NAME="Manjaro Linux"
ID=manjaro
ID_LIKE=arch
BUILD_ID=rolling
ANSI_COLOR="32;1;24;144;200"
HOME_URL="https://manjaro.org/"
DOCUMENTATION_URL="https://wiki.manjaro.org/"
SUPPORT_URL="https://forum.manjaro.org/"
BUG_REPORT_URL="https://docs.manjaro.org/reporting-bugs/"
PRIVACY_POLICY_URL="https://manjaro.org/privacy-policy/"
LOGO=manjarolinux

Manjaro ARM - https://gitlab.manjaro.org/manjaro-arm/packages/core/filesystem/-/blob/master/os-release

NAME="Manjaro ARM"
ID="manjaro-arm"
ID_LIKE="manjaro arch"
PRETTY_NAME="Manjaro ARM"
ANSI_COLOR="1;32"
HOME_URL="https://www.manjaro.org/"
SUPPORT_URL="https://forum.manjaro.org/c/arm/"
LOGO=manjarolinux

EndeavourOS

NAME=EndeavourOS
PRETTY_NAME=EndeavourOS
ID=endeavouros
ID_LIKE=arch
BUILD_ID=rolling
ANSI_COLOR="38;2;23;147;209"
HOME_URL='https://endeavouros.com'
DOCUMENTATION_URL='https://discovery.endeavouros.com'
SUPPORT_URL='https://forum.endeavouros.com'
BUG_REPORT_URL='https://forum.endeavouros.com/c/arch-based-related-questions/bug-reports'
PRIVACY_POLICY_URL="https://terms.archlinux.org/docs/privacy-policy/"
LOGO=endeavouros

ArcoLinux - https://github.com/arcolinux/arcolinux-system-config/blob/master/usr/local/share/arcolinux/release/os-release-arco

NAME=ArcoLinux
ID=arcolinux
ID_LIKE=arch
BUILD_ID=rolling
ANSI_COLOR="0;36"
HOME_URL="https://arcolinux.info/"
SUPPORT_URL="https://arcolinuxforum.com/"
BUG_REPORT_URL="https://github.com/arcolinux"
LOGO=arcolinux-hello

Note: ID_LIKE is optional so there will likely be arch-based distros that miss this check but at least the majority will be covered :).

Personal Test

Successfully ran this on my Manjaro machine.

2023-06-08 12.50.32 - ============================================================
2023-06-08 12.50.32 - Session start: Host is Arch Linux
2023-06-08 12.50.58 - Stop    - PASS
2023-06-08 12.51.10 - Vacuum  - Check com.plexapp.plugins.library.db - PASS
2023-06-08 12.51.12 - Vacuum  - Check com.plexapp.plugins.library.blobs.db - PASS
2023-06-08 12.51.12 - Vacuum  - MakeBackup com.plexapp.plugins.library.db - PASS
2023-06-08 12.51.12 - Vacuum  - MakeBackup com.plexapp.plugins.library.blobs.db - PASS
2023-06-08 12.51.12 - Vacuum  - MakeBackups - PASS
2023-06-08 12.51.13 - Vacuum  - Vacuum main database - PASS (Size: 77MB/77MB).
2023-06-08 12.51.16 - Vacuum  - Vacuum blobs database - PASS (Size: 146MB/146MB).
2023-06-08 12.51.16 - Vacuum  - PASS
2023-06-08 12.51.24 - Check   - Check com.plexapp.plugins.library.db - PASS
2023-06-08 12.51.24 - Check   - Check com.plexapp.plugins.library.blobs.db - PASS
2023-06-08 12.51.24 - Check   - PASS
2023-06-08 12.51.38 - Exit    - Retain temp files.

Thanks!

ChuckPa commented 1 year ago

When you look at all theses distributions, are they all using the same Application Support directory path?

I don't mind picking up support for miscellaneous variants but it's not within scope to support everything. When using docker, there is a level of implied skill here. It should be easy enough for the "weird distros" to tweak the script to work.

The core features of the script are largely set. I don't see much more happening to it.

Frankkz commented 1 year ago

When you look at all theses distributions, are they all using the same Application Support directory path?

Yes, because all these arch-based distros use the same package repository for their Plex Media Server.
plex-media-server or plex-media-server-plexpass

The above packages create the following file upon installation: https://aur.archlinux.org/cgit/aur.git/tree/plexmediaserver.conf.d?h=plex-media-server cat /etc/conf.d/plexmediaserver

# If your LC_ALL and LANG aren't en_US.UTF-8, plex crashes.
LC_ALL=en_US.UTF-8
LANG=en_US.UTF-8

LD_LIBRARY_PATH=/usr/lib/plexmediaserver/lib
PLEX_MEDIA_SERVER_HOME=/usr/lib/plexmediaserver
PLEX_MEDIA_SERVER_APPLICATION_SUPPORT_DIR=/var/lib/plex
PLEX_MEDIA_SERVER_MAX_PLUGIN_PROCS=6
PLEX_MEDIA_SERVER_TMPDIR=/tmp
TMPDIR=/tmp

I don't mind picking up support for miscellaneous variants but it's not within scope to support everything. When using docker, there is a level of implied skill here. It should be easy enough for the "weird distros" to tweak the script to work.

The core features of the script are largely set. I don't see much more happening to it.

I understand. The script for arch-based distros is already there, simply adjusting "[ grep "Arch Linux" ]" to also search for "ID_LIKE=arch" would be all that's really needed to successfully run on distributions based on Arch Linux.

I am not too experienced with shell scripting but this is what I'd suggest;

HostConfig() {
  ...
  # Arch Linux (must check for native Arch after binhex)
  if [ -e /etc/os-release ] && { source /etc/os-release; ( [[ $ID == "arch" ]] || [[ $ID_LIKE == *"arch"* ]] ) } && \
     [ -d /usr/lib/plexmediaserver ] && \
     [ -d /var/lib/plex ]; then
      ...
      HostType="$PRETTY_NAME"
      ...
      return 0
  fi
  return 1
  ...
}

Running DBRepair.sh with the above modification will successfully run the script :)

2023-06-09 14.11.24 - ============================================================
2023-06-09 14.11.24 - Session start: Host is Manjaro Linux
2023-06-09 14.11.28 - Stop    - PASS
2023-06-09 14.12.54 - Auto    - START
2023-06-09 14.12.56 - Check   - Check com.plexapp.plugins.library.db - PASS
2023-06-09 14.12.57 - Check   - Check com.plexapp.plugins.library.blobs.db - PASS
2023-06-09 14.12.57 - Check   - PASS
2023-06-09 14.13.11 - Repair  - Export databases - PASS
2023-06-09 14.13.17 - Repair  - Import - PASS
2023-06-09 14.13.18 - Repair  - Verify main database - PASS (Size: 77MB/71MB).
2023-06-09 14.13.18 - Repair  - Verify blobs database - PASS (Size: 143MB/146MB).
2023-06-09 14.13.18 - Repair  - Move files - PASS
2023-06-09 14.13.18 - Repair  - PASS
2023-06-09 14.13.18 - Repair  - PASS
2023-06-09 14.13.18 - Reindex - MakeBackup com.plexapp.plugins.library.db - PASS
2023-06-09 14.13.18 - Reindex - MakeBackup com.plexapp.plugins.library.blobs.db - PASS
2023-06-09 14.13.18 - Reindex - MakeBackup - PASS
2023-06-09 14.13.19 - Reindex - Reindex: com.plexapp.plugins.library.db - PASS
2023-06-09 14.13.19 - Reindex - Reindex: com.plexapp.plugins.library.blobs.db - PASS
2023-06-09 14.13.19 - Reindex - PASS
2023-06-09 14.13.19 - Reindex - PASS
2023-06-09 14.13.19 - Auto    - COMPLETED
2023-06-09 14.13.35 - Exit    - Retain temp files.