cbe2c5
#!/usr/bin/bash
71c2a1
#
71c2a1
# The contents of this file are subject to the Netscape Public
71c2a1
# License Version 1.1 (the "License"); you may not use this file
71c2a1
# except in compliance with the License. You may obtain a copy of
71c2a1
# the License at http://www.mozilla.org/NPL/
71c2a1
#
71c2a1
# Software distributed under the License is distributed on an "AS
71c2a1
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
71c2a1
# implied. See the License for the specific language governing
71c2a1
# rights and limitations under the License.
71c2a1
#
71c2a1
# The Original Code is mozilla.org code.
71c2a1
#
71c2a1
# The Initial Developer of the Original Code is Netscape
71c2a1
# Communications Corporation.  Portions created by Netscape are
71c2a1
# Copyright (C) 1998 Netscape Communications Corporation. All
71c2a1
# Rights Reserved.
71c2a1
#
71c2a1
# Contributor(s): 
71c2a1
#
71c2a1
71c2a1
## 
71c2a1
## Usage:
71c2a1
##
71c2a1
## $ firefox
71c2a1
##
71c2a1
## This script is meant to run a mozilla program from the mozilla
71c2a1
## rpm installation.
71c2a1
##
71c2a1
## The script will setup all the environment voodoo needed to make
71c2a1
## mozilla work.
71c2a1
71c2a1
cmdname=`basename $0`
71c2a1
71c2a1
##
71c2a1
## Variables
71c2a1
##
71c2a1
MOZ_ARCH=$(uname -m)
71c2a1
case $MOZ_ARCH in
71c2a1
	x86_64 | s390x | sparc64)
cbe2c5
		MOZ_LIB_DIR="/__PREFIX__/lib64"
cbe2c5
		SECONDARY_LIB_DIR="/__PREFIX__/lib"
71c2a1
		;;
71c2a1
	* )
cbe2c5
		MOZ_LIB_DIR="/__PREFIX__/lib"
cbe2c5
		SECONDARY_LIB_DIR="/__PREFIX__/lib64"
71c2a1
		;;
71c2a1
esac
71c2a1
71c2a1
MOZ_FIREFOX_FILE="firefox"
71c2a1
71c2a1
if [ ! -r $MOZ_LIB_DIR/firefox/$MOZ_FIREFOX_FILE ]; then
71c2a1
    if [ ! -r $SECONDARY_LIB_DIR/firefox/$MOZ_FIREFOX_FILE ]; then
71c2a1
	echo "Error: $MOZ_LIB_DIR/firefox/$MOZ_FIREFOX_FILE not found"
71c2a1
	if [ -d $SECONDARY_LIB_DIR ]; then
71c2a1
	    echo "       $SECONDARY_LIB_DIR/firefox/$MOZ_FIREFOX_FILE not found"
71c2a1
	fi
71c2a1
	exit 1
71c2a1
    fi
71c2a1
    MOZ_LIB_DIR="$SECONDARY_LIB_DIR"
71c2a1
fi
71c2a1
MOZ_DIST_BIN="$MOZ_LIB_DIR/firefox"
cbe2c5
MOZ_LANGPACKS_DIR="$MOZ_DIST_BIN/langpacks"
cbe2c5
MOZ_EXTENSIONS_PROFILE_DIR="$HOME/.mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
71c2a1
MOZ_PROGRAM="$MOZ_DIST_BIN/$MOZ_FIREFOX_FILE"
71c2a1
MOZ_LAUNCHER="$MOZ_DIST_BIN/run-mozilla.sh"
cbe2c5
GETENFORCE_FILE="/usr/sbin/getenforce"
cbe2c5
cbe2c5
##
cbe2c5
## Enable Wayland backend?
cbe2c5
##
cbe2c5
%DISABLE_WAYLAND_PLACEHOLDER%
cbe2c5
cbe2c5
if ! [ $MOZ_DISABLE_WAYLAND ] && [ "$WAYLAND_DISPLAY" ]; then
cbe2c5
  if [ "$XDG_CURRENT_DESKTOP" == "GNOME" ]; then
cbe2c5
    export MOZ_ENABLE_WAYLAND=1
cbe2c5
  fi
cbe2c5
##  Enable Wayland on KDE/Sway
cbe2c5
##
cbe2c5
  if [ "$XDG_SESSION_TYPE" == "wayland" ]; then
cbe2c5
    export MOZ_ENABLE_WAYLAND=1
cbe2c5
  fi
cbe2c5
fi
cbe2c5
cbe2c5
##
cbe2c5
## Use D-Bus remote exclusively when there's Wayland display.
cbe2c5
##
cbe2c5
if [ "$WAYLAND_DISPLAY" ]; then
cbe2c5
  export MOZ_DBUS_REMOTE=1
cbe2c5
fi
71c2a1
71c2a1
##
71c2a1
## Set MOZ_GRE_CONF
71c2a1
##
71c2a1
MOZ_GRE_CONF=/etc/gre.d/gre.conf
cbe2c5
if [ "$MOZ_LIB_DIR" == "/__PREFIX__/lib64" ]; then
71c2a1
  MOZ_GRE_CONF=/etc/gre.d/gre64.conf
71c2a1
fi
71c2a1
export MOZ_GRE_CONF
71c2a1
71c2a1
##
71c2a1
## Set MOZILLA_FIVE_HOME
71c2a1
##
71c2a1
MOZILLA_FIVE_HOME="$MOZ_DIST_BIN"
71c2a1
71c2a1
export MOZILLA_FIVE_HOME
71c2a1
71c2a1
##
71c2a1
## Make sure that we set the plugin path
71c2a1
##
71c2a1
MOZ_PLUGIN_DIR="plugins"
71c2a1
71c2a1
if [ "$MOZ_PLUGIN_PATH" ]
71c2a1
then
71c2a1
  MOZ_PLUGIN_PATH=$MOZ_PLUGIN_PATH:$MOZ_LIB_DIR/mozilla/$MOZ_PLUGIN_DIR:$MOZ_DIST_BIN/$MOZ_PLUGIN_DIR
71c2a1
else
71c2a1
  MOZ_PLUGIN_PATH=$MOZ_LIB_DIR/mozilla/$MOZ_PLUGIN_DIR:$MOZ_DIST_BIN/$MOZ_PLUGIN_DIR
71c2a1
fi
71c2a1
export MOZ_PLUGIN_PATH
71c2a1
71c2a1
##
71c2a1
## Set MOZ_APP_LAUNCHER for gnome-session
71c2a1
##
cbe2c5
export MOZ_APP_LAUNCHER="/__PREFIX__/bin/firefox"
cbe2c5
cbe2c5
##
cbe2c5
## Set FONTCONFIG_PATH for Xft/fontconfig
cbe2c5
##
cbe2c5
FONTCONFIG_PATH="/etc/fonts:${MOZILLA_FIVE_HOME}/res/Xft"
cbe2c5
export FONTCONFIG_PATH
cbe2c5
cbe2c5
##
cbe2c5
## We want Firefox to use Openh264 provided by Fedora
cbe2c5
##
cbe2c5
export MOZ_GMP_PATH=$MOZ_LIB_DIR/mozilla/plugins/gmp-gmpopenh264/system-installed
71c2a1
71c2a1
##
71c2a1
## In order to better support certain scripts (such as Indic and some CJK 
71c2a1
## scripts), Fedora builds its Firefox, with permission from the Mozilla 
71c2a1
## Corporation, with the Pango system as its text renderer.  This change 
71c2a1
## may negatively impact performance on some pages.  To disable the use of
71c2a1
## Pango, set MOZ_DISABLE_PANGO=1 in your environment before launching
71c2a1
## Firefox.
71c2a1
##
71c2a1
#
71c2a1
# MOZ_DISABLE_PANGO=1
71c2a1
# export MOZ_DISABLE_PANGO
71c2a1
#
71c2a1
71c2a1
##
71c2a1
## Disable the GNOME crash dialog, Moz has it's own
71c2a1
##
71c2a1
GNOME_DISABLE_CRASH_DIALOG=1
71c2a1
export GNOME_DISABLE_CRASH_DIALOG
71c2a1
71c2a1
##
71c2a1
## Disable the SLICE allocator (rhbz#1014858)
71c2a1
##
71c2a1
export G_SLICE=always-malloc
71c2a1
71c2a1
##
71c2a1
## Enable Xinput2 (mozbz#1207973)
71c2a1
##
71c2a1
export MOZ_USE_XINPUT2=1
71c2a1
cbe2c5
# OK, here's where all the real work gets done
cbe2c5
cbe2c5
cbe2c5
##
cbe2c5
## To disable the use of Firefox localization, set MOZ_DISABLE_LANGPACKS=1
cbe2c5
## in your environment before launching Firefox.
cbe2c5
##
cbe2c5
#
cbe2c5
# MOZ_DISABLE_LANGPACKS=1
cbe2c5
# export MOZ_DISABLE_LANGPACKS
cbe2c5
#
cbe2c5
cbe2c5
##
cbe2c5
## Automatically installed langpacks are tracked by .fedora-langpack-install
cbe2c5
## config file.
cbe2c5
##
cbe2c5
FEDORA_LANGPACK_CONFIG="$MOZ_EXTENSIONS_PROFILE_DIR/.fedora-langpack-install"
cbe2c5
cbe2c5
# MOZ_DISABLE_LANGPACKS disables language packs completely
cbe2c5
MOZILLA_DOWN=0
cbe2c5
if ! [ $MOZ_DISABLE_LANGPACKS ] || [ $MOZ_DISABLE_LANGPACKS -eq 0 ]; then
cbe2c5
    if [ -x $MOZ_DIST_BIN/$MOZ_FIREFOX_FILE ]; then
cbe2c5
        # Is firefox running?
cbe2c5
        /__PREFIX__/bin/pidof $MOZ_PROGRAM > /dev/null 2>&1
cbe2c5
        MOZILLA_DOWN=$?
cbe2c5
    fi
cbe2c5
fi
cbe2c5
cbe2c5
# When Firefox is not running, restore SELinux labels for profile files
cbe2c5
# (rhbz#1731371)
cbe2c5
if [ $MOZILLA_DOWN -ne 0 ]; then
cbe2c5
  if [ -x $GETENFORCE_FILE ] && [ `getenforce` != "Disabled" ]; then
cbe2c5
    (restorecon -vr ~/.mozilla/firefox/* &)
cbe2c5
  fi
cbe2c5
fi
cbe2c5
cbe2c5
# Modify language pack configuration only when firefox is not running 
cbe2c5
# and language packs are not disabled
cbe2c5
if [ $MOZILLA_DOWN -ne 0 ]; then
cbe2c5
cbe2c5
    # Clear already installed langpacks
cbe2c5
    mkdir -p $MOZ_EXTENSIONS_PROFILE_DIR
cbe2c5
    if [ -f $FEDORA_LANGPACK_CONFIG ]; then
cbe2c5
        rm `cat $FEDORA_LANGPACK_CONFIG` > /dev/null 2>&1
cbe2c5
        rm $FEDORA_LANGPACK_CONFIG > /dev/null 2>&1
cbe2c5
        # remove all empty langpacks dirs while they block installation of langpacks
cbe2c5
        rmdir $MOZ_EXTENSIONS_PROFILE_DIR/langpack* > /dev/null 2>&1
cbe2c5
    fi
cbe2c5
cbe2c5
    # Get locale from system
cbe2c5
    CURRENT_LOCALE=$LC_ALL
cbe2c5
    CURRENT_LOCALE=${CURRENT_LOCALE:-$LC_MESSAGES}
cbe2c5
    CURRENT_LOCALE=${CURRENT_LOCALE:-$LANG}
cbe2c5
cbe2c5
    # Try with a local variant first, then without a local variant
cbe2c5
    SHORTMOZLOCALE=`echo $CURRENT_LOCALE | sed "s|_\([^.]*\).*||g" | sed "s|\..*||g"`
cbe2c5
    MOZLOCALE=`echo $CURRENT_LOCALE | sed "s|_\([^.]*\).*|-\1|g" | sed "s|\..*||g"`
cbe2c5
cbe2c5
    function create_langpack_link() {
cbe2c5
        local language=$*
cbe2c5
        local langpack=langpack-${language}@firefox.mozilla.org.xpi
cbe2c5
        if [ -f $MOZ_LANGPACKS_DIR/$langpack ]; then
cbe2c5
            rm -rf $MOZ_EXTENSIONS_PROFILE_DIR/$langpack
cbe2c5
            # If the target file is a symlink (the fallback langpack), 
cbe2c5
            # install the original file instead of the fallback one
cbe2c5
            if [ -h $MOZ_LANGPACKS_DIR/$langpack ]; then
cbe2c5
                langpack=`readlink $MOZ_LANGPACKS_DIR/$langpack`
cbe2c5
            fi
cbe2c5
            ln -s $MOZ_LANGPACKS_DIR/$langpack \
cbe2c5
                  $MOZ_EXTENSIONS_PROFILE_DIR/$langpack
cbe2c5
            echo $MOZ_EXTENSIONS_PROFILE_DIR/$langpack > $FEDORA_LANGPACK_CONFIG
cbe2c5
            return 0
cbe2c5
        fi
cbe2c5
        return 1
cbe2c5
    }
cbe2c5
cbe2c5
    create_langpack_link $MOZLOCALE || create_langpack_link $SHORTMOZLOCALE || true
cbe2c5
fi
cbe2c5
71c2a1
# BEAST fix (rhbz#1005611)
71c2a1
NSS_SSL_CBC_RANDOM_IV=${NSS_SSL_CBC_RANDOM_IV-1}
71c2a1
export NSS_SSL_CBC_RANDOM_IV
71c2a1
71c2a1
# Prepare command line arguments
71c2a1
script_args=""
71c2a1
pass_arg_count=0
71c2a1
while [ $# -gt $pass_arg_count ]
71c2a1
do
71c2a1
  case "$1" in
71c2a1
    -g | --debug)
71c2a1
      script_args="$script_args -g"
71c2a1
      debugging=1
71c2a1
      shift
71c2a1
      ;;
71c2a1
    -d | --debugger)
71c2a1
      if [ $# -gt 1 ]; then
71c2a1
        script_args="$script_args -d $2"
71c2a1
        shift 2
71c2a1
      else
71c2a1
        shift
71c2a1
      fi
71c2a1
      ;;
71c2a1
    *)
71c2a1
      # Move the unrecognized argument to the end of the list.
71c2a1
      arg="$1"
71c2a1
      shift
71c2a1
      set -- "$@" "$arg"
71c2a1
      pass_arg_count=`expr $pass_arg_count + 1`
71c2a1
      ;;
71c2a1
  esac
71c2a1
done
71c2a1
cbe2c5
# Flatpak specific environment variables
cbe2c5
%FLATPAK_ENV_VARS%
71c2a1
d445b2
# Don't throw "old profile" dialog box.
d445b2
export MOZ_ALLOW_DOWNGRADE=1
d445b2
71c2a1
# Run the browser
cbe2c5
debugging=0
cbe2c5
if [ $debugging = 1 ]
cbe2c5
then
cbe2c5
  echo $MOZ_LAUNCHER $script_args $MOZ_PROGRAM "$@"
cbe2c5
fi
cbe2c5
71c2a1
exec $MOZ_LAUNCHER $script_args $MOZ_PROGRAM "$@"