Files
gitlab-instance-0a899031_sh/d2ypp2/services/neko/browser-launch.sh
root 07aa02bca6 s
2026-05-17 04:31:59 +00:00

83 lines
2.2 KiB
Bash

#!/bin/sh
set -eu
family="${1:-chromium}"
start_url="${NEKO_START_URL:-about:blank}"
arch="$(uname -m 2>/dev/null || echo unknown)"
prune_path() {
target="${1:-}"
[ -n "$target" ] || return 0
[ -e "$target" ] || return 0
rm -rf "$target"
}
find_bin() {
if [ "$family" = "google-chrome" ]; then
command -v google-chrome 2>/dev/null || command -v google-chrome-stable 2>/dev/null || true
else
command -v chromium 2>/dev/null || command -v chromium-browser 2>/dev/null || true
fi
}
browser_bin="$(find_bin)"
if [ -z "$browser_bin" ]; then
exit 0
fi
profile_dir="/home/neko/.config/chromium"
if [ "$family" = "google-chrome" ]; then
profile_dir="/home/neko/.config/google-chrome"
fi
render_mode="${NEKO_BROWSER_RENDER_MODE:-auto}"
render_flags="--disable-gpu --use-gl=swiftshader --enable-unsafe-swiftshader"
case "$render_mode" in
auto)
case "$arch:$family" in
x86_64:google-chrome|amd64:google-chrome)
render_flags="--disable-gpu --disable-software-rasterizer"
;;
esac
;;
gpu)
render_flags=""
;;
legacy|x11|disable-gpu)
render_flags="--disable-gpu --disable-software-rasterizer"
;;
software|swiftshader)
render_flags="--disable-gpu --use-gl=swiftshader --enable-unsafe-swiftshader"
;;
esac
mkdir -p "$profile_dir"
prune_path "$profile_dir/SingletonCookie"
prune_path "$profile_dir/SingletonLock"
prune_path "$profile_dir/SingletonSocket"
prune_path "$profile_dir/SingletonStartupLock"
prune_path "$profile_dir/BrowserMetrics"
prune_path "$profile_dir/Crash Reports"
prune_path "$profile_dir/Crashpad"
prune_path "$profile_dir/ShaderCache"
prune_path "$profile_dir/GrShaderCache"
prune_path "$profile_dir/GraphiteDawnCache"
prune_path "$profile_dir/Default/Cache"
prune_path "$profile_dir/Default/Code Cache"
prune_path "$profile_dir/Default/GPUCache"
prune_path "$profile_dir/Default/DawnGraphiteCache"
prune_path "$profile_dir/Default/DawnWebGPUCache"
exec "$browser_bin" \
${render_flags} \
--window-position=0,0 \
--display="${DISPLAY:?DISPLAY is required}" \
--user-data-dir="$profile_dir" \
--password-store=basic \
--no-first-run \
--start-maximized \
--force-dark-mode \
--disable-file-system \
--disable-dev-shm-usage \
"$start_url"