#! /bin/sh
#
# This program is called from AQgetentry to send an index
#
# usage: AQindex "destination" "username" arg1 ... argn

PATH=/aeneas/ftp/archive/bin:/usr/local:/bin:/usr/ucb:/usr/bin
export PATH
Tmpfile=/tmp/AQindex.$$
HomeDir=/aeneas/ftp

trap "rm -f $Tmpfile; exit" 0 1 2 3 15

Path="$1"; shift
User="$1"; shift

echo "`date`" index $Path $* >> /aeneas/ftp/archive/requestqueue/out.log
cat << xxx > $Tmpfile
Subject: index, per your request
From: ATHENA-DIST archive service <archive-server>
In-reply-to: message from $User
To: $Path

xxx
FirstFlag=0
cd $HomeDir
for j in $*
do
    Dir="."
    . /aeneas/ftp/archive/bin/AQsetdir
    case $Dir in
	.) DirName="top level";;
	*) DirName=$j;;
    esac
    cat >> $Tmpfile << halfmast
Index of $DirName from ATHENA-DIST archive service (updated `ls -l $Dir/Index | awk '{print $5,$6,$7}'`)
-----------------------------------------------------------------
halfmast
	if [ -f $Dir/Index ]
	then
	    cat $Dir/Index >> $Tmpfile
	else
	    echo "Sorry, I don't have an index on file for \"$DirName\"" >> $Tmpfile
	    echo >> $Tmpfile
	fi
done

/usr/lib/sendmail -ba "$Path" < $Tmpfile
