v5/debian/DEBIAN/postinst
Mark Sapiro 71b0ffd1cc Remove invalid change of '#include' to 'include' in (#236)
/etc/apparmor.d/usr.sbin.clamd.
2018-10-05 18:18:44 -04:00

303 lines
9.5 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
# save directory
SAVEDIR="$HOME/ms_upgrade/saved.$$";
# 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 id -u avast >/dev/null 2>&1; then
usermod -a -G mtagroup avast >/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/MailScanner/milterin' ]; then
mkdir -p /var/spool/MailScanner/milterin
fi
if [ ! -d '/var/spool/MailScanner/milterout' ]; then
mkdir -p /var/spool/MailScanner/milterout
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/archive
install -d -omail -gmtagroup -m0775 /var/spool/MailScanner/incoming
install -d -omail -gmtagroup -m0775 /var/spool/MailScanner/quarantine
install -d -omail -gmtagroup -m0775 /var/spool/MailScanner/milterin
install -d -omail -gmtagroup -m0775 /var/spool/MailScanner/milterout
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
# 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
# remove old symlink if present
if [ -L '/etc/init.d/mailscanner' ]; then
rm -f /etc/init.d/mailscanner
fi
# remove old file if present
if [ -f '/etc/init.d/mailscanner' ]; then
rm -f /etc/init.d/mailscanner
fi
# remove old symlink if present
if [ -L '/etc/init.d/MailScanner' ]; then
rm -f /etc/init.d/MailScanner
fi
# remove old file if present
if [ -f '/etc/init.d/MailScanner' ]; then
rm -f /etc/init.d/MailScanner
fi
# remove old symlink if present
if [ -L '/etc/init.d/msmilter' ]; then
rm -f /etc/init.d/msmilter
fi
# remove old file if present
if [ -f '/etc/init.d/msmilter' ]; then
rm -f /etc/init.d/msmilter
fi
# remove old systemd file if present
if [ -f '/lib/systemd/system/mailscanner.service' ]; then
rm -f /lib/systemd/system/mailscanner.service
fi
# remove old systemd file if present
if [ -f '/lib/systemd/system/msmilter.service' ]; then
rm -f /lib/systemd/system/msmilter.service
fi
# Check for systemd
if [ -f '/lib/systemd/systemd' -o -f '/usr/lib/systemd/systemd' ]; then
cp /usr/lib/MailScanner/systemd/ms-systemd /lib/systemd/system/mailscanner.service
chmod -x /lib/systemd/system/mailscanner.service
cp /usr/lib/MailScanner/systemd/ms-milter /lib/systemd/system/msmilter.service
chmod -x /lib/systemd/system/msmilter.service
# add symlink to init script
elif [ ! -L '/etc/init.d/mailscanner' ]; then
ln -s /usr/lib/MailScanner/init/ms-init /etc/init.d/mailscanner
ln -s /usr/lib/MailScanner/init/msmilter-init /etc/init.d/msmilter
fi
# create if missing
[ -d '/etc/MailScanner/conf.d' ] || mkdir -p /etc/MailScanner/conf.d
# upgrade the old config
if [ -f /etc/MailScanner/MailScanner.conf.original -a -f /etc/MailScanner/MailScanner.conf ]; then
cp -f /etc/MailScanner/MailScanner.conf /etc/MailScanner/MailScanner.conf.dist
ms-upgrade-conf /etc/MailScanner/MailScanner.conf.original /etc/MailScanner/MailScanner.conf.dist > /etc/MailScanner/MailScanner.conf
mkdir -p ${SAVEDIR}/etc/MailScanner
mv -f /etc/MailScanner/MailScanner.conf.* ${SAVEDIR}/etc/MailScanner > /dev/null 2>&1
cp -f /etc/MailScanner/MailScanner.conf ${SAVEDIR}/etc/MailScanner/MailScanner.new > /dev/null 2>&1
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
# 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
echo '/var/spool/MailScanner/incoming/** krw,' > /etc/apparmor.d/local/usr.sbin.clamd
echo '/var/spool/MailScanner/incoming/** ix,' >> /etc/apparmor.d/local/usr.sbin.clamd
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 =';
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 true';
if [ -f '/etc/clamav/clamd.conf' ]; then
sed -i "s/${CAVOLD}/${CAVNEW}/g" /etc/clamav/clamd.conf
fi
if [ -f '/lib/systemd/systemd' -o -f '/usr/lib/systemd/systemd' ]; then
systemctl enable mailscanner.service
else
update-rc.d mailscanner defaults 80 80
fi
exit 0