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