The Mailmunge email filtering framework https://www.mailmunge.org/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

158 lines
6.6 KiB

#!/bin/sh
if test "$1" != "sendmail" -a "$1" != "postfix" ; then
echo "Usage: $0 sendmail|postfix buster|rocky|bullseye [-f] [-v] [-c]"
exit 1
fi
if test "$2" != "buster" -a "$2" != "rocky" -a "$2" != "bullseye"; then
echo "Usage: $0 sendmail|postfix buster|rocky|bullseye [-f] [-v] [-c]"
exit 1
fi
MTA="$1"
OS="$2"
if test "$OS" = "buster" -o "$OS" = "bullseye" ; then
FLAVOR=debian
else
FLAVOR=rocky
fi
IMAGE=mm-$MTA-$OS-image
CONTAINER=mm-$MTA-$OS
FORCE_REBUILD=0
VERBOSE=
COLOR=
INTERACTIVE=
for arg in "$@" ; do
if test "$arg" = "-f" ; then
FORCE_REBUILD=1
fi
if test "$arg" = "-v" ; then
VERBOSE="-v"
fi
if test "$arg" = "-c" ; then
COLOR="-c"
INTERACTIVE="-it"
fi
done
bailout () {
echo "FATAL: $@"
exit 1
}
# Get version
VERSION=`grep '^PACKAGE_VERSION=' ../configure | sed -e 's/PACKAGE_VERSION=//' -e "s/'//g"`
if test -z "$VERSION" ; then
bailout "Could not determine Mailmunge version!"
fi
# Check if container is running. If not, start it
docker exec "$CONTAINER" true > /dev/null 2>&1
if test $? != 0 ; then
RUNNING=0
echo "Container $CONTAINER doesn't seem to be running; starting it..."
docker start "$CONTAINER"
for i in `seq 1 10` ; do
docker exec "$CONTAINER" true > /dev/null 2>&1
if test $? = 0; then
RUNNING=1
break;
fi
sleep 1
done
if test "$RUNNING" = 0 ; then
bailout "Could not start $CONTAINER"
fi
fi
REBUILD=1
# Check if we already have a mailmunge dir there
docker exec "$CONTAINER" test -d "/root/mailmunge-$VERSION"
if test $? = 0 ; then
if test "$FLAVOR" = "debian" ; then
docker exec "$CONTAINER" dpkg -l mailmunge-base
else
false
fi
if test $? = 0 ; then
if test "$FORCE_REBUILD" = 0 ; then
REBUILD=0
echo "NOTE: /root/mailmunge-$VERSION exists; not rebuilding."
echo "Use '$0 -f' to force a rebuild."
fi
fi
fi
if test "$REBUILD" = 1 ; then
if test "$FLAVOR" = "debian" ; then
# Purge any existing .debs
docker exec "$CONTAINER" /bin/sh -c "dpkg -l mailmunge > /dev/null 2>&1 && apt --assume-yes purge mailmunge mailmunge-base libmailmunge-perl"
# Create a tarball of mailmunge and copy it to the container
make -C .. dist || bailout "make dist failed"
docker cp ../mailmunge-$VERSION.tar.gz "$CONTAINER:/root/" || bailout "docker cp failed"
docker exec "$CONTAINER" /bin/sh -c "cd /root && rm -f *.deb && rm -rf mailmunge-$VERSION && tar xf mailmunge-$VERSION.tar.gz && cd /root/mailmunge-$VERSION && ./configure && dpkg-buildpackage --no-sign && dpkg -i ../libmailmunge-action-boilerplate-perl_${VERSION}_all.deb ../libmailmunge-perl_${VERSION}_all.deb ../libmailmunge-test-getmx-perl_${VERSION}_all.deb ../libmailmunge-test-smtpforward-perl_${VERSION}_all.deb ../libmailmunge-test-spamassassin-perl_${VERSION}_all.deb ../libmailmunge-test-rspamd-perl_${VERSION}_all.deb ../libmailmunge-test-greylist-perl_${VERSION}_all.deb ../libtest-mailmunge-perl_${VERSION}_all.deb ../mailmunge-base_${VERSION}_*.deb ../mailmunge_${VERSION}_all.deb" || bailout "docker exec failed"
else
# Create a tarball of mailmunge and copy it to the container
make -C .. dist || bailout "make dist failed" || bailout "docker exec failed"
docker exec "$CONTAINER" /bin/sh -c "cd /root && rm -rf mailmunge*"
# Remove old rpms
docker exec "$CONTAINER" /bin/sh -c "rpm -qa | grep -i mailmunge | xargs --no-run-if-empty rpm -ev"
docker cp ../mailmunge-$VERSION.tar.gz "$CONTAINER:/root/" || bailout "docker cp failed"
docker exec "$CONTAINER" /bin/sh -c "cd /root && rpmbuild -tb mailmunge-$VERSION.tar.gz && rpm -Uvh /root/rpmbuild/RPMS/noarch/perl-*Mailmunge*.rpm /root/rpmbuild/RPMS/x86_64/mailmunge-$VERSION*.rpm" || bailout "docker exec failed"
fi
fi
# Copy all the test files
docker cp docker-testfiles "$CONTAINER:/root/"
# Copy the test filter
docker exec "$CONTAINER" /bin/sh -c "mkdir -p /etc/mailmunge"
docker cp ../regression-tests/filter/mailmunge-filter.pl "$CONTAINER:/etc/mailmunge/"
docker exec "$CONTAINER" /bin/sh -c "chmod a+rx /etc/mailmunge/mailmunge-filter.pl"
if test "$FLAVOR" = "debian" ; then
docker exec "$CONTAINER" /bin/sh -c "addgroup clamav mailmunge"
fi
if test "$FLAVOR" = "debian" ; then
docker exec "$CONTAINER" /bin/sh -c "cp /root/docker-testfiles/etc-default-mailmunge /etc/default/mailmunge"
docker exec "$CONTAINER" /bin/sh -c "/etc/init.d/mailmunge restart"
docker exec "$CONTAINER" freshclam -v
docker exec "$CONTAINER" /bin/sh -c "/etc/init.d/clamav-daemon restart; /etc/init.d/rsyslog start; /etc/init.d/rspamd start"
else
echo "Starting services..."
docker exec "$CONTAINER" /bin/sh -c "cp /root/docker-testfiles/etc-default-mailmunge /etc/sysconfig/mailmunge"
# Can't use systemd inside a docker container, so use the SysVInit startup file
docker exec "$CONTAINER" /bin/sh -c "cd /root && tar xvf mailmunge-$VERSION.tar.gz && cd /root/mailmunge-$VERSION && ./configure --prefix=/usr --disable-perl-build-artifacts --with-perlinstalldirs=vendor && mkdir -p /etc/init.d && cp /root/mailmunge-$VERSION/sysvinit/mailmunge /etc/init.d/ && chmod a+x /etc/init.d/mailmunge && /etc/init.d/mailmunge restart"
docker exec "$CONTAINER" freshclam -v
docker exec "$CONTAINER" /bin/sh -c "pkill -9 -u _rspamd; mkdir /var/run/clamav; chown clamscan /var/run/clamav; mkdir /var/run/rspamd; chown _rspamd /var/run/rspamd; clamd; syslog-ng" > /dev/null 2>&1
# rspamd on CentOS does something very weird if it daemonizes itself;
# it makes docker exe commands hang. Hence this awful hack
echo "Starting rspamd..."
docker exec "$CONTAINER" /bin/sh -c "rspamd -f -u _rspamd -g _rspamd < /dev/null > /dev/null 2>&1 &"
echo "Waiting for rspamd to get going..."
# Let rspamd start
sleep 15
fi
if test "$MTA" = "postfix" ; then
if test "$FLAVOR" = "debian" ; then
docker exec "$CONTAINER" /bin/sh -c "/etc/init.d/postfix restart"
else
docker exec "$CONTAINER" /bin/sh -c "postfix reload || postfix start || true"
fi
else
docker exec "$CONTAINER" /bin/sh /root/docker-testfiles/qualify-hostname.sh
docker exec "$CONTAINER" /bin/sh -c "pkill sendmail"
if test "$FLAVOR" = "debian" ; then
docker exec "$CONTAINER" /bin/sh -c "/etc/init.d/sendmail restart"
else
docker exec "$CONTAINER" /bin/sh -c "/usr/sbin/sendmail -bd"
fi
fi
docker exec $INTERACTIVE "$CONTAINER" /bin/sh -c "cd /root/mailmunge-$VERSION/regression-tests && prove $VERBOSE $COLOR -l t/*.t" || bailout "Tests failed"