Files
jellyfin-customization/inject-banner.sh
T
2026-09-23 12:45:11 -07:00

57 lines
1.6 KiB
Bash
Executable File

#!/bin/bash
set -euo pipefail
CUSTOM_DIR="/srv/jellyfin/custom"
WEB_DIR="/usr/share/jellyfin/web"
SRC_JS="${CUSTOM_DIR}/banner.js"
INDEX="${WEB_DIR}/index.html"
if [[ ! -f "${SRC_JS}" ]]; then
echo "jellyfin-inject-banner: ${SRC_JS} not found, skipping." >&2
exit 0
fi
python3 - "${INDEX}" "${SRC_JS}" <<'EOF'
import sys
index_path, js_path = sys.argv[1], sys.argv[2]
with open(index_path, 'r') as f:
html = f.read()
with open(js_path, 'r') as f:
js = f.read()
# Remove any previous injection
import re
html = re.sub(r'<script id="custom-banner-script">.*?</script>', '', html, flags=re.DOTALL)
# Inject before </body>
tag = f'<script id="custom-banner-script">{js}</script>'
html = html.replace('</body>', tag + '</body>', 1)
with open(index_path, 'w') as f:
f.write(html)
print("jellyfin-inject-banner: inlined banner script into " + index_path)
EOF
# Replace the logo image(s) (filenames contain a content hash that changes on
# updates). "icon-transparent" is the top-bar logo as of the 12.x header
# redesign; "banner-light" is kept too since it's still used for the splash
# screen / PWA icons.
LOGO_SRC="${CUSTOM_DIR}/banner-light.png"
if [[ -f "${LOGO_SRC}" ]]; then
for LOGO_BASENAME in banner-light icon-transparent; do
LOGO_DEST=$(ls "${WEB_DIR}/${LOGO_BASENAME}".*.png 2>/dev/null | head -1)
if [[ -n "${LOGO_DEST}" ]]; then
cp "${LOGO_SRC}" "${LOGO_DEST}"
echo "jellyfin-inject-banner: replaced logo at ${LOGO_DEST}"
else
echo "jellyfin-inject-banner: no ${LOGO_BASENAME}.*.png found in ${WEB_DIR}, skipping." >&2
fi
done
else
echo "jellyfin-inject-banner: ${LOGO_SRC} not found, skipping logo." >&2
fi