#!/usr/bin/perl -w # Debconf configuration script for spamassassin # Re-written in perl because sh sucks. # Duncan Findlay, May 2003 use Debconf::Client::ConfModule ':all'; # Numerous bug reports were filed about the handling of old # configuration files in /etc/spamassassin. To stem the volume of such # reports, files should be checked against their default md5sums and # automatically deleted if they match. # Why is this so complicated? # 1. I want to make the upgrade from woody as easy as possible. Thus, # if woody's configuration files are present and unmodified, I want to # suggest that they be deleted. # 2. I want to try to detect if # spamproxyd is in use, as it is not present in versions after 2.42-1 # If you can simplify this, be my guest. I'd love a patch. my %md5sums220 = ( '10_misc.cf' => '375793c39e49fba64da80e11c759d82b', '20_body_tests.cf' => '63a69c13b4b058461fd9a54cdb9f3018', '20_head_tests.cf' => '716bfe7de71d7af62be88368426fa4ad', '20_uri_tests.cf' => '0b69de24a719312768bc0e42473e7fab', '25_body_tests_es.cf' => 'e3443e08de32c286923d42ba6c5604d0', '25_body_tests_pl.cf' => 'a7d7783111e978e725fb7a6a3ff1ee45', '25_head_tests_pl.cf' => 'dfcc0ea9493cd4556c89f94788d0c0c0', '30_text_es.cf' => 'b159eee227a3fb31077740633ee284f2', '30_text_pl.cf' => 'e80d3fd80e1fbb4aab2bd317ffdfc94f', '40_spam_phrases.cf' => 'f8bf9b6756225376c72973c221617c70', '50_scores.cf' => 'be92571fcad701fed8e3876c26254161', '60_whitelist.cf' => '13fa135e93eef55704910a448a7b453f', '65_debian.cf' => 'ae26803254c798140d6afac61c5e3d21' ); my $command = shift; if ($command eq "configure") { my $version_raw = shift; if ( !$version_raw ) { exit 0; # not an upgrade } $version_raw =~ /(\d+)\.(\d+)/ or warn "Unknown version!"; my $version_maj = $1; my $version_min = $2; my $offer_quit = 0; if ($version_maj <= 2 && $version_min < 40 ) { if (check_for_spamproxyd()) { my $ret = show_warning("upgrade/2.40w", "critical", 0); $offer_quit = 1 if !$ret; } else { my $ret = show_warning("upgrade/2.40", "high", 0); $offer_quit = 1 if !$ret; } } if ($offer_quit) { my $ret = show_warning("upgrade/cancel", "critical", 1); if (!$ret) { # Not showing critical? Their problem, not mine. go(); my ($ret, $value) = get("spamassassin/upgrade/cancel"); if ($value eq "Cancel") { stop(); exit 1; # They don't want to continue } } } if ($version_maj <= 2 && $version_min <= 42) { if ($version_raw eq "2.20-1woody" && check_for_unmodified_220_files() ) { # We want to set this to yes, but only the first time it's seen. # If it's already been seen, leave it. my ($ret, $value) = fget("spamassassin/upgrade/2.42u", "seen"); if ($value eq "false") { set("spamassassin/upgrade/2.42u", "Yes"); } show_warning("upgrade/2.42u", "medium", 0); } elsif (check_for_old_files()) { show_warning("upgrade/2.42m", "high", 0); } } } elsif ( $command eq "reconfigure" ) { # just offer to delete files if ( check_for_unmodified_220_files() ) { # We want to set this to yes, but only the first time it's seen. # If it's already been seen, leave it. my ($ret, $value) = fget("spamassassin/upgrade/2.42u", "seen"); if ($value eq "false") { set("spamassassin/upgrade/2.42u", "Yes"); } show_warning("upgrade/2.42u", "medium", 0); } elsif (check_for_old_files()) { show_warning("upgrade/2.42m", "high", 1); } } go(); # C'mon, lets go already. # Subroutines sub check_for_unmodified_220_files { foreach $file (keys %md5sums220) { if (-e "/etc/spamassassin/$file") { my $md5sum = `md5sum /etc/spamassassin/$file`; my ($md5) = split (/\s/, $md5sum); if ($md5 ne $md5sums220{$file}) { return 0; # Files have been modified! } } else { return 0; # File deleted... may be admin's choice. Better be # safe than sorry. } } return 1; } sub check_for_spamproxyd { if (open (PS, 'ps ax |')) { while () { if (/spamproxyd/) { close PS; return 1; } } close PS; } else { warn "Can't open pipe from ps."; } return 0; } sub check_for_old_files { my @files = glob("/etc/spamassassin/[0-6][0-9]_*.cf"); if (scalar(@files) > 0) { # files exist return 1; } return 1 if -e "/etc/spamassassin/triplets.txt"; return 1 if -e "/etc/spamassassin/languages"; return 0; } sub show_warning { my ($template, $severity, $reshow) = @_; fset("spamassassin/$template", "seen", "false") if $reshow; my ($ret) = input($severity, "spamassassin/$template"); return $ret; }