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