#!/bin/sh
#
# FILESTATS: Make a File Stats Page that tells you all the goodies
#            about textfiles.com and lets you see how big the thing is.

I="/textfiles/webfiles/filestats.html"

echo "<HTML><TITLE>T E X T F I L E S</TITLE>"                                                            >$I
echo "<BODY BGCOLOR="#6699FF" TEXT="#FFFFFF" LINK="#FFFFFF" ALINK="#FFFFFF" VLINK="#FFFFFF">"           >>$I
echo "<CENTER><H1>WEB.TEXTFILES.COM File Statistics</H1>"                                                   >>$I
echo "<SMALL><I>This Document Was Last Updated at `date`</I></SMALL>"                                   >>$I
echo "<P>"                                                                                              >>$I
echo ""                                                                                                 >>$I
echo "<TABLE WIDTH=100%><TR><TD BGCOLOR=#6666FF><FONT COLOR=#000000>&nbsp<B>Directory</B></FONT>"       >>$I
echo "<TD BGCOLOR=#6666DD><FONT COLOR=#000000>&nbsp<B># of Files</B></FONT>"                            >>$I
echo "<TD BGCOLOR=#6666AA><FONT COLOR=#000000>&nbsp<B>Size of Directory</B></FONT>"                     >>$I

for directory in `cat /textfiles/webfiles/.directories`
    do
    
    nfiles="`ls -R /textfiles/webfiles/$directory | grep -v .html | wc -l`"
    bytes="`/usr/local/bin/du -sb /textfiles/webfiles/$directory | cut -f1`"

    tfiles=$(($tfiles + $nfiles))
    tbyte=$(($tbyte + $bytes))

    echo "<TR><TD>&nbsp<B><A HREF=\"/$directory\">$directory</A></B>"                                   >>$I
    echo "<TD>&nbsp `/textfiles/magic/comma $nfiles`"                                                   >>$I
    echo "<TD>&nbsp `/textfiles/magic/comma $bytes`"                                                    >>$I
    done

echo "<TR><TD BGCOLOR=#6666FF><FONT COLOR=#000000>&nbsp<B>Totals</B></FONT>"                              >>$I
echo "<TD BGCOLOR=#6666EE><FONT COLOR=#000000>&nbsp<B>`/textfiles/magic/comma $tfiles` files</B></FONT>"  >>$I
echo "<TD BGCOLOR=#6666AA><FONT COLOR=#000000>&nbsp<B>`/textfiles/magic/comma $tbyte` bytes</B></FONT>"   >>$I

echo "</TABLE>"                                                                                         >>$I
echo "</BODY></HTML>"                                                                                   >>$I
