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