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