v5/debian/DEBIAN/postinst
Jerry.Benton f63299c7bf update
none
2016-05-10 23:46:21 -04:00

250 lines
7.7 KiB
Bash

#!/bin/sh
# postinst script for MailScanner
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <postinst> `configure' <most-recently-configured-version>
# * <old-postinst> `abort-upgrade' <new version>
# * <conflictor's-postinst> `abort-remove' `in-favour' <package>
# <new-version>
# * <postinst> `abort-remove'
# * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
# <failed-install-package> <version> `removing'
# <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
MSVERSION=VersionNumberHere
# group for users to run under
if ! getent group mtagroup >/dev/null 2>&1; then
groupadd -f mtagroup >/dev/null 2>&1
fi
# check for common users and add to the mtagroup
if id -u clam >/dev/null 2>&1; then
usermod -a -G mtagroup clam >/dev/null 2>&1
fi
if id -u clamav >/dev/null 2>&1; then
usermod -a -G mtagroup clamav >/dev/null 2>&1
fi
if id -u clamscan >/dev/null 2>&1; then
usermod -a -G mtagroup clamscan >/dev/null 2>&1
fi
if id -u vscan >/dev/null 2>&1; then
usermod -a -G mtagroup vscan >/dev/null 2>&1
fi
if id -u sophosav >/dev/null 2>&1; then
usermod -a -G mtagroup sophosav >/dev/null 2>&1
fi
if id -u Debian-exim >/dev/null 2>&1; then
usermod -a -G mtagroup Debian-exim >/dev/null 2>&1
fi
if id -u postfix >/dev/null 2>&1; then
usermod -a -G mtagroup postfix >/dev/null 2>&1
fi
if id -u mail >/dev/null 2>&1; then
usermod -a -G mtagroup mail >/dev/null 2>&1
fi
if [ ! -d '/var/spool/MailScanner/archive' ]; then
mkdir -p /var/spool/MailScanner/archive
fi
if [ ! -d '/var/spool/MailScanner/incoming' ]; then
mkdir -p /var/spool/MailScanner/incoming
fi
if [ ! -d '/var/spool/MailScanner/quarantine' ]; then
mkdir -p /var/spool/MailScanner/quarantine
fi
if [ -d '/var/spool/exim4.in' ]; then
install -d -oDebian-exim -gmtagroup -m0750 /var/spool/exim4.in
install -d -oDebian-exim -gmtagroup -m0750 /var/spool/exim4.in/db
install -d -oDebian-exim -gmtagroup -m0750 /var/spool/exim4.in/input
install -d -oDebian-exim -gmtagroup -m0750 /var/spool/exim4.in/msglog
fi
if [ ! -d '/var/spool/mqueue.in' ]; then
perl -pi -e 's{Incoming Queue Dir = /var/spool/mqueue.in}{Incoming Queue Dir = /var/spool/mqueue}g;' /etc/MailScanner/MailScanner.conf
fi
# lock down some directory permissions
install -d -omail -gmtagroup -m0775 /var/spool/MailScanner/incoming
install -d -omail -gmtagroup -m0775 /var/spool/MailScanner/quarantine
if [ -d '/etc/MailScanner/custom' -o -L '/etc/MailScanner/custom' ]; then
rm -f /etc/MailScanner/custom
fi
# softlink for custom functions
if [ -d '/usr/share/MailScanner/perl/custom' -a ! -L '/etc/MailScanner/custom' ]; then
ln -s /usr/share/MailScanner/perl/custom /etc/MailScanner/custom
fi
# softlink for reports
if [ -d '/usr/share/MailScanner/reports' -a ! -L '/etc/MailScanner/reports' ]; then
ln -s /usr/share/MailScanner/reports /etc/MailScanner/reports
fi
# update web bug link
OLD="^Web Bug Replacement.*";
NEW="Web Bug Replacement = https\:\/\/s3\.amazonaws\.com\/msv5\/images\/spacer\.gif";
if [ -f '/etc/MailScanner/MailScanner.conf' ]; then
sed -i "s/${OLD}/${NEW}/g" /etc/MailScanner/MailScanner.conf
fi
# fix reports directory
OLDTHING='\/etc\/MailScanner\/reports';
NEWTHING='\/usr\/share\/MailScanner\/reports';
if [ -f '/etc/MailScanner/MailScanner.conf' ]; then
sed -i "s/${OLDTHING}/${NEWTHING}/g" /etc/MailScanner/MailScanner.conf
fi
# fix custom functions directory
OLDTHING='^Custom Functions Dir.*';
NEWTHING='Custom Functions Dir = \/usr\/share\/MailScanner\/perl\/custom';
if [ -f '/etc/MailScanner/MailScanner.conf' ]; then
sed -i "s/${OLDTHING}/${NEWTHING}/g" /etc/MailScanner/MailScanner.conf
fi
# remove old link if present
if [ -L '/etc/mail/spamassassin/mailscanner.cf' ]; then
rm -f /etc/mail/spamassassin/mailscanner.cf
fi
if [ -L '/etc/mail/spamassassin/MailScanner.cf' ]; then
rm -f /etc/mail/spamassassin/MailScanner.cf
fi
if [ -f '/etc/MailScanner/spam.assassin.prefs.conf' ]; then
mv -f /etc/MailScanner/spam.assassin.prefs.conf /etc/MailScanner/spamassassin.conf
fi
# create symlink for spamasassin
if [ -d '/etc/mail/spamassassin' -a ! -L '/etc/mail/spamassassin/MailScanner.cf' -a -f '/etc/MailScanner/spamassassin.conf' -a ! -f '/etc/mail/spamassassin/MailScanner.cf' ]; then
ln -s /etc/MailScanner/spamassassin.conf /etc/mail/spamassassin/MailScanner.cf
fi
# add symlink to init script
if [ ! -L '/etc/init.d/mailscanner' ]; then
ln -s /usr/lib/MailScanner/init/ms-init /etc/init.d/mailscanner
fi
# create if missing
[ -d '/etc/MailScanner/conf.d' ] || mkdir -p /etc/MailScanner/conf.d
# fix the clamav wrapper if the user does not exist
if [ -d '/etc/clamav' ]; then
DISTROCAVUSER='ClamUser="clamav"';
DISTROCAVGRP='ClamGroup="clamav"';
# check for common users and add to the mtagroup
if id -u clam >/dev/null 2>&1; then
CAVUSR='ClamUser="clam"';
fi
if id -u clamav >/dev/null 2>&1; then
CAVUSR='ClamUser="clamav"';
fi
if id -u clamscan >/dev/null 2>&1; then
CAVUSR='ClamUser="clamscan"';
fi
if getent group clamav >/dev/null 2>&1; then
CAVGRP='ClamGroup="clamav"';
fi
if getent group clam >/dev/null 2>&1; then
CAVGRP='ClamGroup="clam"';
fi
if getent group clamscan >/dev/null 2>&1; then
CAVGRP='ClamGroup="clamscan"';
fi
if [ -f '/usr/lib/MailScanner/wrapper/clamav-wrapper' ]; then
sed -i "s/${DISTROCAVUSER}/${CAVUSR}/g" /usr/lib/MailScanner/wrapper/clamav-wrapper
sed -i "s/${DISTROCAVGRP}/${CAVGRP}/g" /usr/lib/MailScanner/wrapper/clamav-wrapper
fi
if [ -f '/etc/apparmor.d/usr.sbin.clamd' ]; then
# add to include for clamd
if [ -f '/etc/apparmor.d/local/usr.sbin.clamd' ]; then
DEFAULTAPPARMOR='#include <local\/usr.sbin.clamd>';
APPARMORFIX=' include local\/usr.sbin.clamd';
# enable include directory
sed -i "s/${DEFAULTAPPARMOR}/${APPARMORFIX}/g" /etc/apparmor.d/usr.sbin.clamd
grep '/vat/spool/MailScanner/incoming/\*\* krw,' /etc/apparmor.d/local/usr.sbin.clamd
RETVAL="$?"
if [ $RETVAL -ne 0 ]; then
echo '/var/spool/MailScanner/incoming/** krw,' >> /etc/apparmor.d/local/usr.sbin.clamd
fi
grep '/var/spool/MailScanner/incoming/** ix,' /etc/apparmor.d/local/usr.sbin.clamd
RETVAL="$?"
if [ $RETVAL -ne 0 ]; then
echo '/var/spool/MailScanner/incoming/** ix,' >> /etc/apparmor.d/local/usr.sbin.clamd
fi
fi
fi
# fix old style clamav Monitors if preset in old mailscanner.conf
CAVOLD='^Monitors for ClamAV Updates.*';
CAVNEW='Monitors for ClamAV Updates = \/usr\/local\/share\/clamav\/\*\.cld \/usr\/local\/share\/clamav\/\*\.cvd \/var\/lib\/clamav\/\*\.inc\/\* \/var\/lib\/clamav\/\*\.\?db \/var\/lib\/clamav\/\*\.cvd';
if [ -f '/etc/MailScanner/MailScanner.conf' ]; then
sed -i "s/${CAVOLD}/${CAVNEW}/g" /etc/MailScanner/MailScanner.conf
fi
fi
# set the correct sock for debian systems
CAVOLD='^Clamd Socket.*';
CAVNEW='Clamd Socket = \/var\/run\/clamav\/clamd\.ctl';
if [ -f '/etc/MailScanner/MailScanner.conf' ]; then
sed -i "s/${CAVOLD}/${CAVNEW}/g" /etc/MailScanner/MailScanner.conf
fi
# set the correct lock file for debian systems
CAVOLD='^Clamd Lock File.*';
CAVNEW='Clamd Lock File = \/var\/run\/clamav\/clamd\.pid';
if [ -f '/etc/MailScanner/MailScanner.conf' ]; then
sed -i "s/${CAVOLD}/${CAVNEW}/g" /etc/MailScanner/MailScanner.conf
fi
# allow supplementary groups
CAVOLD='^#AllowSupplementaryGroups.*';
CAVNEW='AllowSupplementaryGroups yes';
if [ -f '/etc/clamav/clamd.conf' ]; then
sed -i "s/${CAVOLD}/${CAVNEW}/g" /etc/clamav/clamd.conf
fi
# postfix fix
if [ -f '/etc/postfix/master.cf' ]; then
sed -i "s/pickup unix/pickup fifo/g" /etc/postfix/master.cf
sed -i "s/qmgr unix/qmgr fifo/g" /etc/postfix/master.cf
fi
update-rc.d mailscanner defaults 80 20
exit 0