#!/bin/sh
#
# postinstall script for pkgadd ICNC Solstice suites
# This script is aimed to install a common index for
# all the docs packages comming from the suites.
#

echo
echo "Adding entry to Solstice documentation index..."

# safety first, in case this does something nasty
#
sync
if [ -z "$BASEDIR" ]
then
	BASEDIR=/opt
fi
PATH=$PATH:/usr/bin
DOCROOT=$BASEDIR/SUNWconn/docs

# This function is aimed to test install the index.htm file
#
add_index_htm ()
{
	if [ ! -f $DOCROOT/index.htm ]
	then
		cp -p $DOCROOT/templates/index.htm $DOCROOT/index.htm
	fi
}

# This function is aimed to patch the index.htm
# adding a hot link for the books contained in this
# package.
#	$1	book to install
#	$2	path of the book
#
patch_index_htm ()
{
	book=$1
	path=$2
	res=`grep "$book" $DOCROOT/index.htm`
	if [ -n "$res" ]
	then
		echo "Book $book already installed"
	else
		cat $DOCROOT/index.htm | awk '
			{ printf ("%s\n", $0); }
			/^<!-- BEGIN ADD LIST -->/ {
				printf ("<DT><IMG SRC=\"images/bullet.gif\" BORDER=0 WIDTH=\"41\" HEIGHT=\"20\" ALT=\"*\"> ");
				printf ("<A HREF=\"%s\">%s</A>\n", path, book);
			}
		' book="$book" path="$path" > /tmp/index.htm.$$
		mv /tmp/index.htm.$$ $DOCROOT/index.htm
		echo "Book $book installed"
	fi
}


# Install the docs...
#
add_index_htm
cp -p $DOCROOT/index.htm $DOCROOT/index.htm.bak

patch_index_htm "Java Dynamic Management Kit 3.0 Overview and Examples" "locale/C/JDMKMAIN/index.htm"
patch_index_htm "Java Dynamic Management Kit 3.0 Programming Guide" "locale/C/JDMKPG/index.htm"
patch_index_htm "Java Dynamic Management Kit 3.0 API Reference" "locale/C/JDMKAPI/packages.html"

exit 0 

# End of file
