cd486f
#!/bin/bash
cd486f
#
cd486f
# The contents of this file are subject to the Netscape Public
cd486f
# License Version 1.1 (the "License"); you may not use this file
cd486f
# except in compliance with the License. You may obtain a copy of
cd486f
# the License at http://www.mozilla.org/NPL/
cd486f
#
cd486f
# Software distributed under the License is distributed on an "AS
cd486f
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
cd486f
# implied. See the License for the specific language governing
cd486f
# rights and limitations under the License.
cd486f
#
cd486f
# The Original Code is mozilla.org code.
cd486f
#
cd486f
# The Initial Developer of the Original Code is Netscape
cd486f
# Communications Corporation.  Portions created by Netscape are
cd486f
# Copyright (C) 1998 Netscape Communications Corporation. All
cd486f
# Rights Reserved.
cd486f
#
cd486f
# Contributor(s): 
cd486f
#
cd486f
cd486f
## 
cd486f
## Usage:
cd486f
##
cd486f
## $ firefox
cd486f
##
cd486f
## This script is meant to run a mozilla program from the mozilla
cd486f
## rpm installation.
cd486f
##
cd486f
## The script will setup all the environment voodoo needed to make
cd486f
## mozilla work.
cd486f
cd486f
cmdname=`basename $0`
cd486f
cd486f
##
cd486f
## Variables
cd486f
##
cd486f
MOZ_ARCH=$(uname -m)
cd486f
case $MOZ_ARCH in
cd486f
	x86_64 | s390x | sparc64)
cd486f
		MOZ_LIB_DIR="/usr/lib64"
cd486f
		SECONDARY_LIB_DIR="/usr/lib"
cd486f
		;;
cd486f
	* )
cd486f
		MOZ_LIB_DIR="/usr/lib"
cd486f
		SECONDARY_LIB_DIR="/usr/lib64"
cd486f
		;;
cd486f
esac
cd486f
cd486f
MOZ_FIREFOX_FILE="firefox"
cd486f
cd486f
if [ ! -r $MOZ_LIB_DIR/firefox/$MOZ_FIREFOX_FILE ]; then
cd486f
    if [ ! -r $SECONDARY_LIB_DIR/firefox/$MOZ_FIREFOX_FILE ]; then
cd486f
	echo "Error: $MOZ_LIB_DIR/firefox/$MOZ_FIREFOX_FILE not found"
cd486f
	if [ -d $SECONDARY_LIB_DIR ]; then
cd486f
	    echo "       $SECONDARY_LIB_DIR/firefox/$MOZ_FIREFOX_FILE not found"
cd486f
	fi
cd486f
	exit 1
cd486f
    fi
cd486f
    MOZ_LIB_DIR="$SECONDARY_LIB_DIR"
cd486f
fi
cd486f
MOZ_DIST_BIN="$MOZ_LIB_DIR/firefox"
cd486f
MOZ_LANGPACKS_DIR="$MOZ_DIST_BIN/langpacks"
cd486f
MOZ_EXTENSIONS_PROFILE_DIR="$HOME/.mozilla/extensions/{ec8030f7-c20a-464f-9b0e-13a3a9e97384}"
cd486f
MOZ_PROGRAM="$MOZ_DIST_BIN/$MOZ_FIREFOX_FILE"
cd486f
MOZ_LAUNCHER="$MOZ_DIST_BIN/run-mozilla.sh"
cd486f
cd486f
##
cd486f
## Set MOZ_GRE_CONF
cd486f
##
cd486f
MOZ_GRE_CONF=/etc/gre.d/gre.conf
cd486f
if [ "$MOZ_LIB_DIR" == "/usr/lib64" ]; then
cd486f
  MOZ_GRE_CONF=/etc/gre.d/gre64.conf
cd486f
fi
cd486f
export MOZ_GRE_CONF
cd486f
cd486f
##
cd486f
## Set MOZILLA_FIVE_HOME
cd486f
##
cd486f
MOZILLA_FIVE_HOME="$MOZ_DIST_BIN"
cd486f
cd486f
export MOZILLA_FIVE_HOME
cd486f
cd486f
##
cd486f
## Make sure that we set the plugin path
cd486f
##
cd486f
MOZ_PLUGIN_DIR="plugins"
cd486f
cd486f
if [ "$MOZ_PLUGIN_PATH" ]
cd486f
then
cd486f
  MOZ_PLUGIN_PATH=$MOZ_PLUGIN_PATH:$MOZ_LIB_DIR/mozilla/$MOZ_PLUGIN_DIR:$MOZ_DIST_BIN/$MOZ_PLUGIN_DIR
cd486f
else
cd486f
  MOZ_PLUGIN_PATH=$MOZ_LIB_DIR/mozilla/$MOZ_PLUGIN_DIR:$MOZ_DIST_BIN/$MOZ_PLUGIN_DIR
cd486f
fi
cd486f
export MOZ_PLUGIN_PATH
cd486f
cd486f
##
cd486f
## Set MOZ_APP_LAUNCHER for gnome-session
cd486f
##
cd486f
export MOZ_APP_LAUNCHER="/usr/bin/firefox"
cd486f
cd486f
##
cd486f
## Set FONTCONFIG_PATH for Xft/fontconfig
cd486f
##
cd486f
FONTCONFIG_PATH="/etc/fonts:${MOZILLA_FIVE_HOME}/res/Xft"
cd486f
export FONTCONFIG_PATH
cd486f
cd486f
##
cd486f
## In order to better support certain scripts (such as Indic and some CJK 
cd486f
## scripts), Fedora builds its Firefox, with permission from the Mozilla 
cd486f
## Corporation, with the Pango system as its text renderer.  This change 
cd486f
## may negatively impact performance on some pages.  To disable the use of
cd486f
## Pango, set MOZ_DISABLE_PANGO=1 in your environment before launching
cd486f
## Firefox.
cd486f
##
cd486f
#
cd486f
# MOZ_DISABLE_PANGO=1
cd486f
# export MOZ_DISABLE_PANGO
cd486f
#
cd486f
cd486f
##
cd486f
## Disable the GNOME crash dialog, Moz has it's own
cd486f
##
cd486f
GNOME_DISABLE_CRASH_DIALOG=1
cd486f
export GNOME_DISABLE_CRASH_DIALOG
cd486f
cd486f
##
cd486f
## Disable the SLICE allocator (rhbz#1014858)
cd486f
##
cd486f
export G_SLICE=always-malloc
cd486f
cd486f
##
cd486f
## Enable Xinput2 (mozbz#1207973)
cd486f
##
cd486f
export MOZ_USE_XINPUT2=1
cd486f
cd486f
# OK, here's where all the real work gets done
cd486f
cd486f
cd486f
##
cd486f
## To disable the use of Firefox localization, set MOZ_DISABLE_LANGPACKS=1
cd486f
## in your environment before launching Firefox.
cd486f
##
cd486f
#
cd486f
# MOZ_DISABLE_LANGPACKS=1
cd486f
# export MOZ_DISABLE_LANGPACKS
cd486f
#
cd486f
cd486f
##
cd486f
## Automatically installed langpacks are tracked by .fedora-langpack-install
cd486f
## config file.
cd486f
##
cd486f
FEDORA_LANGPACK_CONFIG="$MOZ_EXTENSIONS_PROFILE_DIR/.fedora-langpack-install"
cd486f
cd486f
# Since Firefox 60 the installation of individual langpack cannot be done by
cd486f
# copying xpi file to the home directory, because the langpack is loaded
cd486f
# as to the available languages after the language has been decided and
cd486f
# for the first run it won't be in language according to the locale.
cd486f
#
cd486f
# The current workaround is to put all langpacks to the location
cd486f
# for system wide extensions. So we set MOZ_DISABLE_LANGPACKS=1 for this moment
cd486f
export MOZ_DISABLE_LANGPACKS=1
cd486f
# MOZ_DISABLE_LANGPACKS disables language packs completely
cd486f
MOZILLA_DOWN=0
cd486f
if ! [ $MOZ_DISABLE_LANGPACKS ] || [ $MOZ_DISABLE_LANGPACKS -eq 0 ]; then
cd486f
    if [ -x $MOZ_DIST_BIN/$MOZ_FIREFOX_FILE ]; then
cd486f
        # Is firefox running?
cd486f
        /usr/bin/pidof firefox > /dev/null 2>&1
cd486f
        MOZILLA_DOWN=$?
cd486f
    fi
cd486f
fi
cd486f
cd486f
# Modify language pack configuration only when firefox is not running 
cd486f
# and language packs are not disabled
cd486f
if [ $MOZILLA_DOWN -ne 0 ]; then
cd486f
cd486f
    # Clear already installed langpacks
cd486f
    mkdir -p $MOZ_EXTENSIONS_PROFILE_DIR
cd486f
    if [ -f $FEDORA_LANGPACK_CONFIG ]; then
cd486f
        rm `cat $FEDORA_LANGPACK_CONFIG` > /dev/null 2>&1
cd486f
        rm $FEDORA_LANGPACK_CONFIG > /dev/null 2>&1
cd486f
        # remove all empty langpacks dirs while they block installation of langpacks
cd486f
        rmdir $MOZ_EXTENSIONS_PROFILE_DIR/langpack* > /dev/null 2>&1
cd486f
    fi
cd486f
cd486f
    # Get locale from system
cd486f
    CURRENT_LOCALE=$LC_ALL
cd486f
    CURRENT_LOCALE=${CURRENT_LOCALE:-$LC_MESSAGES}
cd486f
    CURRENT_LOCALE=${CURRENT_LOCALE:-$LANG}
cd486f
cd486f
    # Try with a local variant first, then without a local variant
cd486f
    SHORTMOZLOCALE=`echo $CURRENT_LOCALE | sed "s|_\([^.]*\).*||g"`
cd486f
    MOZLOCALE=`echo $CURRENT_LOCALE | sed "s|_\([^.]*\).*|-\1|g"`
cd486f
cd486f
    function create_langpack_link() {
cd486f
        local language=$*
cd486f
        local langpack=langpack-${language}@firefox.mozilla.org.xpi
cd486f
        if [ -f $MOZ_LANGPACKS_DIR/$langpack ]; then
cd486f
            rm -rf $MOZ_EXTENSIONS_PROFILE_DIR/$langpack
cd486f
            # If the target file is a symlink (the fallback langpack), 
cd486f
            # install the original file instead of the fallback one
cd486f
            if [ -h $MOZ_LANGPACKS_DIR/$langpack ]; then
cd486f
                langpack=`readlink $MOZ_LANGPACKS_DIR/$langpack`
cd486f
            fi
cd486f
            ln -s $MOZ_LANGPACKS_DIR/$langpack \
cd486f
                  $MOZ_EXTENSIONS_PROFILE_DIR/$langpack
cd486f
            echo $MOZ_EXTENSIONS_PROFILE_DIR/$langpack > $FEDORA_LANGPACK_CONFIG
cd486f
            return 0
cd486f
        fi
cd486f
        return 1
cd486f
    }
cd486f
cd486f
    create_langpack_link $MOZLOCALE || create_langpack_link $SHORTMOZLOCALE || true
cd486f
fi
cd486f
cd486f
# BEAST fix (rhbz#1005611)
cd486f
NSS_SSL_CBC_RANDOM_IV=${NSS_SSL_CBC_RANDOM_IV-1}
cd486f
export NSS_SSL_CBC_RANDOM_IV
cd486f
cd486f
# Prepare command line arguments
cd486f
script_args=""
cd486f
pass_arg_count=0
cd486f
while [ $# -gt $pass_arg_count ]
cd486f
do
cd486f
  case "$1" in
cd486f
    -g | --debug)
cd486f
      script_args="$script_args -g"
cd486f
      debugging=1
cd486f
      shift
cd486f
      ;;
cd486f
    -d | --debugger)
cd486f
      if [ $# -gt 1 ]; then
cd486f
        script_args="$script_args -d $2"
cd486f
        shift 2
cd486f
      else
cd486f
        shift
cd486f
      fi
cd486f
      ;;
cd486f
    *)
cd486f
      # Move the unrecognized argument to the end of the list.
cd486f
      arg="$1"
cd486f
      shift
cd486f
      set -- "$@" "$arg"
cd486f
      pass_arg_count=`expr $pass_arg_count + 1`
cd486f
      ;;
cd486f
  esac
cd486f
done
cd486f
cd486f
# Linux version specific environment variables
cd486f
%RHEL_ENV_VARS%
cd486f
98fa6e
# Don't throw "old profile" dialog box.
98fa6e
export MOZ_ALLOW_DOWNGRADE=1
98fa6e
cd486f
# Make sure at-spi-bus is running
cd486f
if ! dbus-send --session            \
cd486f
     --dest=org.freedesktop.DBus    \
cd486f
     --type=method_call             \
cd486f
     --print-reply                  \
cd486f
     /org/freedesktop/DBus          \
cd486f
     org.freedesktop.DBus.ListNames \
cd486f
     | grep org.a11y.Bus > /dev/null; then
cd486f
    if [ -f "$MOZ_LIB_DIR/firefox/bundled/libexec/at-spi-bus-launcher" ]; then
cd486f
        echo "Starting a11y dbus service..."
cd486f
        $MOZ_LIB_DIR/firefox/bundled/libexec/at-spi-bus-launcher &
cd486f
    else
cd486f
        echo "Running without a11y support!"
cd486f
    fi
cd486f
fi
cd486f
cd486f
# Run the browser
cd486f
debugging=0
cd486f
if [ $debugging = 1 ]
cd486f
then
cd486f
  echo $MOZ_LAUNCHER $script_args $MOZ_PROGRAM "$@"
cd486f
fi
cd486f
cd486f
cd486f
exec $MOZ_LAUNCHER $script_args $MOZ_PROGRAM "$@"