7b08d5
#!/bin/bash
7b08d5
#
7b08d5
# Startup script for the fedora.us Thunderbird RPM
7b08d5
# (based on the Mozilla RPM launch script)
7b08d5
#
7b08d5
7b08d5
##
7b08d5
## Variables
7b08d5
##
7b08d5
MOZ_ARCH=$(uname -m)
7b08d5
case $MOZ_ARCH in
7b08d5
        x86_64 | s390x | sparc64 )
7b08d5
                MOZ_LIB_DIR="/usr/lib64"
7b08d5
                SECONDARY_LIB_DIR="/usr/lib"
7b08d5
                ;;
7b08d5
        * )
7b08d5
                MOZ_LIB_DIR="/usr/lib"
7b08d5
                SECONDARY_LIB_DIR="/usr/lib64"
7b08d5
                ;;
7b08d5
esac
7b08d5
7b08d5
if [ ! -x $MOZ_LIB_DIR/thunderbird/thunderbird ]; then
7b08d5
    if [ ! -x $SECONDARY_LIB_DIR/thunderbird/thunderbird ]; then
7b08d5
        echo "Error: $MOZ_LIB_DIR/thunderbird/thunderbird not found"
7b08d5
        if [ -d $SECONDARY_LIB_DIR ]; then
7b08d5
            echo "       $SECONDARY_LIB_DIR/thunderbird/thunderbird not found"
7b08d5
        fi
7b08d5
        exit 1
7b08d5
    fi
7b08d5
    MOZ_LIB_DIR="$SECONDARY_LIB_DIR"
7b08d5
fi
7b08d5
7b08d5
MOZ_DIST_BIN="$MOZ_LIB_DIR/thunderbird"
7b08d5
MOZ_PROGRAM="$MOZ_DIST_BIN/thunderbird"
7b08d5
MOZ_LANGPACKS_DIR="$MOZ_DIST_BIN/langpacks"
7b08d5
MOZ_EXTENSIONS_PROFILE_DIR="$HOME/.mozilla/extensions/{3550f703-e582-4d05-9a08-453d09bdfdc6}"
7b08d5
MOZ_LAUNCHER="$MOZ_DIST_BIN/run-mozilla.sh"
7b08d5
7b08d5
##
7b08d5
## Set MOZ_ENABLE_PANGO is no longer used because Pango is enabled by default
7b08d5
## you may use MOZ_DISABLE_PANGO=1 to force disabling of pango
7b08d5
##
7b08d5
#MOZ_DISABLE_PANGO=1
7b08d5
#export MOZ_DISABLE_PANGO
7b08d5
7b08d5
##
7b08d5
## Set MOZ_APP_LAUNCHER for gnome-session
7b08d5
##
7b08d5
export MOZ_APP_LAUNCHER="/usr/bin/thunderbird"
7b08d5
7b08d5
##
7b08d5
## Disable the GNOME crash dialog, Moz has it's own
7b08d5
## 
7b08d5
GNOME_DISABLE_CRASH_DIALOG=1
7b08d5
export GNOME_DISABLE_CRASH_DIALOG
7b08d5
7b08d5
##
7b08d5
## Disable the SLICE allocator (rhbz#1014858)
7b08d5
##
7b08d5
export G_SLICE=always-malloc
7b08d5
7b08d5
##
7b08d5
## To disable the use of Firefox localization, set MOZ_DISABLE_LANGPACKS=1
7b08d5
## in your environment before launching Firefox.
7b08d5
##
7b08d5
#
7b08d5
# MOZ_DISABLE_LANGPACKS=1
7b08d5
# export MOZ_DISABLE_LANGPACKS
7b08d5
#
7b08d5
7b08d5
##
7b08d5
## Automatically installed langpacks are tracked by .fedora-langpack-install
7b08d5
## config file.
7b08d5
##
7b08d5
FEDORA_LANGPACK_CONFIG="$MOZ_EXTENSIONS_PROFILE_DIR/.fedora-langpack-install"
7b08d5
7b08d5
# MOZ_DISABLE_LANGPACKS disables language packs completelly
7b08d5
MOZILLA_DOWN=0
7b08d5
if ! [ $MOZ_DISABLE_LANGPACKS ] || [ $MOZ_DISABLE_LANGPACKS -eq 0 ]; then
7b08d5
    pidof thunderbird > /dev/null 2>&1
7b08d5
    MOZILLA_DOWN=$?
7b08d5
fi
7b08d5
7b08d5
# Modify language pack configuration only when thunderbird is not running 
7b08d5
# and language packs are not disabled
7b08d5
if [ $MOZILLA_DOWN -ne 0 ]; then
7b08d5
7b08d5
    # Clear already installed langpacks
7b08d5
    mkdir -p $MOZ_EXTENSIONS_PROFILE_DIR
7b08d5
    if [ -f $FEDORA_LANGPACK_CONFIG ]; then
7b08d5
        rm `cat $FEDORA_LANGPACK_CONFIG` > /dev/null 2>&1
7b08d5
        rm $FEDORA_LANGPACK_CONFIG > /dev/null 2>&1
7b08d5
        # remove all empty langpacks dirs while they block installation of langpacks
7b08d5
        rmdir $MOZ_EXTENSIONS_PROFILE_DIR/lang* > /dev/null 2>&1
7b08d5
    fi
7b08d5
7b08d5
    # Get locale from system
7b08d5
    CURRENT_LOCALE=$LC_ALL
7b08d5
    CURRENT_LOCALE=${CURRENT_LOCALE:-$LC_MESSAGES}
7b08d5
    CURRENT_LOCALE=${CURRENT_LOCALE:-$LANG}
7b08d5
    
7b08d5
    # Try without a local variant first, then with a local variant
7b08d5
    # So that pt-BR doesn't try to use pt for example
7b08d5
    SHORTMOZLOCALE=`echo $CURRENT_LOCALE | sed "s|_\([^.]*\).*||g"`
7b08d5
    MOZLOCALE=`echo $CURRENT_LOCALE | sed "s|_\([^.]*\).*|-\1|g"`
7b08d5
7b08d5
    function create_langpack_link() {
7b08d5
        local language=$*
7b08d5
        local langpack=langpack-${language}@thunderbird.mozilla.org.xpi
7b08d5
        if [ -f $MOZ_LANGPACKS_DIR/$langpack ]; then
7b08d5
            rm -rf $MOZ_EXTENSIONS_PROFILE_DIR/$langpack
7b08d5
            ln -s $MOZ_LANGPACKS_DIR/$langpack \
7b08d5
                  $MOZ_EXTENSIONS_PROFILE_DIR/$langpack
7b08d5
            echo $MOZ_EXTENSIONS_PROFILE_DIR/$langpack > $FEDORA_LANGPACK_CONFIG
7b08d5
            return 0
7b08d5
        fi
7b08d5
        return 1
7b08d5
    }
7b08d5
7b08d5
    create_langpack_link $SHORTMOZLOCALE || create_langpack_link $MOZLOCALE || true
7b08d5
fi
7b08d5
7b08d5
# BEAST fix (rhbz#1005611)
7b08d5
NSS_SSL_CBC_RANDOM_IV=${NSS_SSL_CBC_RANDOM_IV-1}
7b08d5
export NSS_SSL_CBC_RANDOM_IV
7b08d5
7b08d5
# Prepare command line arguments
7b08d5
script_args=""
7b08d5
pass_arg_count=0
7b08d5
while [ $# -gt $pass_arg_count ]
7b08d5
do
7b08d5
  case "$1" in
7b08d5
    -g | --debug)
7b08d5
      script_args="$script_args -g"
7b08d5
      debugging=1
7b08d5
      shift
7b08d5
      ;;
7b08d5
    -d | --debugger)
7b08d5
      if [ $# -gt 1 ]; then
7b08d5
        script_args="$script_args -d $2"
7b08d5
        shift 2
7b08d5
      else
7b08d5
        shift
7b08d5
      fi
7b08d5
      ;;
7b08d5
    *)
7b08d5
      # Move the unrecognized argument to the end of the list.
7b08d5
      arg="$1"
7b08d5
      shift
7b08d5
      set -- "$@" "$arg"
7b08d5
      pass_arg_count=`expr $pass_arg_count + 1`
7b08d5
      ;;
7b08d5
  esac
7b08d5
done
7b08d5
7b08d5
exec $MOZ_LAUNCHER $script_args $MOZ_PROGRAM "$@"