#!/bin/sh
#
# Sun Branded Mozilla postinstall script
#
# ident "@(#)postinstall	1.6 07/11/03"

mozdir=$BASEDIR/sfw/lib/mozilla
installedchrometxt=$mozdir/chrome/installed-chrome.txt
chromerdf=$mozdir/chrome/chrome.rdf
overlayinfo=$mozdir/chrome/overlayinfo
compregdat=$mozdir/components/compreg.dat
xptidat=$mozdir/components/xpti.dat

ARCH=`uname -p`

cd $mozdir/chrome

# update installed-chrome.txt
rm -f $installedchrometxt
for i in `ls installed-chrome.txt.*`
do
	if [ -f "$i" ]
	then
		cat $i >> $installedchrometxt
	fi
done
installf $PKGINST $installedchrometxt f 0755 root sys

# update chrome.rdf and overlayinfo and compreg.dat & xpti.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

installf $PKGINST $chromerdf f 0755 root sys
installf $PKGINST $compregdat f 0755 root sys
installf $PKGINST $xptidat f 0755 root sys
installf -f $PKGINST


JREPATH=`$mozdir/checkJRE.ksh $INST_DATADIR $PKG_INSTALL_ROOT`

if [ "X$JREPATH" != "X" ]; then
# test to see if BASEDIR of the JRE & Netscape are the same
     if [ "$PKG_INSTALL_ROOT" != "" ]; then
	BASEDIR_JRE=`pkginfo -R $PKG_INSTALL_ROOT -l SUNWj3rt | grep BASEDIR | sed 's/BASEDIR: *//' | sed 's/ *//'`
     else
	BASEDIR_JRE=`pkginfo -l SUNWj3rt | grep BASEDIR | sed 's/BASEDIR: *//' | sed 's/ *//'`
     fi  
 
   if [ "$BASEDIR_JRE" != "" ]; then
        if [ "${PKG_INSTALL_ROOT}$BASEDIR_JRE" = "${PKG_INSTALL_ROOT}$CLIENT_BASEDIR" ]; then
	   if [ ! -h $mozdir/plugins/libjavaplugin_oji.so ]; then
                ln -s ../../../../j2se/jre/plugin/$ARCH/ns610/libjavaplugin_oji.so $mozdir/plugins/libjavaplugin_oji.so
	   fi
	   if [ ! -h $mozdir/java ]; then
                ln -s ../../../j2se/jre $mozdir/java
	   fi
        else
	   if [ ! -h $mozdir/plugins/libjavaplugin_oji.so ]; then
                ln -s ${PKG_INSTALL_ROOT}$BASEDIR_JRE/j2se/jre/plugin/$ARCH/ns610/libjavaplugin_oji.so $mozdir/plugins/libjavaplugin_oji.so
	   fi
	   if [ ! -h $mozdir/java ]; then
                ln -s ${PKG_INSTALL_ROOT}$BASEDIR_JRE/j2se/jre $mozdir/java
	   fi
        fi
   fi
else
        echo "WARNING: No Java1.4 found--APPLETS will not work "
fi
 
# 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

#if [ "${PKG_INSTALL_ROOT}$BASEDIR_CDE" = "$BASEDIR" ]; then
#   if [ ! -h ${PKG_INSTALL_ROOT}$BASEDIR_CDE/dt/bin/mozilla ]; then
#      ln -s ../../sfw/mozilla/mozilla ${PKG_INSTALL_ROOT}$BASEDIR_CDE/dt/bin/mozilla
#   fi
#else
#   if [ ! -h ${PKG_INSTALL_ROOT}$BASEDIR_CDE/dt/bin/mozilla ]; then
#      ln -s $BASEDIR/mozilla/mozilla ${PKG_INSTALL_ROOT}$BASEDIR_CDE/dt/bin/mozilla
#   fi
#fi

if [ ! -h $BASEDIR/sfw/bin/mozilla ]; then
	if [ ! -d $BASEDIR/sfw/bin ]; then
		mkdir -p $BASEDIR/sfw/bin
	fi
        ln -s $mozdir/mozilla $BASEDIR/sfw/bin/mozilla
fi

exit 0
