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