
# Copyright 2003 Sun Microsystems, Inc. All Rights Reserved.
#
# ident "@(#)preremove	1.4 07/09/03"

# preremove script
 
#
# Return pid of named process in variable "pid"
#
# Exit codes for installation scripts
 
export BASEDIR
 
mozdir=$BASEDIR/sfw/lib/mozilla

e_ok=0
e_fatal=1      # stop installation on this exit
e_warning=2    # Installation will go on.
e_int=3        # Interrupted. Stop installation
e_reboot=10    # User must reboot after installation of all selected packages
e_rebootnow=20 # User must reboot right after installation of current package
               # To be added to one of the single-digit exit codes above
 
#
# Trap interrupt
#
trap `exit $e_int` 15
#

# test to see if BASEDIR of the CDE & Netscape are the same
if [ "$PKG_INSTALL_ROOT" != "" ]; then
	BASEDIR_CDE=`pkginfo -R ${PKG_INSTALL_ROOT} -l SUNWdtbas | grep BASEDIR | sed 's/BASEDIR: *//' | sed 's/ *//'`
else
	BASEDIR_CDE=`pkginfo -l SUNWdtbas | grep BASEDIR | sed 's/BASEDIR: *//' | sed 's/ *//'`
fi

# do the following only if the package is installed
if [ "$PKG_INSTALL_ROOT" != "" ]; then
	pkginfo -R ${PKG_INSTALL_ROOT} -q $PKGINST
else
	pkginfo -q $PKGINST
fi
if [ $? -eq 0 ]
then
	if [ -h $mozdir/plugins/libjavaplugin_oji.so ]; then
		rm -f $mozdir/plugins/libjavaplugin_oji.so
	fi
	if [ -h $mozdir/java ]; then
		rm -f $mozdir/java
	fi
        if [ -h $BASEDIR/sfw/bin/mozilla ]; then
                rm -f $BASEDIR/sfw/bin/mozilla
        fi
fi


installedchrometxt=$mozdir/chrome/installed-chrome.txt
chromerdf=$mozdir/chrome/chrome.rdf
overlayinfo=$mozdir/chrome/overlayinfo
suffix=en-US
compregdat=$mozdir/components/compreg.dat
xptidat=$mozdir/components/xpti.dat

# update installed-chrome.txt
if [ -f $installedchrometxt ] ; then
	diff $installedchrometxt $mozdir/chrome/installed-chrome.txt.$suffix | \
		grep '^<' | sed -e 's/^< //' > /tmp/$$installed-chrome.txt.new
	count=`cat /tmp/$$installed-chrome.txt.new | wc -l`
	if [ $count -eq 0 ]; then
		rm -r $installedchrometxt
	else
		cat /tmp/$$installed-chrome.txt.new > $installedchrometxt
	fi
	rm -f /tmp/$$installed-chrome.txt.new
fi

# update chrome.rdf, overlayinfo, xpti.dat and compreg.dat
/bin/rm -f $chromerdf
/bin/rm -rf $overlayinfo
/bin/rm -f $compregdat
/bin/rm -f $xptidat

if [ -f $installedchrometxt ] ; then
	LD_LIBRARY_PATH=$mozdir/:$mozdir/components
	MOZILLA_FIVE_HOME=$mozdir
	export LD_LIBRARY_PATH MOZILLA_FIVE_HOME
	$MOZILLA_FIVE_HOME/regchrome
fi

#
exit $e_ok
