From 7b09384f31633e3766434b091f26ffbfcd7b9ee1 Mon Sep 17 00:00:00 2001 From: Sleeps Date: Wed, 7 Oct 2026 11:01:43 +0100 Subject: [PATCH] Add deployment helper scripts --- scripts/common.sh | 37 ++++++++++++++++++ scripts/docker-rebuild.sh | 17 ++++++++ scripts/docker-restart.sh | 16 ++++++++ scripts/logs.sh | 11 ++++++ scripts/plugin-rebuild.sh | 81 +++++++++++++++++++++++++++++++++++++++ scripts/status.sh | 35 +++++++++++++++++ scripts/update-all.sh | 61 +++++++++++++++++++++++++++++ 7 files changed, 258 insertions(+) create mode 100755 scripts/common.sh create mode 100755 scripts/docker-rebuild.sh create mode 100755 scripts/docker-restart.sh create mode 100755 scripts/logs.sh create mode 100755 scripts/plugin-rebuild.sh create mode 100755 scripts/status.sh create mode 100755 scripts/update-all.sh diff --git a/scripts/common.sh b/scripts/common.sh new file mode 100755 index 0000000..28ace1d --- /dev/null +++ b/scripts/common.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +set -Eeuo pipefail + +SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" +REPO_ROOT="$(cd -- "${SCRIPT_DIR}/.." && pwd)" +cd "$REPO_ROOT" + +PLUGIN_PROJECT="jellyfin-plugin/Jellyfin.Plugin.SceneSearch/Jellyfin.Plugin.SceneSearch.csproj" +PLUGIN_DLL="jellyfin-plugin/Jellyfin.Plugin.SceneSearch/bin/Release/net10.0/Jellyfin.Plugin.SceneSearch.dll" +JELLYFIN_PLUGIN_DIR="${JELLYFIN_PLUGIN_DIR:-/var/lib/jellyfin/plugins/SceneSearch}" + +banner() { + printf '\n==> %s\n' "$*" +} + +die() { + printf 'ERROR: %s\n' "$*" >&2 + exit 1 +} + +need() { + command -v "$1" >/dev/null 2>&1 || die "Required command not found: $1" +} + +as_root() { + if [[ "${EUID}" -eq 0 ]]; then + "$@" + elif command -v sudo >/dev/null 2>&1; then + sudo "$@" + else + die "This step needs root privileges (run as root or install sudo)." + fi +} + +compose() { + docker compose "$@" +} diff --git a/scripts/docker-rebuild.sh b/scripts/docker-rebuild.sh new file mode 100755 index 0000000..6103c04 --- /dev/null +++ b/scripts/docker-rebuild.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/common.sh" + +need docker +compose version >/dev/null + +banner "Rebuilding and starting Docker services" + +if [[ $# -gt 0 ]]; then + compose up -d --build --remove-orphans "$@" +else + compose up -d --build --remove-orphans +fi + +banner "Docker status" +compose ps diff --git a/scripts/docker-restart.sh b/scripts/docker-restart.sh new file mode 100755 index 0000000..5663fef --- /dev/null +++ b/scripts/docker-restart.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/common.sh" + +need docker +compose version >/dev/null + +if [[ $# -eq 0 ]]; then + set -- scene-search +fi + +banner "Restarting Docker service(s): $*" +compose restart "$@" + +banner "Docker status" +compose ps "$@" diff --git a/scripts/logs.sh b/scripts/logs.sh new file mode 100755 index 0000000..f4192e8 --- /dev/null +++ b/scripts/logs.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/common.sh" + +need docker + +if [[ $# -eq 0 ]]; then + set -- scene-search +fi + +compose logs -f --tail=100 "$@" diff --git a/scripts/plugin-rebuild.sh b/scripts/plugin-rebuild.sh new file mode 100755 index 0000000..e12d689 --- /dev/null +++ b/scripts/plugin-rebuild.sh @@ -0,0 +1,81 @@ +#!/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 diff --git a/scripts/status.sh b/scripts/status.sh new file mode 100755 index 0000000..f91b57e --- /dev/null +++ b/scripts/status.sh @@ -0,0 +1,35 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/common.sh" + +need docker + +banner "Docker" +compose ps || true + +banner "Jellyfin" +if command -v systemctl >/dev/null 2>&1; then + systemctl is-active jellyfin || true +else + printf 'systemctl unavailable\n' +fi + +banner "Scene Search health" +port="${SCENE_API_PORT:-8097}" +if command -v curl >/dev/null 2>&1; then + health="$(curl -fsS "http://127.0.0.1:${port}/api/health" 2>/dev/null || true)" + if [[ -n "$health" ]]; then + if command -v python3 >/dev/null 2>&1; then + printf '%s' "$health" | python3 -m json.tool || printf '%s\n' "$health" + else + printf '%s\n' "$health" + fi + else + printf 'Scene Search health endpoint unavailable on port %s.\n' "$port" + fi +fi + +if command -v nvidia-smi >/dev/null 2>&1; then + banner "GPU" + nvidia-smi --query-gpu=name,memory.used,memory.total,utilization.gpu --format=csv,noheader || true +fi diff --git a/scripts/update-all.sh b/scripts/update-all.sh new file mode 100755 index 0000000..b902c13 --- /dev/null +++ b/scripts/update-all.sh @@ -0,0 +1,61 @@ +#!/usr/bin/env bash +set -Eeuo pipefail +source "$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)/common.sh" + +no_pull=false +skip_plugin=false +skip_docker=false + +while [[ $# -gt 0 ]]; do + case "$1" in + --no-pull) no_pull=true ;; + --skip-plugin) skip_plugin=true ;; + --skip-docker) skip_docker=true ;; + -h|--help) + cat <<'EOF' +Usage: ./scripts/update-all.sh [options] + +Update the checkout and deploy Scene Search. + +Default sequence: + 1. git pull --ff-only + 2. build the Jellyfin plugin DLL + 3. rebuild/start Docker services + 4. install the DLL and restart Jellyfin + 5. show status + +Options: + --no-pull Skip git pull (useful immediately after you already pulled). + --skip-plugin Do not build/install/restart the Jellyfin plugin. + --skip-docker Do not rebuild/restart Docker. +EOF + exit 0 + ;; + *) die "Unknown option: $1" ;; + esac + shift +done + +if ! "$no_pull"; then + need git + if [[ -n "$(git status --porcelain)" ]]; then + die "Working tree is not clean. Commit/stash local changes, or use --no-pull." + fi + + banner "Updating repository" + git pull --ff-only +fi + +if ! "$skip_plugin"; then + "$SCRIPT_DIR/plugin-rebuild.sh" --build-only +fi + +if ! "$skip_docker"; then + "$SCRIPT_DIR/docker-rebuild.sh" +fi + +if ! "$skip_plugin"; then + "$SCRIPT_DIR/plugin-rebuild.sh" --install-only +fi + +"$SCRIPT_DIR/status.sh"