5 [ "$1" = "configure" ] || exit 0
6 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
9 . /usr/share/carnet-tools/functions.sh
12 . /usr/share/debconf/confmodule
18 # clean up old debconf questions that are no longer in this package
19 if dpkg --compare-versions "$2" lt "2:3.1.7-4"; then
20 db_unregister spamassassin-cn/usedcc || true
23 db_get spamassassin-cn/usebayes || true
26 db_get spamassassin-cn/userazor2 || true
29 db_get spamassassin-cn/runservice || true
32 db_get spamassassin-cn/runasuser || true
37 # run spamd service as non-root
38 if [ "$run_as_user" = "non-root" ]; then
39 if ! grep -q '^OPTIONS=".*username=spamd"' \
40 /etc/default/spamassassin; then
41 service spamassassin stop
45 if ! getent group spamd >/dev/null 2>&1; then
46 echo "CN: Adding group spamd"
47 addgroup --system spamd >/dev/null 2>&1
49 if ! getent passwd spamd >/dev/null 2>&1; then
50 echo "CN: Adding user spamd"
51 adduser --system --no-create-home --home /etc/spamassassin \
52 --gecos "SpamAssassin User" \
53 --ingroup spamd --disabled-password spamd >/dev/null 2>&1
56 if [ ! -d "/var/run/spamd" ]; then
60 chown -R spamd:spamd /var/run/spamd/
61 dpkg-statoverride --remove /var/run/spamd >/dev/null 2>&1 || true
62 dpkg-statoverride --update --add spamd spamd 755 /var/run/spamd \
63 >/dev/null 2>&1 || true
65 # nope, run spamd as root
66 elif [ "$run_as_user" = "root" ]; then
67 if grep -q '^OPTIONS=".*username=spamd"' \
68 /etc/default/spamassassin; then
69 service spamassassin stop
73 if [ -d "/var/run/spamd" ]; then
76 dpkg-statoverride --remove /var/run/spamd >/dev/null 2>&1 || true
79 examdir="/usr/share/doc/spamassassin-cn/examples"
80 confdir="/etc/spamassassin"
82 # check and replace local.cf if needed
83 if [ -f $examdir/local.cf ]; then
84 # non-existant or zero
85 if [ ! -s $confdir/local.cf ]; then
86 rm -f $confdir/local.cf
90 if [ -s $confdir/local.cf ] &&
91 dpkg --compare-versions "$2" lt "2:3.2.5-4"; then
92 echo "CN: Backing up old version of $confdir/local.cf in /var/backups"
93 cp_backup_conffile $confdir/local.cf
94 rm -f $confdir/local.cf
98 cp -f $examdir/local.cf $confdir/local.cf.$$
100 # merge both configurations
101 if [ -s $confdir/local.cf ]; then
102 #cat $confdir/local.cf > $confdir/local.cf.$$
104 # merge old and new in one conf, primarily respecting old
110 open (NEW, "<", $ARGV[0]);
114 if (/^(\S+)\s+(.+)$/o)
116 my ($key, $value) = ($1, $2);
117 $hash{$key} = $value;
122 # read old configuration
123 open (OLD, "<", $ARGV[1]);
127 if (/^(\S+)\s+(.+)$/o)
129 my ($key, $value) = ($1, $2);
130 delete($hash{$key}) if exists($hash{$key});
139 # print missing configuration lines
142 print $_, " ", $hash{$_}, "\n";
146 perl -e "$script" $confdir/local.cf.$$ $confdir/local.cf > \
147 $confdir/local.cf.$$.$$ && \
148 mv -f $confdir/local.cf.$$.$$ $confdir/local.cf.$$
150 rm -f $confdir/local.cf.$$.$$
153 # set bayes/razor2 in local.cf.$$
154 for i in bayes razor2; do
156 use_value=$(eval echo \$$use_name)
157 if [ "$use_value" = "true" ]; then
162 cp_check_and_sed "^$use_name " \
163 "s/^$use_name .*/$use_name $use_value/g" \
164 $confdir/local.cf.$$ || true
167 # remove obsolete options from old SA
168 egrep -v '^(bayes_use_chi2_combining|ok_languages|use_pyzor|pyzor_|use_dcc|dcc_)' \
169 $confdir/local.cf.$$ > $confdir/local.cf.$$.$$ && \
170 mv -f $confdir/local.cf.$$.$$ $confdir/local.cf.$$
171 rm -f $confdir/local.cf.$$.$$
173 # calculate trusted networks
174 cp_get_netaddr || true
176 # ... get already configured trusted networks
177 trusted_networks=$(awk '/^trusted_networks/ { print $2 }' \
178 $confdir/local.cf.$$ | sed -e 's/,/ /g')
179 # ... merge with local networks configured on eth interfaces
180 for i in $netaddr; do
181 if ! echo "$trusted_networks" | grep -q "$i"; then
182 trusted_networks="$trusted_networks $i"
185 # ... merge with Postfix ranges
186 if [ -x /usr/sbin/postconf ]; then
187 for i in $(postconf -h mynetworks | sed -e 's/,/ /g'); do
188 if ! echo "$trusted_networks" | grep -q "$i"; then
189 trusted_networks="$trusted_networks $i"
193 # ... strip 127/8 range
194 for i in $trusted_networks; do
195 if ! echo "$i" | egrep -q \
196 "127.0.0.0/8|\[::1\]/128|\[::ffff:127.0.0.0\]/104"; then
197 trusted_networks_clean="$trusted_networks_clean $i"
200 # ... strip left and right blanks from final string
201 trusted_networks_clean=$(echo "$trusted_networks_clean" \
202 | sed 's/^[ \t]*//;s/[ \t]*$//')
203 # ... and replace if non-zero
204 if [ ! -z "$trusted_networks_clean" ]; then
205 trusted_networks=$trusted_networks_clean
207 cp_check_and_sed "^trusted_networks " \
208 "s#^trusted_networks .*#trusted_networks $trusted_networks#g" \
209 $confdir/local.cf.$$ || true
210 echo "CN: Activated $trusted_networks as trusted networks"
212 if dpkg --compare-versions "$2" lt "2:3.3.5"; then
213 cp_check_and_sed "^bayes_auto_expire 1" \
214 "s#^bayes_auto_expire .*#bayes_auto_expire 0#g" \
215 $confdir/local.cf.$$ || true
216 echo "CN: Set bayes_auto_expire to 0"
219 # different than template
220 if ! cmp -s $confdir/local.cf.$$ $confdir/local.cf; then
221 # backup if not zero size
222 if [ -s $confdir/local.cf ]; then
223 echo "CN: Backing up old version of $confdir/local.cf in /var/backups"
224 cp_backup_conffile $confdir/local.cf
227 echo "CN: Installing new version of $confdir/local.cf"
228 mv -f $confdir/local.cf.$$ $confdir/local.cf
233 rm -f $confdir/local.cf.$$
236 # enable/disable plugins in SA
237 list=$(find /etc/spamassassin -type f -name 'v*.pre')
241 plugin="loadplugin Mail::SpamAssassin::Plugin::DKIM"
242 cp_check_and_sed "^.*#.*$plugin.*$" \
243 "s/^.*#.*$plugin.*$/$plugin/g" $i.$$ || true
244 if ! cmp -s $i.$$ $i; then
251 plugin="loadplugin Mail::SpamAssassin::Plugin::Pyzor"
252 cp_check_and_sed "^$plugin.*$" \
253 "s/^$plugin.*$/#$plugin/g" $i.$$ || true
254 if ! cmp -s $i.$$ $i; then
261 plugin="loadplugin Mail::SpamAssassin::Plugin::DCC"
262 cp_check_and_sed "^$plugin.*$" \
263 "s/^$plugin.*$/#$plugin/g" $i.$$ || true
264 if ! cmp -s $i.$$ $i; then
271 plugin="loadplugin Mail::SpamAssassin::Plugin::AWL"
272 cp_check_and_sed "^#$plugin.*$" \
273 "s/^#$plugin.*$/$plugin/g" $i.$$ || true
274 if ! cmp -s $i.$$ $i; then
280 # check and replace /etc/default/spamasassin if needed
281 if [ "$run_service" = "true" -a \
282 -f $examdir/etc-default-spamassassin-$run_as_user ]; then
283 if ! cmp -s $examdir/etc-default-spamassassin-$run_as_user \
284 /etc/default/spamassassin; then
285 echo "CN: Backing up old version of /etc/default/spamassassin in /var/backups"
286 cp_backup_conffile /etc/default/spamassassin
288 echo "CN: Installing new version of /etc/default/spamassassin"
289 cp -pf $examdir/etc-default-spamassassin-$run_as_user \
290 /etc/default/spamassassin
296 # do we run spamd at all?
297 if [ "$run_service" = "true" ]; then
303 # enable or disable spamd in /etc/default/spamassassin
304 if [ -f "/etc/default/spamassassin" ]; then
305 cp_check_and_sed '^ENABLED=' \
306 "s/^ENABLED=.*/ENABLED=$i_run_service/g" \
307 /etc/default/spamassassin || true
308 if [ "$run_service" = "true" ]; then
309 echo "CN: Will start spamd by default"
311 echo "CN: Will not start spamd by default"
316 # fix old /razor-agent.log bug
317 if [ -f "/razor-agent.log" ]; then
318 mv -f /razor-agent.log /tmp
319 echo "CN: Moving razor logs (razor-agent.log) to /tmp"
322 # fix razor agent position
323 if [ -f "/etc/razor/razor-agent.conf" ]; then
324 cp_check_and_sed '^.*logfile.*=' \
325 "s,^.*logfile.*=.*,logfile=sys-syslog,g" \
326 /etc/razor/razor-agent.conf || true
331 if getent passwd amavis >/dev/null 2>&1; then
332 AWL=~amavis/.spamassassin/auto-whitelist
334 echo "CN: Cleaning the Amavis auto-whitelist"
335 su -c '/usr/bin/check_whitelist --clean' - amavis >/dev/null 2>&1 \
338 # see if size is still unacceptable
339 SIZE=$(du -ks $AWL | awk '{print $1}')
340 if [ $SIZE -ge 51200 ]; then
341 echo "CN: Size of AWL database > 50MB, doing full cleanup"
348 echo "CN: Importing SpamAssassin channels' public PGP keys"
349 echo "$(date +'%d-%m-%Y %T'): Importing new SA keys..." >> \
350 /var/log/sa-update.log
351 if [ ! -d /etc/spamassassin/sa-update-keys ]; then
352 mkdir -p /etc/spamassassin/sa-update-keys
353 touch /etc/spamassassin/sa-update-keys/pubring.gpg \
354 /etc/spamassassin/sa-update-keys/secring.gpg
355 chmod -R go-rwx /etc/spamassassin/sa-update-keys
357 sa-update --gpghomedir /etc/spamassassin/sa-update-keys --import /etc/spamassassin/sa-keys.pgp \
358 >>/var/log/sa-update.log 2>&1 || true
360 # import http://spamassassin.apache.org/updates/GPG.KEY
361 echo "CN: Importing new http://spamassassin.apache.org/updates/GPG.KEY..."
362 sa-update --gpghomedir /etc/spamassassin/sa-update-keys --import /usr/share/spamassassin-cn/GPG.KEY
364 # clean old RulesDuJour rules
365 echo "CN: Cleaning old RulesDuJour and SARE rules..."
366 rm -rf /etc/spamassassin/*_sare_*.cf /etc/spamassassin/RulesDuJour
367 find /var/lib/spamassassin -iname \*_sare_\* -print0 | xargs -0r rm -rf
368 sed -i -e '/dostech.net/d' /etc/spamassassin/sa-update.channels
369 echo "CN: Please use /etc/spamassassin/sa-update.channels in future!"
371 # clean old sought.rules.yerp.org
372 echo "CN: Cleaning old YERP rules..."
373 find /var/lib/spamassassin -iname \*_yerp_\* -print0 | xargs -0r rm -rf
374 sed -i -e '/sought.rules.yerp.org/d' /etc/spamassassin/sa-update.channels
376 # add spamassassin.heinlein-support.de
377 #echo "CN: Adding spamassassin.heinlein-support.de to /etc/spamassassin/sa-update.channels..."
378 #if ! grep -q spamassassin.heinlein-support.de /etc/spamassassin/sa-update.channels; then
379 # echo spamassassin.heinlein-support.de >> /etc/spamassassin/sa-update.channels
382 # get/update the rules
383 echo "CN: Downloading new SpamAssassin rules and updating in background"
384 echo "$(date +'%d-%m-%Y %T'): Fetching new SA rules..." >> \
385 /var/log/sa-update.log
387 --channelfile /etc/spamassassin/sa-update.channels \
388 --gpghomedir /etc/spamassassin/sa-update-keys \
389 --allowplugins >>/var/log/sa-update.log 2>&1 &
391 echo "CN: SpamAssassin updates are now logged at /var/log/sa-update.log"
393 # restart the spamasassin
394 if [ "x$restart" = "xyes" ]; then
395 pkill -f /usr/sbin/spamd || true
396 service spamassassin restart
400 if [ "x$restart" = "xyes" -a -x /etc/init.d/amavis ]; then
401 service amavis restart
404 # dh_installdeb will replace this with shell code automatically
405 # generated by other debhelper scripts.