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