#! /bin/bash

directory='/etc/mail'
accessdb=/etc/mail/smtp.access
relaydb=/etc/mail/smtp.relay
mk_accessdb='/usr/sbin/mk-accessdb'
mk_relaydb='/usr/sbin/mk-relaydb'
test='/asr/bin/test'
whoami='/usr/bin/whoami'
echo='/bin/echo'

# Sanity check
test `$whoami` = 'root' || {
    $echo "You must be root to run this script"
    exit 1
}

for conffile in $accessdb $relaydb ; {
    test -f $db || {
	$echo "Error, can't find $conffile"
	exit 1
    }
}

for db in $accessdb.db $relaydb.db ; {
    ( test -w $db || test ! -e $db ) || {
	$echo "Error, $conffile.db exists, and is not writeable."
	exit 1
    }
}

# Ok, now the real work

pushd $directory >/dev/null

$echo "Rebuilding smtp.relay"
mk-relaydb smtp.relay | makemap hash smtp.relay

$echo "Rebuilding smtp.access"
mk-accessdb smtp.access | makemap hash smtp.access

popd >/dev/null

