#!/bin/sh

which=""

if echo $0 | grep 'navigator' >/dev/null; then
	which=netscape-navigator
elif echo $0 | grep 'communicator' >/dev/null ; then
	which=netscape-communicator
fi

if [ -z $which ]; then
	if rpm -q netscape-communicator >/dev/null 2>&1; then
	    which=netscape-communicator
	elif rpm -q netscape-navigator >/dev/null 2>&1; then
	    which=netscape-navigator
	else
	    echo "You don't have netscape installed." >&2
	fi
fi
	
if ! rpm -q $which >/dev/null 2>&1; then
	echo "You don't have $which installed." >&2
	exit 1
fi

I="`rpm -q $which --qf '%{INSTALLPREFIX}\n'`"
if [ "$I" = "(none)" ]; then
	I=/usr
fi

if [ -f $I/lib/netscape/gnumalloc.glibc.so ]; then
	export LD_PRELOAD=$I/lib/netscape/gnumalloc.glibc.so
fi

if [ -x $I/lib/netscape/$which ]; then
	export LD_PRELOAD=$I/lib/netscape/gnumalloc.glibc.so 
	if [ -z "$*" ]; then
	    	exec $I/lib/netscape/$which /usr/doc/HTML/index.html
	else
	    	exec $I/lib/netscape/$which $*
	fi
fi

echo "An error occurred running and $I/lib/netscape/$which."
