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