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