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