adjustments_bluray/scripts/run-vlc.sh

71 lines
2.7 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
MISE_BIN="${MISE_BIN:-$HOME/.local/bin/mise}"
# Default to the on-disk BDMV folder; pass an explicit path to override (a
# folder or an .iso). The folder is just the simpler preview target -- a real
# player reads the JAR from the ISO's disc filesystem directly.
TARGET="${1:-$ROOT_DIR/build/disc}"
if [[ -d "$TARGET" && ! -d "$TARGET/BDMV" ]]; then
echo "Not a BDMV folder (no BDMV/ inside): $TARGET" >&2
echo "Run: make" >&2
exit 1
fi
if [[ ! -e "$TARGET" ]]; then
echo "Missing disc target: $TARGET" >&2
echo "Run: make" >&2
exit 1
fi
if [[ -x "$MISE_BIN" ]]; then
JDK8_HOME="$("$MISE_BIN" where java@temurin-8.0.502+7 2>/dev/null || true)"
else
JDK8_HOME=""
fi
if [[ -z "$JDK8_HOME" && -d "$ROOT_DIR/vendor/bdj-sdk/host/jdk8" ]]; then
JDK8_HOME="$(cd "$ROOT_DIR/vendor/bdj-sdk/host/jdk8" && pwd)"
fi
if [[ -n "$JDK8_HOME" ]]; then
export JAVA_HOME="$JDK8_HOME/jre"
export JDK_HOME="$JDK8_HOME"
export LD_LIBRARY_PATH="$JDK8_HOME/jre/lib/amd64/server:${LD_LIBRARY_PATH:-}"
fi
# Note: no VLC_PLUGIN_PATH juggling. This system's VLC already ships the bluray
# access plugin (/usr/lib/vlc/plugins/access/liblibbluray_plugin.so); the old
# tools/vlc-plugins copy was only needed for split-package installs that lack it.
# Give libbluray writable BD-J storage roots, and -- the important part -- put
# the BD-J VFS cache *under* the cache (BUDA) root.
#
# libbluray copies the disc's JAR and fonts into a VFS cache under java.io.tmpdir
# (default /tmp/libbluray-bdj-cache). Its BD-J SecurityManager.canWrite() checks
# roots in this order: budaRoot -> persistentRoot -> (if an Xlet context is
# active: DENY) -> cacheRoot. That extraction often runs while an Xlet context is
# live on the thread, so the write is denied before the cacheRoot allowance is
# ever reached -- the flaky "error creating .../libbluray-bdj-cache" /
# "failed to create temporary cache directory" cascade that stops the Xlet (menu)
# from loading. budaRoot/persistentRoot are allowed unconditionally, so pointing
# TMPDIR (== java.io.tmpdir == the VFS cache's base) at the buda root makes the
# cache path start with budaRoot and always pass the write check.
BDJ_RUN_DIR="$ROOT_DIR/build/bdj-runtime"
export LIBBLURAY_CACHE_ROOT="$BDJ_RUN_DIR/cache"
export LIBBLURAY_PERSISTENT_ROOT="$BDJ_RUN_DIR/persistent"
export TMPDIR="$LIBBLURAY_CACHE_ROOT"
mkdir -p "$LIBBLURAY_CACHE_ROOT" "$LIBBLURAY_PERSISTENT_ROOT"
# start each preview from a clean VFS cache
rm -rf "$LIBBLURAY_CACHE_ROOT/libbluray-bdj-cache"
if [[ -d "$TARGET" ]]; then
ABS_TARGET="$(cd "$TARGET" && pwd)"
else
ABS_TARGET="$(cd "$(dirname "$TARGET")" && pwd)/$(basename "$TARGET")"
fi
exec vlc --bluray-menu "bluray://$ABS_TARGET"