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