#!/bin/sh
. /usr/local/ifmail/sets
out=~andrej/News/out

exec >>$LOGDIR/Pack.log 2>&1

cd $MAIN
tl=$SPOOL/Pack.lock
if $MAIN/bat/chklock $tl $SPOOL/cron.log Pack; then exit; fi
startflag=$SPOOL/Pack.OK
loop=0
rm -f $startflag
cd $MAIN
./ifpack -I$MAIN/config.ifmail

rm $tl

cd $SPOOL/outb
if [ -f 01d00014.flo ]
then
  for i in 000000b4.???
  do
    sleep 2
    t=`date +%s | sed 's/^.//'`
    if [ ! -d $out ]; then
      echo Making $out
      if mkdir -p $out; then
        chown andrej $out
      else
        echo Aborting.
      fi
    fi
    mv $i $out/$t.mo1
    chmod a+r $out/$t.mo1 2>&1 > /dev/null
  done
  rm 01d00014.flo
fi
rm -f $tl
