SmartestHome/hosts/touch-panel/configs/firefox/web-browser

35 lines
1.5 KiB
Bash
Executable File

#!/bin/sh
# Opens the general-browsing Firefox window — minimal chrome, not kiosk mode.
# Installed to /usr/local/bin/web-browser. Its own profile, separate from any other
# Firefox instance on this machine (there is only this one on the touch panel, but the
# profile is still named explicitly for the same reason hosts/thin-client keeps three
# separate ones: a Firefox profile can only be open in one process).
set -eu
PROFILE_DIR="${HOME:-/home/$(id -un)}/.mozilla/firefox/web"
if command -v firefox-esr >/dev/null 2>&1; then
FIREFOX=firefox-esr
else
FIREFOX=firefox
fi
mkdir -p "$PROFILE_DIR/chrome"
# Re-copied on every launch rather than once at build time: this is a locked-down
# profile with no interactive customisation expected, so keeping it in lockstep with
# /etc/touchpanel-firefox/ (edited by rebuilding the image) is simpler than a one-shot
# seed that could drift after a userChrome.css update.
cp /etc/touchpanel-firefox/userChrome.css "$PROFILE_DIR/chrome/userChrome.css" 2>/dev/null || true
cp /etc/touchpanel-firefox/user.js "$PROFILE_DIR/user.js" 2>/dev/null || true
# Focus an already-open window rather than stacking a second one: this window holds
# state (history, a half-typed URL, a logged-in page) that a kill-and-relaunch would
# throw away.
if pgrep -u "$(id -u)" -f "$FIREFOX .*--profile $PROFILE_DIR" >/dev/null 2>&1; then
[ -n "${1:-}" ] && exec "$FIREFOX" --profile "$PROFILE_DIR" --new-tab "$1"
exit 0
fi
exec "$FIREFOX" --profile "$PROFILE_DIR" --new-instance --new-window "${1:-about:blank}"