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