#! /bin/sh
#
# Author      : Olivier.Sirol@lip6.fr
# Date        : fev 1999
# Description : 
#
# (C) Czo 1998,99
# This code is released under GPL
#
# $Id: hypreset,v 1.2 2000/06/06 15:34:00 czo Exp $
#

PATH=/asim/gnu/bin:/usr/ucb:/usr/etc:/bin:/usr/local/bin:${PATH}
TMPWORKDIR=/tmp/hypczo
WML=/users/largo2/webmastr/wwwroot/mailing-lists
LOCK=/usr/local/listes/.etc/rc.lock
HMRC=/users/largo1/czo/cvslargo/listes-rules/hypermail/.hmrc 
SPLIT=/users/largo1/czo/cvslargo/listes-rules

#lock 
touch $LOCK

rm -fr "$TMPWORKDIR"
cd $WML 

echo "--> Sleep 5 sec and check..."
sleep 5
RES=`ps auxww | grep "hypermail" | grep -v grep`
if [ "$?" -eq 0 ] 
then
 echo "ERROR: hypermail running"
else
 echo "--> generating..."

#for MBOX in alliance-support 
for MBOX in alliance-programmers alliance-support alliance-users archi help
do
 echo "--> $MBOX..."
 mkdir -p "$TMPWORKDIR"
 cd "$WML/$MBOX"
 find . -type d -maxdepth 1 -mindepth 1 | xargs rm -fr dummy

cat "$WML/$MBOX/$MBOX.mbox" | formail -s $SPLIT/splitmailbyyear

echo %%%%%%%%%%%%%%%%%%%
for YEARBOX in `find /tmp/hypczo -type f -printf "%P\n"`
do
echo $YEARBOX
/usr/local/bin/hypermail -c $HMRC -p -x -l  "$MBOX '$YEARBOX" -d "$WML/$MBOX/$YEARBOX" -m "/tmp/hypczo/$YEARBOX"
done
rm -fr "$TMPWORKDIR"

done
fi

rm -f $LOCK


