From f49167d933ef33c4f02f0aa335bb91f251ba1e7f Mon Sep 17 00:00:00 2001 From: Thomas Deutschmann Date: Mon, 30 Mar 2020 01:19:57 +0200 Subject: [PATCH] www-client/firefox-bin: use wrapper This change will replace /usr/bin/firefox-bin symlink with a wrapper script: - Using a wrapper will allow us to set additional variables more easily. - The wrapper will address an issue that prevented external applications from opening links when a Firefox instance was already running. - In general, the wrapper will allow user to execute 'firefox-bin' from wherever and whenever they like without getting an error that an instance is already running. In addition, Wayland support was exposed via USE flag. Package-Manager: Portage-2.3.96, Repoman-2.3.22 Signed-off-by: Thomas Deutschmann --- .../firefox-bin/files/firefox-bin-wayland.sh | 7 + .../firefox-bin/files/firefox-bin-x11.sh | 7 + www-client/firefox-bin/files/firefox-bin.sh | 100 +++++++++++++ .../firefox-bin/firefox-bin-68.6.0-r1.ebuild | 136 +++++++++++------- .../firefox-bin/firefox-bin-74.0-r1.ebuild | 136 +++++++++++------- 5 files changed, 290 insertions(+), 96 deletions(-) create mode 100644 www-client/firefox-bin/files/firefox-bin-wayland.sh create mode 100644 www-client/firefox-bin/files/firefox-bin-x11.sh create mode 100644 www-client/firefox-bin/files/firefox-bin.sh diff --git a/www-client/firefox-bin/files/firefox-bin-wayland.sh b/www-client/firefox-bin/files/firefox-bin-wayland.sh new file mode 100644 index 000000000000..6107d5073858 --- /dev/null +++ b/www-client/firefox-bin/files/firefox-bin-wayland.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# +# Run Mozilla Firefox (bin) on Wayland +# +export MOZ_ENABLE_WAYLAND=1 +exec @PREFIX@/bin/firefox-bin "$@" diff --git a/www-client/firefox-bin/files/firefox-bin-x11.sh b/www-client/firefox-bin/files/firefox-bin-x11.sh new file mode 100644 index 000000000000..915ac2cac193 --- /dev/null +++ b/www-client/firefox-bin/files/firefox-bin-x11.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +# +# Run Mozilla Firefox (bin) on X11 +# +export MOZ_DISABLE_WAYLAND=1 +exec @PREFIX@/bin/firefox-bin "$@" diff --git a/www-client/firefox-bin/files/firefox-bin.sh b/www-client/firefox-bin/files/firefox-bin.sh new file mode 100644 index 000000000000..5bf52692b3dc --- /dev/null +++ b/www-client/firefox-bin/files/firefox-bin.sh @@ -0,0 +1,100 @@ +#!/bin/bash + +## +## Usage: +## +## $ firefox-bin +## +## This script is meant to run Mozilla Firefox in Gentoo. + +cmdname=$(basename "$0") + +## +## Variables +## +MOZ_ARCH=$(uname -m) +case ${MOZ_ARCH} in + x86_64|s390x|sparc64) + MOZ_LIB_DIR="@PREFIX@/lib64" + SECONDARY_LIB_DIR="@PREFIX@/lib" + ;; + *) + MOZ_LIB_DIR="@PREFIX@/lib" + SECONDARY_LIB_DIR="@PREFIX@/lib64" + ;; +esac + +MOZ_FIREFOX_FILE="firefox-bin" +MOZILLA_FIVE_HOME="@MOZ_FIVE_HOME@" +MOZ_EXTENSIONS_PROFILE_DIR="${HOME}/.mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}" +MOZ_PROGRAM="${MOZILLA_FIVE_HOME}/${MOZ_FIREFOX_FILE}" +APULSELIB_DIR="@APULSELIB_DIR@" +DESKTOP_FILE="firefox-bin" + +## +## Enable Wayland backend? +## +if @DEFAULT_WAYLAND@ && [[ -z ${MOZ_DISABLE_WAYLAND} ]]; then + if [[ -n "$WAYLAND_DISPLAY" ]]; then + DESKTOP_FILE="firefox-bin-wayland" + export MOZ_ENABLE_WAYLAND=1 + fi +elif [[ -n ${MOZ_DISABLE_WAYLAND} ]]; then + DESKTOP_FILE="firefox-bin-x11" +fi + +## +## Use D-Bus remote exclusively when there's Wayland display. +## +if [[ -n "${WAYLAND_DISPLAY}" ]]; then + export MOZ_DBUS_REMOTE=1 +fi + +## +## Make sure that we set the plugin path +## +MOZ_PLUGIN_DIR="plugins" + +if [[ -n "${MOZ_PLUGIN_PATH}" ]]; then + MOZ_PLUGIN_PATH=${MOZ_PLUGIN_PATH}:${MOZ_LIB_DIR}/mozilla/${MOZ_PLUGIN_DIR} +else + MOZ_PLUGIN_PATH=${MOZ_LIB_DIR}/mozilla/${MOZ_PLUGIN_DIR} +fi + +if [[ -d "${SECONDARY_LIB_DIR}/mozilla/${MOZ_PLUGIN_DIR}" ]]; then + MOZ_PLUGIN_PATH=${MOZ_PLUGIN_PATH}:${SECONDARY_LIB_DIR}/mozilla/${MOZ_PLUGIN_DIR} +fi + +export MOZ_PLUGIN_PATH + +## +## Set MOZ_APP_LAUNCHER for gnome-session +## +export MOZ_APP_LAUNCHER="@PREFIX@/bin/${cmdname}" + +## +## Disable the GNOME crash dialog, Moz has it's own +## +if [[ "$XDG_CURRENT_DESKTOP" == "GNOME" ]]; then + GNOME_DISABLE_CRASH_DIALOG=1 + export GNOME_DISABLE_CRASH_DIALOG +fi + +# Don't throw "old profile" dialog box. +export MOZ_ALLOW_DOWNGRADE=1 + +## +## Set special variables for -bin +export LD_LIBRARY_PATH="${APULSELIB_DIR:${APULSELIB_DIR}:}${MOZILLA_FIVE_HOME}" +export GTK_PATH="${MOZ_LIB_DIR}/gtk-3.0" + +## +## Route to the correct .desktop file to get proper +## names and contect menus +## +if [[ $@ != *"--name "* ]]; then + set -- "--name ${DESKTOP_FILE}" "$@" +fi + +# Run the browser +exec ${MOZ_PROGRAM} $@ diff --git a/www-client/firefox-bin/firefox-bin-68.6.0-r1.ebuild b/www-client/firefox-bin/firefox-bin-68.6.0-r1.ebuild index 340bb3612955..eb30ac30836f 100644 --- a/www-client/firefox-bin/firefox-bin-68.6.0-r1.ebuild +++ b/www-client/firefox-bin/firefox-bin-68.6.0-r1.ebuild @@ -35,7 +35,7 @@ RESTRICT="strip mirror" KEYWORDS="-* amd64 x86" SLOT="0" LICENSE="MPL-2.0 GPL-2 LGPL-2.1" -IUSE="+alsa +ffmpeg +pulseaudio selinux startup-notification" +IUSE="+alsa +ffmpeg +pulseaudio selinux startup-notification wayland" DEPEND="app-arch/unzip alsa? ( @@ -96,22 +96,47 @@ src_unpack() { } src_install() { - declare MOZILLA_FIVE_HOME=/opt/${MOZ_PN} + local MOZILLA_FIVE_HOME=/opt/${MOZ_PN} + + # Install firefox in /opt + dodir ${MOZILLA_FIVE_HOME%/*} + mv "${S}" "${ED%/}"${MOZILLA_FIVE_HOME} || die + cd "${WORKDIR}" || die + + # Install language packs + MOZEXTENSION_TARGET="distribution/extensions" \ + MOZ_INSTALL_L10N_XPIFILE="1" \ + mozlinguas_src_install + + # Disable built-in auto-update because we update firefox-bin through package manager + insinto ${MOZILLA_FIVE_HOME}/distribution/ + newins "${FILESDIR}"/disable-auto-update.policy.json policies.json + + # Fix prefs that make no sense for a system-wide install + insinto ${MOZILLA_FIVE_HOME}/defaults/pref/ + doins "${FILESDIR}"/local-settings.js + insinto ${MOZILLA_FIVE_HOME} + newins "${FILESDIR}"/all-gentoo-3.js all-gentoo.js local size sizes icon_path icon name sizes="16 32 48 128" - icon_path="${S}/browser/chrome/icons/default" + icon_path="${MOZILLA_FIVE_HOME}/browser/chrome/icons/default" icon="${PN}" - name="Mozilla Firefox" + name="Mozilla Firefox (bin)" + + local apulselib= + if use alsa && ! use pulseaudio; then + apulselib="${EPREFIX%/}/usr/$(get_libdir)/apulse" + patchelf --set-rpath "${apulselib}" "${ED%/}"${MOZILLA_FIVE_HOME}/libxul.so || die + fi # Install icons and .desktop for menu entry - for size in ${sizes}; do + for size in ${sizes} ; do insinto "/usr/share/icons/hicolor/${size}x${size}/apps" newins "${icon_path}/default${size}.png" "${icon}.png" done # Install a 48x48 icon into /usr/share/pixmaps for legacy DEs - newicon "${S}"/browser/chrome/icons/default/default48.png ${PN}.png - newmenu "${FILESDIR}/${PN}-r1.desktop" "${PN}.desktop" + newicon ${MOZILLA_FIVE_HOME}/browser/chrome/icons/default/default48.png ${PN}.png # Add StartupNotify=true bug 237317 local startup_notify="false" @@ -119,48 +144,63 @@ src_install() { startup_notify="true" fi - sed -i \ - -e "s:@NAME@:${name} (bin):" \ - -e "s:@EXEC@:firefox-bin:" \ - -e "s:@ICON@:${icon}:" \ - -e "s:@STARTUP_NOTIFY@:${startup_notify}:" \ - "${ED%/}/usr/share/applications/${PN}.desktop" || die - - # Install firefox in /opt - dodir ${MOZILLA_FIVE_HOME%/*} - mv "${S}" "${ED}"${MOZILLA_FIVE_HOME} || die - - # Disable built-in auto-update because we update firefox-bin through package manager - insinto ${MOZILLA_FIVE_HOME}/distribution/ - newins "${FILESDIR}"/disable-auto-update.policy.json policies.json - - # Fix prefs that make no sense for a system-wide install - insinto ${MOZILLA_FIVE_HOME}/defaults/pref/ - doins "${FILESDIR}"/local-settings.js - insinto ${MOZILLA_FIVE_HOME} - newins "${FILESDIR}"/all-gentoo-2.js all-gentoo.js - - # Install language packs - MOZEXTENSION_TARGET="distribution/extensions" \ - MOZ_INSTALL_L10N_XPIFILE="1" \ - mozlinguas_src_install - - if use alsa && ! use pulseaudio; then - local apulselib="/usr/$(get_libdir)/apulse" - patchelf --set-rpath "${apulselib}" "${ED}"${MOZILLA_FIVE_HOME}/libxul.so || die + local display_protocols="auto X11" use_wayland="false" + if use wayland ; then + display_protocols+=" Wayland" + use_wayland="true" fi - # Create /usr/bin/firefox-bin - dodir /usr/bin/ - local apulselib=$(usex pulseaudio "/usr/$(get_libdir)/apulse:" "") - cat <<-EOF >"${ED}"usr/bin/${PN} - #!/bin/sh - unset LD_PRELOAD - LD_LIBRARY_PATH="${apulselib}/opt/firefox/" \\ - GTK_PATH=/usr/$(get_libdir)/gtk-3.0/ \\ - exec /opt/${MOZ_PN}/${MOZ_PN} "\$@" - EOF - fperms 0755 /usr/bin/${PN} + local app_name desktop_filename display_protocol exec_command + for display_protocol in ${display_protocols} ; do + app_name="${name} on ${display_protocol}" + desktop_filename="${PN}-${display_protocol,,}.desktop" + + case ${display_protocol} in + Wayland) + exec_command="${PN}-wayland --name ${PN}-wayland" + newbin "${FILESDIR}"/firefox-bin-wayland.sh ${PN}-wayland + ;; + X11) + exec_command="${PN}-x11 --name ${PN}-x11" + if use wayland ; then + # Only needed when there's actually a choice + newbin "${FILESDIR}"/firefox-bin-x11.sh ${PN}-x11 + fi + ;; + *) + app_name="${name}" + desktop_filename="${PN}.desktop" + exec_command='firefox-bin' + ;; + esac + + newmenu "${FILESDIR}/${PN}-r1.desktop" "${desktop_filename}" + sed -i \ + -e "s:@NAME@:${app_name}:" \ + -e "s:@EXEC@:${exec_command}:" \ + -e "s:@ICON@:${icon}:" \ + -e "s:@STARTUP_NOTIFY@:${startup_notify}:" \ + "${ED%/}/usr/share/applications/${desktop_filename}" || die + done + + rm -f "${ED%/}"/usr/bin/firefox-bin || die + newbin "${FILESDIR}"/firefox-bin.sh firefox-bin + + local wrapper + for wrapper in \ + "${ED%/}"/usr/bin/firefox-bin \ + "${ED%/}"/usr/bin/firefox-bin-x11 \ + "${ED%/}"/usr/bin/firefox-bin-wayland \ + ; do + [[ ! -f "${wrapper}" ]] && continue + + sed -i \ + -e "s:@PREFIX@:${EPREFIX%/}/usr:" \ + -e "s:@MOZ_FIVE_HOME@:${MOZILLA_FIVE_HOME}:" \ + -e "s:@APULSELIB_DIR@:${apulselib}:" \ + -e "s:@DEFAULT_WAYLAND@:${use_wayland}:" \ + "${wrapper}" || die + done # revdep-rebuild entry insinto /etc/revdep-rebuild @@ -171,7 +211,7 @@ src_install() { share_plugins_dir # Required in order to use plugins and even run firefox on hardened. - pax-mark mr "${ED}"${MOZILLA_FIVE_HOME}/{firefox,firefox-bin,plugin-container} + pax-mark mr "${ED%/}"${MOZILLA_FIVE_HOME}/{firefox,firefox-bin,plugin-container} } pkg_postinst() { diff --git a/www-client/firefox-bin/firefox-bin-74.0-r1.ebuild b/www-client/firefox-bin/firefox-bin-74.0-r1.ebuild index 6182293952b4..f8f296dafd15 100644 --- a/www-client/firefox-bin/firefox-bin-74.0-r1.ebuild +++ b/www-client/firefox-bin/firefox-bin-74.0-r1.ebuild @@ -35,7 +35,7 @@ RESTRICT="strip mirror" KEYWORDS="-* amd64 x86" SLOT="0" LICENSE="MPL-2.0 GPL-2 LGPL-2.1" -IUSE="+alsa +ffmpeg +pulseaudio selinux startup-notification" +IUSE="+alsa +ffmpeg +pulseaudio selinux startup-notification wayland" DEPEND="app-arch/unzip alsa? ( @@ -96,22 +96,47 @@ src_unpack() { } src_install() { - declare MOZILLA_FIVE_HOME=/opt/${MOZ_PN} + local MOZILLA_FIVE_HOME=/opt/${MOZ_PN} + + # Install firefox in /opt + dodir ${MOZILLA_FIVE_HOME%/*} + mv "${S}" "${ED%/}"${MOZILLA_FIVE_HOME} || die + cd "${WORKDIR}" || die + + # Install language packs + MOZEXTENSION_TARGET="distribution/extensions" \ + MOZ_INSTALL_L10N_XPIFILE="1" \ + mozlinguas_src_install + + # Disable built-in auto-update because we update firefox-bin through package manager + insinto ${MOZILLA_FIVE_HOME}/distribution/ + newins "${FILESDIR}"/disable-auto-update.policy.json policies.json + + # Fix prefs that make no sense for a system-wide install + insinto ${MOZILLA_FIVE_HOME}/defaults/pref/ + doins "${FILESDIR}"/local-settings.js + insinto ${MOZILLA_FIVE_HOME} + newins "${FILESDIR}"/all-gentoo-3.js all-gentoo.js local size sizes icon_path icon name sizes="16 32 48 128" - icon_path="${S}/browser/chrome/icons/default" + icon_path="${MOZILLA_FIVE_HOME}/browser/chrome/icons/default" icon="${PN}" - name="Mozilla Firefox" + name="Mozilla Firefox (bin)" + + local apulselib= + if use alsa && ! use pulseaudio; then + apulselib="${EPREFIX%/}/usr/$(get_libdir)/apulse" + patchelf --set-rpath "${apulselib}" "${ED%/}"${MOZILLA_FIVE_HOME}/libxul.so || die + fi # Install icons and .desktop for menu entry - for size in ${sizes}; do + for size in ${sizes} ; do insinto "/usr/share/icons/hicolor/${size}x${size}/apps" newins "${icon_path}/default${size}.png" "${icon}.png" done # Install a 48x48 icon into /usr/share/pixmaps for legacy DEs - newicon "${S}"/browser/chrome/icons/default/default48.png ${PN}.png - newmenu "${FILESDIR}/${PN}-r1.desktop" "${PN}.desktop" + newicon ${MOZILLA_FIVE_HOME}/browser/chrome/icons/default/default48.png ${PN}.png # Add StartupNotify=true bug 237317 local startup_notify="false" @@ -119,48 +144,63 @@ src_install() { startup_notify="true" fi - sed -i \ - -e "s:@NAME@:${name} (bin):" \ - -e "s:@EXEC@:firefox-bin:" \ - -e "s:@ICON@:${icon}:" \ - -e "s:@STARTUP_NOTIFY@:${startup_notify}:" \ - "${ED%/}/usr/share/applications/${PN}.desktop" || die - - # Install firefox in /opt - dodir ${MOZILLA_FIVE_HOME%/*} - mv "${S}" "${ED}"${MOZILLA_FIVE_HOME} || die - - # Disable built-in auto-update because we update firefox-bin through package manager - insinto ${MOZILLA_FIVE_HOME}/distribution/ - newins "${FILESDIR}"/disable-auto-update.policy.json policies.json - - # Fix prefs that make no sense for a system-wide install - insinto ${MOZILLA_FIVE_HOME}/defaults/pref/ - doins "${FILESDIR}"/local-settings.js - insinto ${MOZILLA_FIVE_HOME} - newins "${FILESDIR}"/all-gentoo-3.js all-gentoo.js - - # Install language packs - MOZEXTENSION_TARGET="distribution/extensions" \ - MOZ_INSTALL_L10N_XPIFILE="1" \ - mozlinguas_src_install - - if use alsa && ! use pulseaudio; then - local apulselib="/usr/$(get_libdir)/apulse" - patchelf --set-rpath "${apulselib}" "${ED}"${MOZILLA_FIVE_HOME}/libxul.so || die + local display_protocols="auto X11" use_wayland="false" + if use wayland ; then + display_protocols+=" Wayland" + use_wayland="true" fi - # Create /usr/bin/firefox-bin - dodir /usr/bin/ - local apulselib=$(usex pulseaudio "" $(usex alsa "/usr/$(get_libdir)/apulse:" "")) - cat <<-EOF >"${ED}"usr/bin/${PN} - #!/bin/sh - unset LD_PRELOAD - LD_LIBRARY_PATH="${apulselib}/opt/firefox/" \\ - GTK_PATH=/usr/$(get_libdir)/gtk-3.0/ \\ - exec /opt/${MOZ_PN}/${MOZ_PN} "\$@" - EOF - fperms 0755 /usr/bin/${PN} + local app_name desktop_filename display_protocol exec_command + for display_protocol in ${display_protocols} ; do + app_name="${name} on ${display_protocol}" + desktop_filename="${PN}-${display_protocol,,}.desktop" + + case ${display_protocol} in + Wayland) + exec_command="${PN}-wayland --name ${PN}-wayland" + newbin "${FILESDIR}"/firefox-bin-wayland.sh ${PN}-wayland + ;; + X11) + exec_command="${PN}-x11 --name ${PN}-x11" + if use wayland ; then + # Only needed when there's actually a choice + newbin "${FILESDIR}"/firefox-bin-x11.sh ${PN}-x11 + fi + ;; + *) + app_name="${name}" + desktop_filename="${PN}.desktop" + exec_command='firefox-bin' + ;; + esac + + newmenu "${FILESDIR}/${PN}-r1.desktop" "${desktop_filename}" + sed -i \ + -e "s:@NAME@:${app_name}:" \ + -e "s:@EXEC@:${exec_command}:" \ + -e "s:@ICON@:${icon}:" \ + -e "s:@STARTUP_NOTIFY@:${startup_notify}:" \ + "${ED%/}/usr/share/applications/${desktop_filename}" || die + done + + rm -f "${ED%/}"/usr/bin/firefox-bin || die + newbin "${FILESDIR}"/firefox-bin.sh firefox-bin + + local wrapper + for wrapper in \ + "${ED%/}"/usr/bin/firefox-bin \ + "${ED%/}"/usr/bin/firefox-bin-x11 \ + "${ED%/}"/usr/bin/firefox-bin-wayland \ + ; do + [[ ! -f "${wrapper}" ]] && continue + + sed -i \ + -e "s:@PREFIX@:${EPREFIX%/}/usr:" \ + -e "s:@MOZ_FIVE_HOME@:${MOZILLA_FIVE_HOME}:" \ + -e "s:@APULSELIB_DIR@:${apulselib}:" \ + -e "s:@DEFAULT_WAYLAND@:${use_wayland}:" \ + "${wrapper}" || die + done # revdep-rebuild entry insinto /etc/revdep-rebuild @@ -171,7 +211,7 @@ src_install() { share_plugins_dir # Required in order to use plugins and even run firefox on hardened. - pax-mark mr "${ED}"${MOZILLA_FIVE_HOME}/{firefox,firefox-bin,plugin-container} + pax-mark mr "${ED%/}"${MOZILLA_FIVE_HOME}/{firefox,firefox-bin,plugin-container} } pkg_postinst() { -- 2.26.2