#!/bin/bash
#
# Updates the list archive with new messages since last run based
# on the last index in $LASTINDEX and the latest index in the $LISTDIR
# 
# 2006 Martin Leopold <leopold@diku.dk>
#

if [ $# -le 1 ]; then
 echo "Grrr.."
 echo "\$1 - name of the archive"
 echo "\$2 - www dir"
 echo "\$3 - list dir"
 exit 0
fi

LABEL=$1
WWWDIR=$2
LISTDIR=$3
LASTINDEXFILE=$WWWDIR/last
NEWINDEX=`cat $LISTDIR/index`
LASTINDEX=`cat $LASTINDEXFILE`
HYPERMAIL="/usr/local/bin/hypermail"

if [ -z $LASTINDEX ]; then
LASTINDEX=1
fi

for IT in `seq $LASTINDEX $NEWINDEX`; do
  $HYPERMAIL -l $LABEL -i -u -d $WWWDIR < $LISTDIR/archive/$IT
done

chown apache:apache -R $WWWDIR

echo $NEWINDEX > $LASTINDEXFILE