#!/bin/sh
#
#  Updates the description for the @THIS_BROKER_NAME@ broker.
#  The Broker's configuration file is available as $1
#
#  Created by @CONTACT_EMAIL@
#
HARVEST_HOME=@THIS_HARVEST_HOME@; export HARVEST_HOME
PATH=${HARVEST_HOME}/bin:${HARVEST_HOME}/lib/broker:$PATH:/bin; export PATH
d=@THIS_BROKER_DIR@

Version="1.3"

# set some variables for the HTML file...

IndexType=`egrep -i -e '^Indexer-Type' $1 | awk '{print $2}'`
WebServer=`egrep -i -e '^Web-Server' $1 | awk '{print $2}'`
BrokerHPP=`egrep -i -e '^Broker-Home-Page' $1 | awk '{print $2}'`
Port=`egrep -i -e '^Port' $1 | awk '{print $2}'`
BrokerHP="http://${WebServer}${BrokerHPP}"
ctime=`date`

# change into the broker directory
cd $d

cpoints=`egrep -v -e '^#' admin/Collection.conf`

# commands to update description file go here...
desc="${d}/description.html"
mv $desc $desc.old
cat <<EOM >$desc
<HTML>
<HEAD>
<META NAME="HarvestServerType" CONTENT="BROKER">
<META NAME="HarvestServerHost" CONTENT="@THIS_BROKER_HOST@">
<META NAME="HarvestServerPort" CONTENT="$Port">
<TITLE>Description for @THIS_BROKER_NAME@ Harvest Broker</TITLE>
</HEAD>
<BODY>
<H2>Description for @THIS_BROKER_NAME@ Harvest Broker</H2>
<HR>
<H4>Mandatory information</H4>
<DT>Description</DT><DD>UNKNOWN</DD>
<DT>Description-File</DT><DD>@THIS_BROKER_DESC_URL@</DD>
<DT>Host</DT><DD>@THIS_BROKER_HOST@</DD>
<DT>Last-Update</DT><DD>@THIS_BROKER_ADMIN_PROCESS@</DD>
<DT>Last-Update-Time</DT><DD>$ctime</DD>
<DT>Maintainer</DT><DD>@CONTACT_EMAIL@</DD>
<DT>Name</DT><DD>@THIS_BROKER_NAME@</DD>
<DT>Port</DT><DD>$Port</DD>
<DT>Version</DT><DD>$Version</DD>
<HR>
<H4>Recommended information</H4>
<DT>Extended-Description</DT><DD>UNKNOWN</DD>
<DT>Gatherer</DT><DD>$cpoints</DD>
<DT>Keywords</DT><DD>UNKNOWN</DD>
<DT>Organization</DT><DD>UNKNOWN</DD>
<HR>
<H4>Optional information</H4>
<DT>Broker-Home-Page</DT><DD>$BrokerHP</DD>
<DT>Index-Type</DT><DD>$IndexType</DD>
<DT>Replicas</DT><DD>@REPLICAS@</DD>
</BODY>
</HTML>
EOM

# make sure the HTTP server can serve the description file
chmod o+r $desc
exit 0
