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