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