From 31e7d625cf13ab5f11676716eb027eecd5e8e0a7 Mon Sep 17 00:00:00 2001 From: Nikolaos Karaolidis Date: Tue, 15 Jul 2025 11:01:34 +0100 Subject: [PATCH] Make jellyfin script idempotent Signed-off-by: Nikolaos Karaolidis --- .../console/podman/media/jellyfin/setup.sh | 70 ++++++++++++------- packages/docker/jellyfin/entrypoint.sh | 9 +-- .../plugins/intro-skipper/default.nix | 7 +- 3 files changed, 50 insertions(+), 36 deletions(-) diff --git a/hosts/jupiter/users/storm/configs/console/podman/media/jellyfin/setup.sh b/hosts/jupiter/users/storm/configs/console/podman/media/jellyfin/setup.sh index e521ab4..48cf451 100644 --- a/hosts/jupiter/users/storm/configs/console/podman/media/jellyfin/setup.sh +++ b/hosts/jupiter/users/storm/configs/console/podman/media/jellyfin/setup.sh @@ -1,24 +1,33 @@ # shellcheck shell=sh -curl -sf "$JELLYFIN_HOST/Startup/Configuration" \ - -X POST \ - -H 'Content-Type: application/json' \ - --data-raw '{"UICulture":"en-US","MetadataCountryCode":"US","PreferredMetadataLanguage":"en"}' +until response="$(curl -sf "$JELLYFIN_HOST/System/Info/Public")"; do + echo "Waiting for Jellyfin to be ready..." + sleep 1 +done -curl -sf "$JELLYFIN_HOST/Startup/User" +setup="$(echo "$response" | jq -r '.StartupWizardCompleted')" -curl -sf "$JELLYFIN_HOST/Startup/User" \ - -X POST \ - -H 'Content-Type: application/json' \ - --data-raw '{"Name":"'"$JELLYFIN_ADMIN_USERNAME"'","Password":"'"$JELLYFIN_ADMIN_PASSWORD"'"}' +if [ "$setup" = "false" ]; then + curl -sf "$JELLYFIN_HOST/Startup/Configuration" \ + -X POST \ + -H 'Content-Type: application/json' \ + --data-raw '{"UICulture":"en-US","MetadataCountryCode":"US","PreferredMetadataLanguage":"en"}' -curl -sf "$JELLYFIN_HOST/Startup/RemoteAccess" \ - -X POST \ - -H 'Content-Type: application/json' \ - --data-raw '{"EnableRemoteAccess":true,"EnableAutomaticPortMapping":false}' + curl -sf "$JELLYFIN_HOST/Startup/User" -curl -sf "$JELLYFIN_HOST/Startup/Complete" \ - -X POST + curl -sf "$JELLYFIN_HOST/Startup/User" \ + -X POST \ + -H 'Content-Type: application/json' \ + --data-raw '{"Name":"'"$JELLYFIN_ADMIN_USERNAME"'","Password":"'"$JELLYFIN_ADMIN_PASSWORD"'"}' + + curl -sf "$JELLYFIN_HOST/Startup/RemoteAccess" \ + -X POST \ + -H 'Content-Type: application/json' \ + --data-raw '{"EnableRemoteAccess":true,"EnableAutomaticPortMapping":false}' + + curl -sf "$JELLYFIN_HOST/Startup/Complete" \ + -X POST +fi token="$(curl -sf "$JELLYFIN_HOST/Users/AuthenticateByName" \ -X POST \ @@ -74,17 +83,6 @@ curl -sf "$JELLYFIN_HOST/Plugins/b8715ed1-6c47-4528-9ad3-f72deb539cd4/Configurat -H 'Authorization: MediaBrowser Token="'"$token"'"' \ --data-binary @- -for filepath in /etc/jellyfin/libraries/*/*.json; do - collectionType=$(jq -rn --arg s "$(basename "$(dirname "$filepath")")" '$s|@uri') - name=$(jq -rn --arg s "$(basename "$filepath" .json)" '$s|@uri') - - curl -sf "$JELLYFIN_HOST/Library/VirtualFolders?collectionType=$collectionType&name=$name" \ - -X POST \ - -H "Content-Type: application/json" \ - -H 'Authorization: MediaBrowser Token="'"$token"'"' \ - --data-binary @"$filepath" -done - curl -sf "$JELLYFIN_HOST/Plugins/505ce9d1-d916-42fa-86ca-673ef241d7df/Configuration" \ -X POST \ -H 'Content-Type: application/json' \ @@ -180,3 +178,23 @@ curl -sf "$JELLYFIN_HOST/System/Configuration/branding" \ -H 'Content-Type: application/json' \ -H "Authorization: MediaBrowser Token=$token" \ --data-binary @- + +existing_libraries="$(curl -sf "$JELLYFIN_HOST/Library/VirtualFolders" \ + -H 'Authorization: MediaBrowser Token="'"$token"'"')" + +for filepath in /etc/jellyfin/libraries/*/*.json; do + collectionType=$(jq -rn --arg s "$(basename "$(dirname "$filepath")")" '$s|@uri') + name=$(jq -rn --arg s "$(basename "$filepath" .json)" '$s|@uri') + + if echo "$existing_libraries" | jq -e --arg name "$name" 'any(.[]; .Name | @uri == $name)'; then + echo "Skipping existing virtual folder: $name" + continue + fi + + echo "Creating virtual folder: $name" + curl -sf "$JELLYFIN_HOST/Library/VirtualFolders?collectionType=$collectionType&name=$name" \ + -X POST \ + -H "Content-Type: application/json" \ + -H 'Authorization: MediaBrowser Token="'"$token"'"' \ + --data-binary @"$filepath" +done diff --git a/packages/docker/jellyfin/entrypoint.sh b/packages/docker/jellyfin/entrypoint.sh index b2b4d2d..3f0792b 100644 --- a/packages/docker/jellyfin/entrypoint.sh +++ b/packages/docker/jellyfin/entrypoint.sh @@ -17,15 +17,12 @@ start() { start "$@" +# shellcheck disable=SC2034 JELLYFIN_HOST="http://localhost:8096" +# shellcheck disable=SC2034 JELLYFIN_ADMIN_USERNAME="${JELLYFIN_ADMIN_USERNAME:-admin}" -until setup="$(curl -sf --retry 10 --retry-connrefused "$JELLYFIN_HOST/System/Info/Public" | jq -r '.StartupWizardCompleted' 2>/dev/null)"; do - echo "Waiting for Jellyfin to be ready..." - sleep 1 -done - -if [ "$setup" = "false" ] && [ -f /etc/jellyfin/setup.sh ]; then +if [ -f /etc/jellyfin/setup.sh ]; then # shellcheck disable=SC1091 . /etc/jellyfin/setup.sh diff --git a/packages/jellyfin/plugins/intro-skipper/default.nix b/packages/jellyfin/plugins/intro-skipper/default.nix index dd801ed..22801a7 100644 --- a/packages/jellyfin/plugins/intro-skipper/default.nix +++ b/packages/jellyfin/plugins/intro-skipper/default.nix @@ -2,17 +2,16 @@ # AUTO-UPDATE: nix-update --flake jellyfin-plugin-intro-skipper pkgs.stdenv.mkDerivation rec { pname = "intro-skipper"; - version = "10.11/v1.10.11.2"; + version = "10.10/v1.10.10.20"; src = let parts = pkgs.lib.strings.splitString "/" version; - major = builtins.elemAt parts 0; full = builtins.elemAt parts 1; in pkgs.fetchzip { - url = "https://github.com/intro-skipper/intro-skipper/releases/download/${major}/${full}/intro-skipper-${full}.zip"; - sha256 = "sha256-3orE9jw2LoejeNYltIju1jtxjkHYd/CydDxAxKYcp5U="; + url = "https://github.com/intro-skipper/intro-skipper/releases/download/${version}/intro-skipper-${full}.zip"; + sha256 = "sha256-RlrZkE8108Uj5V90+jw2o5fXb+K+9/hoDcEaSkKLDGg="; stripRoot = false; };