#!/usr/local/bin/bash
#
# REFLECTORY: Build the Directory of CDs in this Site.
#

TOTALFILES=""
TOTALSIZE=""

O="directory.html"

echo "<HTML><TITLE>CD.TEXTFILES.COM: The Collection</TITLE>"             >$O
echo "<BODY BGCOLOR=\"#000000\" TEXT=\"#FFFFFF\" LINK=\"#FFFFFF\" "     >>$O
echo " ALINK=\"#EEEEEE\" VLINK=\"#DDDDDD\"> " >>$O

echo "<CENTER>"                                                                >>$O
echo "<B>Collections will be nominally web-enabled via various trickery. <BR>" >>$O
echo "In most cases, the descriptions provided by the CD itself will be all"   >>$O
echo "the information available.<BR>Click on the disk icon to the right of a"  >>$O
echo " CD listing to browse with a web-enabled interface.</B><P>"              >>$O
echo "<I>Entries in Red were grabbed from the Net, and so there has been no"   >>$O
echo "verification that they're complete or accurate. But something's better"  >>$O
echo "than nothing.<br> A list of each directory's addition date is <a href=\"newest.html\">here</a>"                                                           >>$O
echo "<P><TABLE WIDTH=700><TR>"                                                >>$O
echo "<TD BGCOLOR=\"#5555CC\"><B>Name of CD-ROM and Year"                      >>$O
echo "<TD BGCOLOR=\"#5555DD\" ALIGN=CENTER><B>Number of Files"                 >>$O
echo "<TD BGCOLOR=\"#5555EE\" ALIGN=CENTER><B>Size in KBytes"                   >>$O

for dire in *
    do
    if [ -d "$dire" ]
       then
       if [ -f "$dire/.name" ]
          then
          touch "$dire/.name"
          if [ ! -f "$dire/.files" ]
             then
             echo "[!] $dire has no filecounts. Fixing."
             FILES="`find $dire -type f | wc -l`"
             SIZE="`du -s $dire | cut -f1`"
             echo "--- $FILES files, $SIZE total size."
             echo "$FILES" >"$dire/.files"
             echo "$SIZE" >"$dire/.size"
          fi

NAME="`cat $dire/.name`"
SUBNAME="`cat $dire/.subname`"
YEAR="`cat $dire/.year`"
FILES="`cat $dire/.files`"
SIZE="`cat $dire/.size`"

let TOTALFILES=$(($TOTALFILES+$FILES))
let TOTALSIZE=$(($TOTALSIZE+$SIZE))

if [ -f "$dire/.month" ]
   then
   YEAR="`cat $dire/.month` $YEAR"
fi

# If this is some crap I downloaded off the net, then make sure it's
# a different color.

PROBATION="#111133"
if [ -f $dire/.probation ]
   then
   PROBATION="#331111"
fi

if [ -f "$dire/.collection" ]
   then
   PROBATION="#222255"
CDS=`ls $dire | grep ^[a-z] | grep -v index.html | wc -l`
echo "<!----- COLLECTION ENTRY ------>"                                 >>$O
echo "<TR><TD BGCOLOR=${PROBATION}><FONT COLOR=\"#FFFFFF\">"       >>$O
echo "<B><A HREF=\"$dire\">$NAME</A></B><BR>"                   >>$O
echo "<I>$CDS CDs ($YEAR)</I><BR>"      >>$O
echo "<TD ALIGN=CENTER> $FILES"                                 >>$O
echo "<TD ALIGN=CENTER> $SIZE"                                  >>$O

else
echo ""								>>$O
echo "<!----- CD ENTRY ------>"                                 >>$O
echo "<TR><TD BGCOLOR=${PROBATION}><FONT COLOR=\"#FFFFFF\">"         >>$O
echo "<B><A HREF=\"$dire\">$NAME</A></B><BR>"                   >>$O
echo "<I>$SUBNAME ($YEAR)</I><BR>"                              >>$O
echo "<TD ALIGN=CENTER> $FILES"					>>$O
echo "<TD ALIGN=CENTER> $SIZE"                                  >>$O

fi

if [ -f "$dire/.index.html" ]
   then
   echo "<TD ALIGN=CENTER><A HREF=\"$dire/.index.html\"><IMG SRC=\"disk.gif\" BORDER=0></A>" >>$O
fi
       else 
       if [ -n "$1" ]
          then
       echo "$dire has no .name."
       fi
       fi
    fi
    done

echo "<TR><TD BGCOLOR=\"#5555CC\">&nbsp;"                      >>$O
echo "<TD BGCOLOR=\"#5555DD\" ALIGN=CENTER><B>$TOTALFILES"                 >>$O
echo "<TD BGCOLOR=\"#5555EE\" ALIGN=CENTER><B>$TOTALSIZE"                   >>$O


echo " </TABLE> <p> Thanks to a bunch of people, including Erik Pederson, Peter Simpson, Chuck Gilbert, Koos van den Hout, MCbx, and Tim Hazel,<br>who have donated, mailed, or uploaded dozens and dozens of CD-ROMs for this site. </CENTER> </BODY> </HTML>"                      >>$O

/cd.textfiles.com/.newest
