Created
April 19, 2026 13:18
-
-
Save iwconfig/5a0e7602bff36a88a6e7cae76a9a0447 to your computer and use it in GitHub Desktop.
manage a singleton firefox instance in e.g. a container with wayland support. this wrapper ensures that opening new URLs via the terminal or `xdg-open` correctly communicates with the existing firefox process instead of failing with the "Firefox is already running" error. It uses `dpkg-divert` to remain persistent across package updates and ensu…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash -e | |
| # firefox singleton installer for e.g. containers | |
| # diverts original binary and installs a dbus aware wrapper | |
| FIREFOX_BIN="/usr/lib/firefox/firefox" | |
| FIREFOX_BIN_REAL="${FIREFOX_BIN}.real" | |
| if ! command -v dbus-launch >/dev/null; then | |
| apt update && apt install dbus-x11 -y | |
| fi | |
| if [ -f "$FIREFOX_BIN" ] && ! dpkg-divert --list | grep -q "$FIREFOX_BIN_REAL"; then | |
| dpkg-divert --package local --add --rename --divert "$FIREFOX_BIN_REAL" "$FIREFOX_BIN" | |
| fi | |
| cat <<EOF > "$FIREFOX_BIN" | |
| #!/bin/sh | |
| DBUS_ENV=/tmp/.dbus-session-env | |
| if pgrep -x dbus-daemon > /dev/null && [ -f "\$DBUS_ENV" ]; then | |
| . "\$DBUS_ENV" | |
| else | |
| eval \$(dbus-launch --sh-syntax | tee "\$DBUS_ENV") | |
| fi | |
| export MOZ_DBUS_REMOTE=1 | |
| export MOZ_ENABLE_WAYLAND=1 | |
| exec "$FIREFOX_BIN_REAL" "\$@" | |
| EOF | |
| chmod +x "$FIREFOX_BIN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment