
trap 'exit 3' 15

#+

#AB2BIN=/usr/lib/ab2/bin
AB2BASEDIR=`pkgparam SUNWab2u BASEDIR 2>> /dev/null`
AB2BIN=${AB2BASEDIR}/lib/ab2/bin

export AB2BIN

#re: configuration file text composition:
#    the following var must be modified under circumstances
#    before writing its value to a config file :

#Jan 97: for the nil_heavy interactive package:
# AB2DATADIR should have been assigned and exported by the request script.

if [ -z "${AB2DATADIR}" ]
then
	echo "FATAL install script processing error!"
	echo "AB2DATADIR has not been passed by th request script!"
	echo "signaling error to pkgadd..."
	
	exit 1
fi

if [ -z "${AB2INSTALLDIR}" ]
then
	echo "FATAL install script processing error!"
	echo "AB2INSTALLDIR has not been passed by th request script!"
	echo "signaling error to pkgadd..."
	
	exit 1
fi

ABINSTALLPATH=${AB2INSTALLDIR}

if [ "$PKG_INSTALL_ROOT" = "/a" ]
then
	#Solaris Install so:prune /a from the path"

	ABINSTALLPATH=`echo ${ABINSTALLPATH} |sed -e 's:^/a::'`
	export ABINSTALLPATH

elif [ "$PKG_INSTALL_ROOT" = "" ]
then
	#install without -R option to pkgadd 

	export ABINSTALLPATH
else
	#Handle client installation
	# for now no changes, we assume this is a doc server machine
	# with ab2 binaries. it is not nfs exporting the docs to client
	# machines, but rather serving them directly with its ab2 web server.

	export ABINSTALLPATH
fi

export ABINSTALLPATH

#-

postinstallstat=0

ESCAPEDAB2DATADIR=`echo ${AB2DATADIR} | sed 's;\\$;;'`
sed -e 's:<<ABINSTALLPATH>>:'${ESCAPEDAB2DATADIR}':' <  ${AB2DATADIR}/socat > /tmp/socat$$

mv /tmp/socat$$ ${ABINSTALLPATH}/socat

sed -e 's:<<ABINSTALLPATH>>:'${ESCAPEDAB2DATADIR}':' <  ${ABINSTALLPATH}/collinfo > /tmp/collinfo$$

mv /tmp/collinfo$$ ${ABINSTALLPATH}/collinfo

chown bin ${ABINSTALLPATH}/socat
chgrp bin ${ABINSTALLPATH}/socat
chown bin ${ABINSTALLPATH}/collinfo
chgrp bin ${ABINSTALLPATH}/collinfo

if [ -x "${AB2BIN}/ab2admin" ]
then
   cmd="${AB2BIN}/ab2admin -o install -n ${PKGINST} -d ${ABINSTALLPATH}/collinfo "
   echo "Adding AnswerBook Collections with command:"
   echo "$cmd"

   eval $cmd

   if [ "$?" -ne 0 ]
   then
	postinstallstat=1
	echo "NOTICE: postinstall failed to add AnswerBook collection to server"
	echo "The collections in this package have been physically added"
	echo "to this machine, but the AnswerBook2 admin function to"
	echo "logically add the collections has failed."
	echo ""
   else
	cmd1="${AB2BIN}/ab2admin -o stop"
	cmd2="${AB2BIN}/ab2admin -o start"
	echo "Restarting the server"
	echo "$cmd1"
	eval $cmd1
	echo "$cmd2"
	eval $cmd2

	#if we get here, then ab2admin has been run and may have
	#created ents/map.txt under the collection directory, so:

#	if [ -d ${AB2DATADIR}/ents -a -f ${AB2DATADIR}/ents/map.txt ]
#	then
#	  #use the packaging command installf to introduce an object
#	  #not listed in the pkgmap:
#
#	  installf -c none $PKGINST ${ABINSTALLPATH}/ents d 0755 root nobody
#	  installf -c none $PKGINST ${ABINSTALLPATH}/ents/map.txt f 0644 root nobody
#	  #finalize the additions:
#	  installf -f $PKGINST || exit 2
#	fi
   fi
else
#   echo "WARNING: Can't see ${AB2BIN}/ab2admin , the AnswerBook2 admin utility,"
#   echo "on this machine!  You will have to go to machine having ${AB2BIN}/ab2admin"
#   echo "to administer the collections which were added on this machine by this"
#   echo "package."
   echo "Note: This Collection will not be accessible until after the AB2 server"
   echo "      has been installed."
fi


exit $?
