about summary refs log tree commit diff
path: root/pkgs/servers/plex
diff options
context:
space:
mode:
authorSandro <sandro.jaeckel@gmail.com>2021-11-16 19:17:31 +0100
committerGitHub <noreply@github.com>2021-11-16 19:17:31 +0100
commita0a5e0be1cc6b9b37f1a53b55bbbc20c9dba6b43 (patch)
treed6caef943096b751199d673b141642ae2330f931 /pkgs/servers/plex
parent0a3a4b3f211fc96084a2088cbac9c4e6085bc49f (diff)
parentef9b3aea0836de44f26f8ece966d13a006fda1f0 (diff)
Merge pull request #139553 from andrew-d/andrew/plex-scanners
Diffstat (limited to 'pkgs/servers/plex')
-rw-r--r--pkgs/servers/plex/default.nix43
1 files changed, 36 insertions, 7 deletions
diff --git a/pkgs/servers/plex/default.nix b/pkgs/servers/plex/default.nix
index 3d69d2197803d..fd580d52d8a08 100644
--- a/pkgs/servers/plex/default.nix
+++ b/pkgs/servers/plex/default.nix
@@ -63,13 +63,9 @@ buildFHSUserEnv {
       test -d "$pluginDir" || mkdir -p "$pluginDir"
 
       # First, remove all of the symlinks in the plugins directory.
-      echo "Removing old symlinks"
-      for f in $(ls "$pluginDir/"); do
-        if [[ -L "$pluginDir/$f" ]]; then
-          echo "Removing plugin symlink: $pluginDir/$f"
-          rm "$pluginDir/$f"
-        fi
-      done
+      while IFS= read -r -d $'\0' f; do
+        echo "Removing plugin symlink: $f"
+      done < <(find "$pluginDir" -type l -print0)
 
       echo "Symlinking plugins"
       IFS=':' read -ra pluginsArray <<< "$PLEX_PLUGINS"
@@ -87,6 +83,39 @@ buildFHSUserEnv {
       done
     fi
 
+    if [[ -n "''${PLEX_SCANNERS:-}" ]]; then
+      for scannerType in Common Movies Music Series; do
+        echo "Preparing $scannerType scanners directory"
+
+        scannerDir="$PLEX_DATADIR/Plex Media Server/Scanners/$scannerType"
+        test -d "$scannerDir" || mkdir -p "$scannerDir"
+
+        # First, remove all of the symlinks in the scanners directory.
+        echo "Removing old symlinks"
+        while IFS= read -r -d $'\0' f; do
+          echo "Removing scanner symlink: $f"
+        done < <(find "$scannerDir" -type l -print0)
+
+        echo "Symlinking scanners"
+        IFS=':' read -ra scannersArray <<< "$PLEX_SCANNERS"
+        for path in "''${scannersArray[@]}"; do
+          # The provided source should contain a 'Scanners' directory; symlink
+          # from inside that.
+          subpath="$path/Scanners/$scannerType"
+          while IFS= read -r -d $'\0' file; do
+            dest="$scannerDir/$(basename "$file")"
+
+            if [[ -f "$dest" || -L "$dest" ]]; then
+              echo "Error symlinking scanner from $file to $dest: file or directory already exists"
+            else
+              echo "Symlinking scanner at: $file"
+              ln -s "$file" "$dest"
+            fi
+          done < <(find "$subpath" -type f -print0)
+        done
+      done
+    fi
+
     # Tell Plex to use the data directory as the "Application Support"
     # directory, otherwise it tries to write things into the user's home
     # directory.