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