Blob Blame History Raw
#!/bin/sh
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is Netscape
# Communications Corporation.  Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): 
#

## 
## Usage:
##
## $ thunderbird
##
## This script is meant to run a mozilla program from the mozilla
## rpm installation.
##
## The script will setup all the environment voodoo needed to make
## mozilla work.

cmdname=`basename $0`

# BEAST fix
NSS_SSL_CBC_RANDOM_IV=${NSS_SSL_CBC_RANDOM_IV-1}
export NSS_SSL_CBC_RANDOM_IV

##
## Variables
##
MOZ_ARCH=$(uname -m)
case $MOZ_ARCH in
	x86_64 | s390x | sparc64)
		MOZ_LIB_DIR="/usr/lib64"
		SECONDARY_LIB_DIR="/usr/lib"
		;;
	* )
		MOZ_LIB_DIR="/usr/lib"
		SECONDARY_LIB_DIR="/usr/lib64"
		;;
esac

if [ ! -x $MOZ_LIB_DIR/thunderbird/thunderbird ]; then
    if [ ! -x $SECONDARY_LIB_DIR/thunderbird/thunderbird ]; then
        echo "Error: $MOZ_LIB_DIR/thunderbird/thunderbird not found"
        if [ -d $SECONDARY_LIB_DIR ]; then
            echo "       $SECONDARY_LIB_DIR/thunderbird/thunderbird not found"
        fi
        exit 1
    fi
    MOZ_LIB_DIR="$SECONDARY_LIB_DIR"
fi

MOZ_DIST_BIN="$MOZ_LIB_DIR/thunderbird"
MOZ_PROGRAM="$MOZ_DIST_BIN/thunderbird"
MOZ_LANGPACKS_DIR="$MOZ_DIST_BIN/langpacks"
MOZ_EXTENSIONS_PROFILE_DIR="$HOME/.mozilla/extensions/{3550f703-e582-4d05-9a08-453d09bdfdc6}"

##
## Set MOZ_ENABLE_PANGO is no longer used because Pango is enabled by default
## you may use MOZ_DISABLE_PANGO=1 to force disabling of pango
##
#MOZ_DISABLE_PANGO=1
#export MOZ_DISABLE_PANGO

##
## Set MOZ_APP_LAUNCHER for gnome-session
##
export MOZ_APP_LAUNCHER="/usr/bin/thunderbird"

##
## Disable the GNOME crash dialog, Moz has it's own
## 
GNOME_DISABLE_CRASH_DIALOG=1
export GNOME_DISABLE_CRASH_DIALOG

##
## To disable the use of Firefox localization, set MOZ_DISABLE_LANGPACKS=1
## in your environment before launching Firefox.
##
#
# MOZ_DISABLE_LANGPACKS=1
# export MOZ_DISABLE_LANGPACKS
#

##
## Automatically installed langpacks are tracked by .fedora-langpack-install
## config file.
##
FEDORA_LANGPACK_CONFIG="$MOZ_EXTENSIONS_PROFILE_DIR/.fedora-langpack-install"

# MOZ_DISABLE_LANGPACKS disables language packs completely
MOZILLA_DOWN=0
if ! [ $MOZ_DISABLE_LANGPACKS ] || [ $MOZ_DISABLE_LANGPACKS -eq 0 ]; then
    pidof thunderbird > /dev/null 2>&1
    MOZILLA_DOWN=$?
fi

# Modify language pack configuration only when thunderbird is not running 
# and language packs are not disabled
if [ $MOZILLA_DOWN -ne 0 ]; then

    # Clear already installed langpacks
    mkdir -p $MOZ_EXTENSIONS_PROFILE_DIR
    if [ -f $FEDORA_LANGPACK_CONFIG ]; then
        rm `cat $FEDORA_LANGPACK_CONFIG` > /dev/null 2>&1
        rm $FEDORA_LANGPACK_CONFIG > /dev/null 2>&1
    fi

    # Get locale from system
    CURRENT_LOCALE=$LC_ALL
    CURRENT_LOCALE=${CURRENT_LOCALE:-$LC_MESSAGES}
    CURRENT_LOCALE=${CURRENT_LOCALE:-$LANG}
    
    # Try without a local variant first, then with a local variant
    # So that pt-BR doesn't try to use pt for example
    SHORTMOZLOCALE=`echo $CURRENT_LOCALE | sed "s|_\([^.]*\).*||g"`
    MOZLOCALE=`echo $CURRENT_LOCALE | sed "s|_\([^.]*\).*|-\1|g"`

    function create_langpack_link() {
        local language=$*
        local langpack=langpack-${language}@thunderbird.mozilla.org.xpi
        if [ -f $MOZ_LANGPACKS_DIR/$langpack ]; then
            rm -rf $MOZ_EXTENSIONS_PROFILE_DIR/$langpack
            ln -s $MOZ_LANGPACKS_DIR/$langpack \
                  $MOZ_EXTENSIONS_PROFILE_DIR/$langpack
            echo $MOZ_EXTENSIONS_PROFILE_DIR/$langpack > $FEDORA_LANGPACK_CONFIG
            return 0
        fi
        return 1
    }

    create_langpack_link $SHORTMOZLOCALE || create_langpack_link $MOZLOCALE || true
fi

exec $MOZ_PROGRAM "$@"