#!/bin/ksh 
set -x
BOOTIMAGE=$1
cdtoc_file=$BOOTIMAGE/../../../.cdtoc

PKG_POOL=$BOOTIMAGE/../../Product

PROD_VERSION=$(grep PRODVERS $cdtoc_file | sed -e 's:PRODVERS=::')
ADMINFILE=/tmp/netadmin.$$

cat << EOF > $ADMINFILE
mail=
instance=unique
partial=ask
runlevel=nocheck
idepend=nocheck
rdepend=ask
space=nocheck
setuid=nocheck
conflict=nocheck
action=nocheck
EOF

setup_ns() {
  echo "		Installing Netscape"
  if [ -d $BOOTIMAGE/webstart/.netscape ];then
    rm -rf $1/webstart/.netscape
  fi
  if [ ! -d $BOOTIMAGE/webstart/.netscape ];then
    mkdir -p $BOOTIMAGE/webstart/.netscape
    mkdir $BOOTIMAGE/webstart/.netscape/archive
  fi
}

if [ `/usr/ucb/whoami` != "root" ]; then
        echo "You Must be root."
        exit 1
fi
if [ ! "$BOOTIMAGE" -o "$1" = '-h' -o "$BOOTIMAGE" = '-help' ]; then
        echo "Usage: install_netscape [Solaris boot image absolute path]."
        exit 1
fi


if [ -d $BOOTIMAGE/platform/i86pc ];then
  ARCH=i386
else
  ARCH=sparc
fi

echo "		Installing Netscape"
setup_ns
SRC=`pwd`
cd $SRC/netscape
find . -name SCCS -prune -o -print | cpio -dump $1/webstart/.netscape/
chown -R root:other $BOOTIMAGE/webstart
cd $SRC

cp $SRC/../NSCPnav.$ARCH.tar.Z /tmp
cd /tmp
zcat NSCPnav.$ARCH.tar.Z | tar xf -

pkgadd -d . -R $BOOTIMAGE -a $ADMINFILE NSCPnav
if [ $? -eq 0 ];then
  exit 0
else
  exit -1
fi
