2 # last update: jelly+paketi@srce.hr Mon Oct 30 14:37:06 CET 2006
6 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
13 abort-upgrade|abort-remove|abort-deconfigure)
18 echo "postinst called with unknown argument \`$1'" >&2
23 PATH=/bin:/usr/bin:/sbin:/usr/sbin
26 . /usr/share/amavisd-cn/version.sh
27 . /usr/share/carnet-tools/functions.sh
28 . /usr/share/amavisd-cn/variables.sh
29 . /usr/share/amavisd-cn/functions.sh
31 # Place configuration tweaks done on upgrades into this function
33 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
34 # comment out spam alerts if we're upgrading from
35 # << 20030616p10-4 in woody, or << 2:20030616p10-5 in sarge,
36 # or a fresh installation is taking place
37 if dpkg --compare-versions "$2" lt 20030616p10-4 || \
38 { dpkg --compare-versions "$2" ge 2:0 && \
39 dpkg --compare-versions "$2" lt 2:20030616p10-5; }; then
40 if cp_check_and_sed '^\$spam_admin = "spamalert\\@\$mydomain";$' \
41 's/^\(\$spam_admin\b\)/# \1/' $ACONF; then
42 cp_echo "CN: commented \$spam_admin in $ACONF."
43 cp_echo "CN: Be sure to whitelist that address if you reenable it!"
44 cp_echo " If spam detection is enabled for that address, loops may occur."
48 # saner defaults - silently discard viruses, and do SMTP-time reject for
49 # explicitely banned attachments instead of bounces
50 if dpkg --compare-versions "$2" lt 2:20030616p10-8; then
52 '^[ ]*\$final_virus_destiny[ ]*=[ ]*D_BOUNCE' \
53 's/^\([ \t]*\$final_virus_destiny[ \t]*=[ \t]*\)D_BOUNCE/\1D_DISCARD/' \
55 cp_echo "CN: Discarding viruses (option \$final_virus_destiny)."
59 '^[ ]*\$final_banned_destiny[ ]*=[ ]*D_BOUNCE' \
60 's/^\([ \t]*\$final_banned_destiny[ \t]*=[ \t]*\)D_BOUNCE/\1D_REJECT/' \
62 cp_echo "CN: Rejecting banned files at SMTP time (option \$final_banned_destiny)."
66 if dpkg --compare-versions "$2" lt 2:20030616p10-11 && \
67 [ "$domain" != "$host" ]; then
69 '^[ ]*\$mydomain[ ]*=[ ]* ["'"']$host['"'"]' \
70 's/^\([ \t]*\$mydomain[ \t]*=[ \t]*\)["'"']$host['"'"]/\1'"'$domain'"/ \
72 cp_echo "CN: MX for $domain detected, updating \$mydomain."
78 # find out which MTA, assume postfix
81 TMPLVERSION=$POSTTMPLVERSION
82 if dpkg -l postfix | grep -q '^.i'; then
83 . /usr/share/amavisd-cn/postfix.sh
84 elif dpkg -l sendmail | grep -q '^.i'; then
87 TMPLVERSION=$SENDTMPLVERSION
88 . /usr/share/amavisd-cn/sendmail.sh
90 # should never happen, we check for this in preinst too!
91 echo "CN: Ugh, no supported mail-transported-agent could be found?!" >&2
92 echo "CN: If you really have a MTA supported by CARNet installed," >&2
93 echo "CN: Please inform the maintainer. Assuming ${mta}..." >&2
96 # XXX remove at least some of woody cruft for CARNet Debian 2.1+1
97 # convert sweep-cn back to "sweep" account, fix uid/gid
98 if getent passwd sweep > /dev/null; then
99 check_and_update_ugid sweep /etc/sweep /var/lib/sav /var/spool/intercheck /var/log/sweep.log || true
100 # chown stuff I forgot in previous versions
101 if dpkg --compare-versions "$2" lt 20030616p10-3; then
102 chown -R sweep:sweep /var/spool/intercheck /var/log/sweep.log 2> /dev/null || true
104 if cp_check_and_sed viruser s/viruser/sweep/ /etc/cron.d/sweep-cn /usr/bin/sophos-ide-update; then
107 if cp_check_and_sed viruser "s/sweep viruser/sweep/g; s/viruser/sweep/g" /etc/samba/smb.conf; then
108 /etc/init.d/samba reload || true
109 did_sweep="${did_sweep}smb.conf "
114 if getent passwd viruser > /dev/null || [ -n "$did_sweep" ]; then
115 # remove viruser account usage
116 echo -n "CN: Removing viruser: "
117 [ "$did_sweep" ] && echo -n "$did_sweep"
118 if cp_check_and_sed '^viruser' s/viruser/clamav/ $ALIASES; then
119 newaliases 2>&1 > /dev/null
122 if cp_check_and_sed "User viruser" \
123 s/viruser/clamav/ /etc/clamav/clamd.conf; then
126 if cp_check_and_sed "DatabaseOwner viruser" \
127 s/viruser/clamav/ /etc/clamav/freshclam.conf; then
130 if [ -n "$clamav_changed" ]; then
131 # add clamav to amavis group
133 id clamav | grep -q amavis || adduser clamav amavis > /dev/null
135 /etc/init.d/clamav-daemon stop > /dev/null || true
136 pkill -9 /usr/sbin/clamd || true
138 /etc/init.d/clamav-freshclam stop > /dev/null || true
139 pkill -9 /usr/bin/freshclam || true
141 chown -R clamav:clamav \
142 /var/lib/clamav /var/log/clamav /var/run/clamav || true
144 # Don't abort if clamav services do not restart.
145 /etc/init.d/clamav-daemon start > /dev/null || failed clamav-daemon
146 /etc/init.d/clamav-freshclam start > /dev/null || failed clamav-freshclam
149 # We'll catch other changes later, just fix user now
150 if cp_check_and_sed '$daemon_user.*viruser' s/viruser/amavis/g $ACONF; then
153 if getent passwd viruser >/dev/null; then
154 if ls -lnG /var/run/amavis $AHOME |grep -q " $(id -u viruser) " || \
155 pgrep -u viruser -f /usr/sbin/amavis-milter > /dev/null || \
156 pgrep -u viruser amavisd > /dev/null; then
160 if [ -n "$stop_amavisd_now" ]; then
162 if [ -x /etc/init.d/$mta ]; then
163 /etc/init.d/$mta stop > /dev/null
165 # shouldn't happen either XXX catch it and send to maintainer?
166 echo -n "iee, no init script for $mta! ignoring... a"
169 if [ -x /etc/init.d/amavisd-new-milter ]; then
170 /etc/init.d/amavisd-new-milter stop > /dev/null
173 pkill -9 -u viruser -f /usr/sbin/amavis-milter || true
175 /etc/init.d/amavis stop > /dev/null
177 pkill -9 -u viruser -x amavisd || true
178 chown_ahome=1 # do it later
181 [ $mta = sendmail ] && restart_milter=1 || true
184 if getent passwd viruser >/dev/null; then
189 cp_echo -mailonly "CN: Removed user viruser."
192 if cp_check_and_sed viruser s/viruser/clamav/ \
193 /etc/logrotate.d/clamav-daemon /etc/logrotate.d/clamav-freshclam; then
197 # $domain will be equal to $host if nothing better can be found
202 if [ "$mta" = sendmail ]; then
205 fi # end sendmail config
208 if [ "$mta" = postfix ]; then
211 fi # end postfix config
214 if [ -f "$ACONFOLD" ]; then
215 cp_echo "CN: Amavisd configuration is now in $ACONF."
216 cp_echo " Previous location was $ACONFOLD."
217 if [ ! -e "$ACONFMOVED" ]; then
218 mv "$ACONFOLD" "$ACONFMOVED"
219 cp_echo " Old file renamed to $ACONFMOVED."
222 cp_echo "CN: If you made any changes to $ACONFOLD, they will NOT be moved"
223 cp_echo "CN: to the new location automatically. You must update the new file"
224 cp_echo "CN: by yourself, and remove the old file afterwards."
225 elif [ -f "$ACONFMOVED" ]; then
226 cp_echo "CN: Remember to remove the old $ACONFMOVED file."
228 if [ -f $ACONF ]; then
229 if grep -q _CN_ $ACONF; then
230 # This is unlikely, actually
231 if cp_check_and_sed "s/_CN_DOMAIN_/$domain/g; s/_CN_HOST_/$domain/g" $ACONF; then
235 if egrep -q "^\\\$mydomain = 'example.com'" $ACONF; then
236 # Debian default or lame sysadmin detected, replace it by template
238 elif egrep -q "#CARNet#\\\$mydomain = 'example.com';" $ACONF &&
239 dpkg --compare-versions "$2" eq 2:20030616p5-0; then
240 # CARNet Debian 2.1 (sarge) CDROM installation detected
244 # add other fixups to update_conf() above
249 # nonexistent or empty config
250 if [ ! -f $ACONF -o ! -s $ACONF ]; then
251 # Create fresh config from template
256 # if not there, comment it out, if there, uncomment and restart
257 if ! dpkg -l libsavi-perl bunch-perl-modules-cn 2> /dev/null | \
259 ! [ -f /usr/lib/libsavi.so ]; then
260 if cp_check_and_sed "^\['Sophos SAVI'" \
261 "s/^\(\['Sophos SAVI', ..sophos_savi \]\)/#\1/" $ACONF; then
262 cp_echo "CN: Disabled SAVI::Perl usage in ${ACONF}."
263 cp_echo " To enable it, run sophos-sweep-update, uncomment and restart amavis."
266 if cp_check_and_sed "^#\['Sophos SAVI'" \
267 "s/^#\(\['Sophos SAVI', ..sophos_savi \]\)/\1/" $ACONF; then
268 cp_echo "CN: Enabled SAVI::Perl usage in ${ACONF}."
273 check_and_add_alias virusalert root
274 check_and_add_alias spamalert root
276 # touch some required files XXX check if necessary for 2.4
277 if [ ! -f $WLIST ]; then
282 if [ ! -f $BLIST ]; then
287 if [ ! -f $AHOME/.spamassassin/user_prefs ] ; then
288 [ -d $AHOME/.spamassassin ] || mkdir -p $AHOME/.spamassassin
289 cat > $AHOME/.spamassassin/user_prefs <<-EEND
290 bayes_path $AHOME/.spamassassin/bayes
292 auto_whitelist_path $AHOME/.spamassassin/auto-whitelist
297 if [ ! -f $AHOME/.spamassassin/auto-whitelist ] ; then
298 touch $AHOME/.spamassassin/auto-whitelist
303 if [ -x "/etc/init.d/sendmail" -a -e /etc/rc2.d/S20sendmail ]; then
304 update-rc.d -f sendmail remove >/dev/null 2>/dev/null
305 update-rc.d sendmail defaults 21 19 >/dev/null
307 if [ -n "$(find /etc/rc2.d -name S18clam\*)" ]; then
308 update-rc.d -f clamav-daemon remove >/dev/null
309 update-rc.d clamav-daemon defaults 22 18 >/dev/null
312 # Cleanup and finalization
313 if dpkg --compare-versions "$2" lt 2:20030616p10-4; then
314 update-rc.d -f amavisd remove > /dev/null
317 # a complicated way to say chmod 750
318 dpkg-statoverride --remove $AHOME > /dev/null || true
319 dpkg-statoverride --update --add amavis amavis 750 $AHOME
322 if [ -n "$chown_ahome" ]; then
324 echo -n "CN: Fixing ownership in /var/*/amavis... "
325 chown -R amavis:amavis $AHOME /var/run/amavis || true
327 cp_echo -mailonly "CN: Fixed ownerships in /var/*/amavis."
330 # kill naughty pyzor descendants
331 if dpkg --compare-versions "$2" lt "2:20030616p10-7" && \
332 pgrep -u amavis -f '/usr/bin/pyzor check' > /dev/null; then
333 /etc/init.d/amavisd-cn stop
334 pkill -9 -u amavis -f '/usr/bin/pyzor check' > /dev/null || true
335 /etc/init.d/amavisd-cn start
341 # about a half of amavisd-cn script is here
342 if [ "$restart_daemon" -a -x /etc/init.d/amavis.amavisd-new ]; then
343 /etc/init.d/amavis.amavisd-new restart
345 # always check that the daemons are running
346 if ! wait_for_fds amavis; then
347 /etc/init.d/amavis.amavisd-new start
350 if [ "$mta" = sendmail ]; then
351 if [ "$restart_daemon" -a -x /etc/init.d/amavisd-new-milter ]; then
352 /etc/init.d/amavisd-new-milter restart
355 # always check that the daemons are running
356 if ! wait_for_fds milter; then
357 /etc/init.d/amavisd-new-milter start
361 elif [ "$restart_mta" ]; then
362 /etc/init.d/$mta restart
365 # this needs to be updated when $CRONTAB file changes
366 if dpkg --compare-versions "$2" lt "2:20030616p10-4"; then
368 cp_echo "CN: Deleting temp files older than 1 day every day at 01:35 AM"
369 cp_echo "CN: Deleting spam-mail older than 7 days every day at 03:15 AM"
370 cp_echo "CN: Deleting virus-mail older than 7 days every day at 04:25 AM"
371 cp_echo " (can be changed in $CRONTAB)"
373 # display this message just once... maybe use debconf instead
374 if dpkg --compare-versions "$2" lt "2:20030616p10-4"; then
376 cp_echo "CN: To stop, start or restart all of the clamav+amavis+mta components,"
377 cp_echo "CN: use the /etc/init.d/amavisd-cn script."
379 if [ "$failed" ]; then
381 cp_echo "CN: Services $failed failed to restart!"
382 cp_echo "CN: Please check and start manually if needed."
385 # Upgrade, but no automatically changed config;
386 # warn if new template available
387 if [ -n "$2" -a -z "$changed_config" ] && \
388 dpkg --compare-versions "$2" lt "$TMPLVERSION"; then
390 cp_echo "CN: It seems you have upgraded this package from version $2."
391 cp_echo "CN: Configuration template for $mta was modified in version ${TMPLVERSION}."
392 cp_echo " You might want to review the changes, or simply copy the new template and"
393 cp_echo " and replace the _CN_DOMAIN_ string with an adequate value:"
394 cp_echo " cp $ACONFTMPL $ACONF"
395 cp_echo " perl -pi -e 's/_CN_DOMAIN_/$domain/g' $ACONF"
398 cp_mail $PKG $VERSION