#!/usr/bin/env bash set -euo pipefail loader_src="/Requests/Assets/nav-loader.js" marker_start="" marker_end="" usage() { cat <&2 usage echo "Pass the path explicitly, for example:" >&2 echo " sudo bash scripts/install-web-loader.sh /usr/share/jellyfin/web/index.html" >&2 exit 1 fi if [ ! -w "$index_path" ]; then echo "Cannot write to $index_path. Run this script with sudo or fix permissions." >&2 exit 1 fi if grep -Fq "$loader_src" "$index_path"; then echo "Request web loader is already installed in $index_path" exit 0 fi backup_path="${index_path}.bak.request.$(date -u +%Y%m%d%H%M%S)" cp -p "$index_path" "$backup_path" tmp_path="$(mktemp)" block="${marker_start} ${marker_end}" awk -v block="$block" ' BEGIN { inserted = 0 } /<\/body>/ && inserted == 0 { print block inserted = 1 } { print } END { if (inserted == 0) { print block } } ' "$index_path" > "$tmp_path" cat "$tmp_path" > "$index_path" rm -f "$tmp_path" echo "Installed Request web loader in $index_path" echo "Backup saved to $backup_path" echo "Restart Jellyfin, then hard refresh the browser."