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