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
##
d2e479
## Enable Wayland backend?
d2e479
##
d2e479
%DISABLE_WAYLAND_PLACEHOLDER%
d2e479
d2e479
if ! [ $MOZ_DISABLE_WAYLAND ] && [ "$WAYLAND_DISPLAY" ]; then
d2e479
  if [ "$XDG_CURRENT_DESKTOP" == "GNOME" ]; then
d2e479
    export MOZ_ENABLE_WAYLAND=1
d2e479
  fi
d2e479
##  Enable Wayland on KDE/Sway
d2e479
##
d2e479
  if [ "$XDG_SESSION_TYPE" == "wayland" ]; then
d2e479
    export MOZ_ENABLE_WAYLAND=1
d2e479
  fi
d2e479
fi
d2e479
d2e479
##
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
exec $MOZ_PROGRAM "$@"