#!/bin/bash

WRAPPERDIR=/usr/lib/MailScanner

LOCKFILE=/var/lock/MailScanner.autoupdate.lock

# the lockfile is not meant to be perfect, it's just in case the
# two cron scripts get run close to each other to keep them from
# stepping on each other's toes.
[ -f $LOCKFILE ] && exit 0
trap "rm -f $LOCKFILE" EXIT
touch $LOCKFILE

# Set umask so user mail can read (and share-lock) the Busy.lock files
umask 022

for UPDATER in ${WRAPPERDIR}/*-autoupdate
do
  NAME=`basename $UPDATER | sed -e 's/-autoupdate//'`
  if ${WRAPPERDIR}/${NAME}-wrapper -IsItInstalled
  then
    #echo Found $NAME installed
    logger -p mail.info -t update.virus.scanners Found $NAME installed
    if [ -x ${UPDATER} ]
    then
      #echo Updating $NAME
      logger -p mail.info -t update.virus.scanners Updating $NAME
      ${UPDATER} >/dev/null 2>&1
    fi
  fi
done

exit 0
