#!/bin/bash
#
# index-howtos --- generate an index.html for the doc-linux-html package
#
# Written by Dirk Eddelbuettel <edd@debian.org> 08 July 97, 27 Jan 98
#            based on indexit by Marco Budde <Budde@tu-harburg.d400.de>

echo "<html>" > index.html
echo "<head><title>Content of the Debian doc-linux-html Package</title></head>" >> index.html
echo "<h1>Content of the Debian doc-linux-html Package</h1>" >> index.html

echo "<table>" >> index.html

# Do the HOWTOs
for i in *HOWTO.html ; do

    # create index.html
    echo "<tr><td valign=baseline><a href=\""$i"\">"$i"</A>" >> index.html
    echo "    <td>" >> index.html
    START=$(grep -n "<P><HR><EM>" $i | cut - -f1 -d:);
    FINISH=$(grep -n "</EM><HR></P>" $i | cut - -f1 -d:);
    if [ "$START" != "" -a "$FINISH" != "" ]
    then 
	head -n $FINISH $i | tail +$START | \
	sed -e 's/<P><HR><EM>//g' -e 's/<\/EM><HR><\/P>//g' >> index.html
    fi
    # Create link to index.html in every toc of the HOWTOs
    mv $i 1.tmp
    sed -e 's/<IMG SRC="toc.gif" ALT="Contents">/<A HREF="index.html"><IMG SRC="toc.gif" ALT="Contents doc-linux-html"><\/A>/' 1.tmp > $i 

done

# Do the mini-HOWTOs
for i in `ls -1 mini/*.html | egrep -v "\-[[:digit:]]+.html"` ; do

    # create index.html
    echo "<tr><td valign=baseline><a href=\""$i"\">"$i"</A>" >> index.html
    echo "    <td>" >> index.html
    START=$(grep -n "<P><HR><EM>" $i | cut - -f1 -d:);
    FINISH=$(grep -n "</EM><HR></P>" $i | cut - -f1 -d:);
    if [ "$START" != "" -a "$FINISH" != "" ]
    then 
	head -n $FINISH $i | tail +$START | \
	sed -e 's/<P><HR><EM>//g' -e 's/<\/EM><HR><\/P>//g' >> index.html
    fi
    # Create link to index.html in every toc of the HOWTOs
    mv $i 1.tmp
    sed -e 's/<IMG SRC="toc.gif" ALT="Contents">/<A HREF="index.html"><IMG SRC="toc.gif" ALT="Contents doc-linux-html"><\/A>/' 1.tmp > $i 

done

now=$(date)
#echo "<tr><td><a href=\"mini/index.html\">mini/</a>" >>index.html
#echo "<td>mini HOWTO Directory" >>index.html
echo "</table>" >>index.html
echo "<hr><address><small>" >>index.html
echo "Please send comments to <a href=\"mailto:edd@debian.org\">Dirk Eddelbuettel</a>.<br>" >>index.html
echo "This page was created automatically at $now." >>index.html
echo "</small></address></body></html>" >>index.html

mv index.html 1.tmp

sed -e 's/.html</</' 1.tmp | \
sed -e 's/>de-/>/'  > index.html

rm -f 1.tmp
