#!/usr/bin/env bash set -Eeuo pipefail source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/common.sh" build_only=false install_only=false no_restart=false while [[ $# -gt 0 ]]; do case "$1" in --build-only) build_only=true ;; --install-only) install_only=true ;; --no-restart) no_restart=true ;; -h|--help) cat <<'EOF' Usage: ./scripts/plugin-rebuild.sh [options] Build, install and restart the Jellyfin Scene Search plugin. Options: --build-only Build the DLL but do not install/restart Jellyfin. --install-only Install the already-built DLL without rebuilding it. --no-restart Install the DLL but do not restart Jellyfin. JELLYFIN_PLUGIN_DIR may override the default: /var/lib/jellyfin/plugins/SceneSearch EOF exit 0 ;; *) die "Unknown option: $1" ;; esac shift done if "$build_only" && "$install_only"; then die "--build-only and --install-only cannot be used together." fi build_plugin() { banner "Building Jellyfin plugin" if command -v dotnet >/dev/null 2>&1; then dotnet build "$PLUGIN_PROJECT" -c Release --nologo else need docker banner "dotnet not installed; using mcr.microsoft.com/dotnet/sdk:10.0" docker run --rm --pull=missing --user "$(id -u):$(id -g)" -e HOME=/tmp -v "$REPO_ROOT:/src" -w /src mcr.microsoft.com/dotnet/sdk:10.0 dotnet build "$PLUGIN_PROJECT" -c Release --nologo fi [[ -f "$PLUGIN_DLL" ]] || die "Build finished but DLL was not found: $PLUGIN_DLL" printf 'Built: %s\n' "$PLUGIN_DLL" } install_plugin() { [[ -f "$PLUGIN_DLL" ]] || die "DLL not found. Run without --install-only first: $PLUGIN_DLL" banner "Installing Jellyfin plugin" as_root mkdir -p "$JELLYFIN_PLUGIN_DIR" as_root install -m 0644 "$PLUGIN_DLL" "$JELLYFIN_PLUGIN_DIR/Jellyfin.Plugin.SceneSearch.dll" as_root chown -R jellyfin:jellyfin "$JELLYFIN_PLUGIN_DIR" printf 'Installed: %s\n' "$JELLYFIN_PLUGIN_DIR/Jellyfin.Plugin.SceneSearch.dll" if ! "$no_restart"; then banner "Restarting Jellyfin" as_root systemctl restart jellyfin if as_root systemctl is-active --quiet jellyfin; then printf 'Jellyfin is active.\n' else die "Jellyfin did not return to active state." fi fi } if ! "$install_only"; then build_plugin fi if ! "$build_only"; then install_plugin fi