Repository Public
1#!/bin/bash2# First-run setup through Jellyfin's own API: administrator account, libraries, hardware encoding.3# setup.sh <admin-user> <password-file> [name:type:path ...] type = movies | tvshows | homevideos4# Idempotent: an already completed wizard is left alone; existing libraries are not duplicated.5set -euo pipefail6J="${JELLYFIN_URL:-http://127.0.0.1:8096/jellyfin}"; USER_NAME="$1"; PW="$(cat "$2")"; shift 27A='Authorization: MediaBrowser Client="setup", Device="setup", DeviceId="jellyfin-node-setup", Version="1"'8j() { python3 -I -c "import json,sys; d=json.load(sys.stdin); print($1)"; }9body() { python3 -I -c "import json,sys; print(json.dumps({'Name': sys.argv[1], 'Password': sys.argv[2]}))" "$USER_NAME" "$PW"; }10login() { python3 -I -c "import json,sys; print(json.dumps({'Username': sys.argv[1], 'Pw': sys.argv[2]}))" "$USER_NAME" "$PW"; }11done_wizard="$(curl -fsS -m 20 "$J/System/Info/Public" | j "d['StartupWizardCompleted']")"12if [ "$done_wizard" != "True" ]; then13 curl -fsS -m 20 -X POST "$J/Startup/Configuration" -H "$A" -H 'content-type: application/json' -d '{"UICulture":"fr","MetadataCountryCode":"CA","PreferredMetadataLanguage":"fr"}' >/dev/null14 curl -fsS -m 20 "$J/Startup/User" -H "$A" >/dev/null15 body | curl -fsS -m 20 -X POST "$J/Startup/User" -H "$A" -H 'content-type: application/json' -d @- >/dev/null16 curl -fsS -m 20 -X POST "$J/Startup/RemoteAccess" -H "$A" -H 'content-type: application/json' -d '{"EnableRemoteAccess":true,"EnableAutomaticPortMapping":false}' >/dev/null || true17 curl -fsS -m 20 -X POST "$J/Startup/Complete" -H "$A" >/dev/null18 echo " assistant de démarrage terminé (compte « $USER_NAME »)"19fi20TOK="$(login | curl -fsS -m 20 -X POST "$J/Users/AuthenticateByName" -H "$A" -H 'content-type: application/json' -d @- | j "d['AccessToken']")"21AT="$A, Token=\"$TOK\""22existing="$(curl -fsS -m 20 "$J/Library/VirtualFolders" -H "$AT" | j "'|'.join(x['Name'] for x in d)")"23for spec in "$@"; do24 name="${spec%%:*}"; rest="${spec#*:}"; type="${rest%%:*}"; path="${rest#*:}"25 case "|$existing|" in *"|$name|"*) echo " bibliothèque « $name » déjà présente"; continue ;; esac26 [ -d "$path" ] || { echo " dossier absent, bibliothèque « $name » non créée : $path" >&2; continue; }27 curl -fsS -m 60 -G -X POST "$J/Library/VirtualFolders" --data-urlencode "name=$name" --data-urlencode "collectionType=$type" --data-urlencode "paths=$path" --data-urlencode "refreshLibrary=true" -H "$AT" -H 'content-type: application/json' -d '{"LibraryOptions":{"PreferredMetadataLanguage":"fr","MetadataCountryCode":"CA"}}' >/dev/null28 echo " bibliothèque « $name » ($type) → $path"29done30# Apple VideoToolbox for transcoding (falls back to software if a file cannot use it).31curl -fsS -m 20 "$J/System/Configuration/encoding" -H "$AT" | python3 -I -c "import json,sys; d=json.load(sys.stdin); d['HardwareAccelerationType']='videotoolbox'; d['EnableHardwareEncoding']=True; print(json.dumps(d))" | curl -fsS -m 20 -X POST "$J/System/Configuration/encoding" -H "$AT" -H 'content-type: application/json' -d @- >/dev/null && echo " encodage matériel VideoToolbox activé"32curl -fsS -m 20 -X POST "$J/Sessions/Logout" -H "$AT" >/dev/null || true33