1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-12-17 03:25:46 +00:00
freebsd-ports/security/amavis-perl/pkg-install.sendmail
David W. Chapman Jr. 4688c2ff1e Update to version 11
Give Seamus Venasse maintainership

PR:		31095
Submitted by:	new maintainer
2001-10-21 18:47:20 +00:00

94 lines
2.4 KiB
Perl

#!/usr/bin/perl
# Roman Shterenzon <roman@xpert.com> 27/12/2000
# $FreeBSD: /tmp/pcvs/ports/security/amavis-perl/Attic/pkg-install.sendmail,v 1.1 2001-10-21 18:47:20 dwcjr Exp $
use strict;
$ENV{'PATH'}='/bin:/usr/bin';
my $cfg;
my $result;
exit 0 if $ARGV[1] ne "POST-INSTALL";
if ( -f '/etc/mail/sendmail.cf' ) {
$cfg='/etc/mail';
}
elsif ( -f '/etc/sendmail.cf' ) {
$cfg='/etc';
}
my $cf="$cfg/sendmail.cf";
my $new="$cfg/amavis.cf";
print "===> Adding necessary hooks to sendmail.cf file\n";
open(IN, $cf) || die "Cannot open $cf";
open(OUT, ">$new") || die "Cannot create $new";
my $replace=0;
while(<IN>) {
if ( /^O QueueDirectory/ ) {
$_="O QueueDirectory=/var/spool/mqamavis\n";
$replace++;
}
elsif ( /O StatusFile/ ) {
$_="O StatusFile=/var/log/amavis.st\n";
$replace++;
}
elsif ( /^Mlocal/ ) {
print OUT <<'EOF';
Mamavis, P=/usr/local/sbin/amavis, F=mlsACDFMS5:/|@qhP, S=0, R=0
T=DNS/RFC822/X-Unix,
A=amavis $f $u
EOF
$replace++;
}
elsif ( /\s+final\s+parsing$/ ) {
print OUT "R\$*\t\t\t\$#amavis \$:\$1\n";
$replace++;
}
s/^(DZ.*)/$1av/;
print OUT;
}
close(OUT);
close(IN);
die "I couldn't patch the sendmail.cf file, its format is unknown to me\n"
unless ( $replace == 4 );
print "===> Adding alias for virusalert to the aliases file\n";
if ( ! -f "$cfg/aliases" ) {
print "Can't find aliases file, you have to add an alias for virusalert by yourself\n";
}
else {
open (IN, "$cfg/aliases") || die "Cannot open aliases file for reading\n";
my $found;
while(<IN>) {
$found=1, last if /^virusalert/;
}
close(IN);
unless ($found) {
open(OUT, ">>$cfg/aliases") || die "Cannot open aliases file for writing\n";
print OUT "virusalert:\troot\n";
close(OUT);
$result=system("newaliases");
die "Failed to run newaliases command\n" if $result;
}
}
print "===> Creating /var/spool/mqamavis directory\n";
if ( ! -d "/var/spool/mqamavis" ) {
mkdir "/var/spool/mqamavis",0755 || die "Can't create /var/spool/mqamavis\n";
}
my $gid=getgrnam('daemon');
chown 0, $gid, "/var/spool/mqamavis";
die "There's already a $cf.pre-amavis, is amavis already installed?\n"
if -f "$cf.pre-amavis";
$result=system("cp $cf $cf.pre-amavis");
die "Failed to copy $cf to $cf.pre-amavis\n" if $result;
rename "$cf", "${cfg}/sendmail.orig.cf" ||
die "Unable to rename $cf to ${cfg}/sendmail.orig.cf\n";
rename "$new", "$cf" || die "Unable to rename $new to $cf\n";