10afcc
#!/bin/bash
10afcc
#
10afcc
# Startup script for the fedora.us Thunderbird RPM
10afcc
# (based on the Mozilla RPM launch script)
10afcc
#
10afcc
10afcc
##
10afcc
## Variables
10afcc
##
10afcc
MOZ_ARCH=$(uname -m)
10afcc
case $MOZ_ARCH in
10afcc
        x86_64 | s390x | sparc64 )
10afcc
                MOZ_LIB_DIR="/usr/lib64"
10afcc
                SECONDARY_LIB_DIR="/usr/lib"
10afcc
                ;;
10afcc
        * )
10afcc
                MOZ_LIB_DIR="/usr/lib"
10afcc
                SECONDARY_LIB_DIR="/usr/lib64"
10afcc
                ;;
10afcc
esac
10afcc
10afcc
if [ ! -x $MOZ_LIB_DIR/thunderbird/thunderbird ]; then
10afcc
    if [ ! -x $SECONDARY_LIB_DIR/thunderbird/thunderbird ]; then
10afcc
        echo "Error: $MOZ_LIB_DIR/thunderbird/thunderbird not found"
10afcc
        if [ -d $SECONDARY_LIB_DIR ]; then
10afcc
            echo "       $SECONDARY_LIB_DIR/thunderbird/thunderbird not found"
10afcc
        fi
10afcc
        exit 1
10afcc
    fi
10afcc
    MOZ_LIB_DIR="$SECONDARY_LIB_DIR"
10afcc
fi
10afcc
10afcc
MOZ_DIST_BIN="$MOZ_LIB_DIR/thunderbird"
10afcc
MOZ_PROGRAM="$MOZ_DIST_BIN/thunderbird"
10afcc
MOZ_LANGPACKS_DIR="$MOZ_DIST_BIN/langpacks"
10afcc
MOZ_EXTENSIONS_PROFILE_DIR="$HOME/.mozilla/extensions/{3550f703-e582-4d05-9a08-453d09bdfdc6}"
10afcc
10afcc
##
10afcc
## Set MOZ_ENABLE_PANGO is no longer used because Pango is enabled by default
10afcc
## you may use MOZ_DISABLE_PANGO=1 to force disabling of pango
10afcc
##
10afcc
#MOZ_DISABLE_PANGO=1
10afcc
#export MOZ_DISABLE_PANGO
10afcc
10afcc
##
10afcc
## Set MOZ_APP_LAUNCHER for gnome-session
10afcc
##
10afcc
export MOZ_APP_LAUNCHER="/usr/bin/thunderbird"
10afcc
10afcc
##
10afcc
## Disable the GNOME crash dialog, Moz has it's own
10afcc
## 
10afcc
GNOME_DISABLE_CRASH_DIALOG=1
10afcc
export GNOME_DISABLE_CRASH_DIALOG
10afcc
10afcc
##
10afcc
## Disable the SLICE allocator (rhbz#1014858)
10afcc
##
10afcc
export G_SLICE=always-malloc
10afcc
10afcc
##
10afcc
## To disable the use of Firefox localization, set MOZ_DISABLE_LANGPACKS=1
10afcc
## in your environment before launching Firefox.
10afcc
##
10afcc
#
10afcc
# MOZ_DISABLE_LANGPACKS=1
10afcc
# export MOZ_DISABLE_LANGPACKS
10afcc
#
10afcc
10afcc
##
10afcc
## Automatically installed langpacks are tracked by .fedora-langpack-install
10afcc
## config file.
10afcc
##
10afcc
FEDORA_LANGPACK_CONFIG="$MOZ_EXTENSIONS_PROFILE_DIR/.fedora-langpack-install"
10afcc
10afcc
# MOZ_DISABLE_LANGPACKS disables language packs completelly
10afcc
MOZILLA_DOWN=0
10afcc
if ! [ $MOZ_DISABLE_LANGPACKS ] || [ $MOZ_DISABLE_LANGPACKS -eq 0 ]; then
10afcc
    pidof thunderbird > /dev/null 2>&1
10afcc
    MOZILLA_DOWN=$?
10afcc
fi
10afcc
10afcc
# Modify language pack configuration only when thunderbird is not running 
10afcc
# and language packs are not disabled
10afcc
if [ $MOZILLA_DOWN -ne 0 ]; then
10afcc
10afcc
    # Clear already installed langpacks
10afcc
    mkdir -p $MOZ_EXTENSIONS_PROFILE_DIR
10afcc
    if [ -f $FEDORA_LANGPACK_CONFIG ]; then
10afcc
        rm `cat $FEDORA_LANGPACK_CONFIG` > /dev/null 2>&1
10afcc
        rm $FEDORA_LANGPACK_CONFIG > /dev/null 2>&1
10afcc
        # remove all empty langpacks dirs while they block installation of langpacks
10afcc
        rmdir $MOZ_EXTENSIONS_PROFILE_DIR/lang* > /dev/null 2>&1
10afcc
    fi
10afcc
10afcc
    # Get locale from system
10afcc
    CURRENT_LOCALE=$LC_ALL
10afcc
    CURRENT_LOCALE=${CURRENT_LOCALE:-$LC_MESSAGES}
10afcc
    CURRENT_LOCALE=${CURRENT_LOCALE:-$LANG}
10afcc
    
10afcc
    # Try without a local variant first, then with a local variant
10afcc
    # So that pt-BR doesn't try to use pt for example
10afcc
    SHORTMOZLOCALE=`echo $CURRENT_LOCALE | sed "s|_\([^.]*\).*||g"`
10afcc
    MOZLOCALE=`echo $CURRENT_LOCALE | sed "s|_\([^.]*\).*|-\1|g"`
10afcc
10afcc
    function create_langpack_link() {
10afcc
        local language=$*
10afcc
        local langpack=langpack-${language}@thunderbird.mozilla.org.xpi
10afcc
        if [ -f $MOZ_LANGPACKS_DIR/$langpack ]; then
10afcc
            rm -rf $MOZ_EXTENSIONS_PROFILE_DIR/$langpack
10afcc
            ln -s $MOZ_LANGPACKS_DIR/$langpack \
10afcc
                  $MOZ_EXTENSIONS_PROFILE_DIR/$langpack
10afcc
            echo $MOZ_EXTENSIONS_PROFILE_DIR/$langpack > $FEDORA_LANGPACK_CONFIG
10afcc
            return 0
10afcc
        fi
10afcc
        return 1
10afcc
    }
10afcc
10afcc
    create_langpack_link $SHORTMOZLOCALE || create_langpack_link $MOZLOCALE || true
10afcc
fi
10afcc
10afcc
# BEAST fix (rhbz#1005611)
10afcc
NSS_SSL_CBC_RANDOM_IV=${NSS_SSL_CBC_RANDOM_IV-1}
10afcc
export NSS_SSL_CBC_RANDOM_IV
10afcc
10afcc
# Linux version specific environment variables
10afcc
%RHEL_ENV_VARS%
10afcc
10afcc
# Make sure at-spi-bus is running
10afcc
if ! dbus-send --session            \
10afcc
     --dest=org.freedesktop.DBus    \
10afcc
     --type=method_call             \
10afcc
     --print-reply                  \
10afcc
     /org/freedesktop/DBus          \
10afcc
     org.freedesktop.DBus.ListNames \
10afcc
     | grep org.a11y.Bus > /dev/null; then
10afcc
    if [ -f "$MOZ_LIB_DIR/firefox/bundled/libexec/at-spi-bus-launcher" ]; then
10afcc
        echo "Starting a11y dbus service..."
10afcc
        $MOZ_LIB_DIR/firefox/bundled/libexec/at-spi-bus-launcher &
10afcc
    else
10afcc
        echo "Running without a11y support!"
10afcc
    fi
10afcc
fi
10afcc
10afcc
exec $MOZ_PROGRAM "$@"