#!/usr/bin/perl

if ($ARGV[1] ne "POST-INSTALL") {
        exit 0
}

# The way things should be:
$mdir="/var/mail";
$mmode="0775";
$nummode=oct($mmode);
$exim_user = "bin";
$exim_group = "mail";

# First make sure that group mail exists. Also make sure that /var/mail
# is 0775 owned by root. Older FreeBSD systems may not be configured
# like this.

if (! defined($mailgroup = getgrnam("$exim_group")) ) {
	print "Exim should be run as $exim_user:$exim_group\n";
	print "but group $exim_group does not appear to exist.\n";
	print "Update your /etc/group as required and try again.\n";
	exit 1;
}

($junk,$junk,$rmode,$junk,$ruid,$rgid,$junk,
    $junk,$junk,$junk,$junk,$junk,$junk) = stat("$mdir");
$rmode &= 07777;
$rowner = getpwuid($ruid);
$rgroup = getgrgid($rgid);

if (($rmode != $nummode) || ($rowner ne $exim_user) ||
    ($rgroup ne $exim_group)) {
	print "$mdir should be owned by $exim_user:$exim_group with\n";
	print "permissions set to 0775. Use chmod(1) and chown(8) to make\n";
	print "the necessary changes and try again.\n";
	exit 1;
}

# Now explain how exim should be configured and offer some warnings to prevent
# much wailing and gnashing of teeth.

print <<EOF;

=========================================================================
Exim is configured to run as user $exim_user and group $exim_group.
The $mdir directory should be owned by same, with permissions $mmode.
Exim will never deliver mail as root. Make sure root's mail is redirected
in /etc/aliases.
=========================================================================

EOF

exit 0;
