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