2 # postinst script for spamassassin-cn
4 # see: dh_installdeb(1)
8 # summary of how this script can be called:
9 # * <postinst> `configure' <most-recently-configured-version>
10 # * <old-postinst> `abort-upgrade' <new version>
11 # * <conflictor's-postinst> `abort-remove' `in-favour' <package>
13 # * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
14 # <failed-install-package> <version> `removing'
15 # <conflicting-package> <version>
16 # for details, see http://www.debian.org/doc/debian-policy/ or
17 # the debian-policy package
21 configure|reconfigure)
31 . /usr/share/carnet-tools/functions.sh
34 . /usr/share/debconf/confmodule
39 db_get spamassassin-cn/usebayes || true
42 db_get spamassassin-cn/userazor2 || true
45 db_get spamassassin-cn/usedcc || true
48 db_get spamassassin-cn/runservice || true
51 db_get spamassassin-cn/runasuser || true
56 # run spamd service as non-root
57 if [ "$run_as_user" = "non-root" ]; then
58 if ! grep -q '^OPTIONS=".*username=spamd"' \
59 /etc/default/spamassassin; then
60 if [ -x /usr/sbin/invoke-rc.d ]; then
61 invoke-rc.d --quiet spamassassin stop
63 /etc/init.d/spamassassin stop
68 if ! getent group spamd >/dev/null 2>&1; then
69 echo "CN: Adding group spamd"
70 addgroup --system spamd >/dev/null 2>&1
72 if ! getent passwd spamd >/dev/null 2>&1; then
73 echo "CN: Adding user spamd"
74 adduser --system --no-create-home --home /etc/spamassassin \
75 --gecos "SpamAssassin User" \
76 --ingroup spamd --disabled-password spamd >/dev/null 2>&1
79 if [ ! -d "/var/run/spamd" ]; then
83 chown -R spamd:spamd /var/run/spamd/
84 dpkg-statoverride --remove /var/run/spamd >/dev/null 2>&1 || true
85 dpkg-statoverride --update --add spamd spamd 755 /var/run/spamd \
86 >/dev/null 2>&1 || true
88 # nope, run spamd as root
89 elif [ "$run_as_user" = "root" ]; then
90 if grep -q '^OPTIONS=".*username=spamd"' \
91 /etc/default/spamassassin; then
92 if [ -x /usr/sbin/invoke-rc.d ]; then
93 invoke-rc.d --quiet spamassassin stop
95 /etc/init.d/spamassassin stop
100 if [ -d "/var/run/spamd" ]; then
101 rm -rf /var/run/spamd
103 dpkg-statoverride --remove /var/run/spamd >/dev/null 2>&1 || true
106 examdir="/usr/share/doc/spamassassin-cn/examples"
107 confdir="/etc/spamassassin"
109 # check and replace local.cf if needed
110 if [ -f $examdir/local.cf ]; then
111 # non-existant or zero
112 if [ ! -s $confdir/local.cf ]; then
113 rm -f $confdir/local.cf
117 if [ -s $confdir/local.cf ] &&
118 dpkg --compare-versions "$2" lt "2:3.0.3-3"; then
119 echo "CN: Backing up old version of $confdir/local.cf in /var/backups"
120 cp_backup_conffile $confdir/local.cf
121 rm -f $confdir/local.cf
125 cp -f $examdir/local.cf $confdir/local.cf.$$
127 # merge both configurations
128 if [ -s $confdir/local.cf ]; then
129 #cat $confdir/local.cf > $confdir/local.cf.$$
131 # merge old and new in one conf, primarily respecting old
137 open (NEW, "<", $ARGV[0]);
141 if (/^(\S+)\s+(.+)$/o)
143 my ($key, $value) = ($1, $2);
144 $hash{$key} = $value;
149 # read old configuration
150 open (OLD, "<", $ARGV[1]);
154 if (/^(\S+)\s+(.+)$/o)
156 my ($key, $value) = ($1, $2);
157 delete($hash{$key}) if exists($hash{$key});
166 # print missing configuration lines
169 print $_, " ", $hash{$_}, "\n";
173 perl -e "$script" $confdir/local.cf.$$ $confdir/local.cf > \
174 $confdir/local.cf.$$.$$ && \
175 mv -f $confdir/local.cf.$$.$$ $confdir/local.cf.$$
177 rm -f $confdir/local.cf.$$.$$
180 # set bayes/razor2/dcc in local.cf.$$
181 for i in bayes razor2 dcc; do
183 use_value=$(eval echo \$$use_name)
184 if [ "$use_value" = "true" ]; then
189 cp_check_and_sed "^$use_name " \
190 "s/^$use_name .*/$use_name $use_value/g" \
191 $confdir/local.cf.$$ || true
194 # different than template
195 if ! cmp -s $confdir/local.cf.$$ $confdir/local.cf; then
196 # backup if not zero size
197 if [ -s $confdir/local.cf ]; then
198 echo "CN: Backing up old version of $confdir/local.cf in /var/backups"
199 cp_backup_conffile $confdir/local.cf
202 echo "CN: Installing new version of $confdir/local.cf"
203 mv -f $confdir/local.cf.$$ $confdir/local.cf
208 rm -f $confdir/local.cf.$$
211 # enable requested plugins in SA
212 list=$(find /etc/spamassassin -type -f -name 'v*.pre')
214 # enable DCC if requested
215 if [ "$use_dcc" = "true" ]; then
216 plugin="loadplugin Mail::SpamAssassin::Plugin::DCC"
217 cp_check_and_sed "^.*#.*$plugin.*$" \
218 "s/^.*#.*$plugin.*$/$plugin/g" $i.$$ || true
219 if ! cmp -s $i.$$ $i; then
226 plugin="loadplugin Mail::SpamAssassin::Plugin::DKIM"
227 cp_check_and_sed "^.*#.*$plugin.*$" \
228 "s/^.*#.*$plugin.*$/$plugin/g" $i.$$ || true
229 if ! cmp -s $i.$$ $i; then
235 # check and replace /etc/default/spamasassin if needed
236 if [ "$run_service" = "true" -a \
237 -f $examdir/etc-default-spamassassin-$run_as_user ]; then
238 if ! cmp -s $examdir/etc-default-spamassassin-$run_as_user \
239 /etc/default/spamassassin; then
240 echo "CN: Backing up old version of /etc/default/spamassassin in /var/backups"
241 cp_backup_conffile /etc/default/spamassassin
243 echo "CN: Installing new version of /etc/default/spamassassin"
244 cp -pf $examdir/etc-default-spamassassin-$run_as_user \
245 /etc/default/spamassassin
251 # do we run spamd at all?
252 if [ "$run_service" = "true" ]; then
258 # enable or disable spamd in /etc/default/spamassassin
259 if [ -f "/etc/default/spamassassin" ]; then
260 cp_check_and_sed '^ENABLED=' \
261 "s/^ENABLED=.*/ENABLED=$i_run_service/g" \
262 /etc/default/spamassassin || true
263 if [ "$run_service" = "true" ]; then
264 echo "CN: Will start spamd by default"
266 echo "CN: Will not start spamd by default"
271 # fix old /razor-agent.log bug
272 if [ -f "/razor-agent.log" ]; then
273 mv -f /razor-agent.log /tmp
274 echo "CN: Moving razor logs (razor-agent.log) to /tmp"
277 # fix razor agent position
278 if [ -f "/etc/razor/razor-agent.conf" ]; then
279 cp_check_and_sed '^.*logfile.*=' \
280 "s,^.*logfile.*=.*,logfile=sys-syslog,g" \
281 /etc/razor/razor-agent.conf || true
286 if getent passwd amavis >/dev/null 2>&1; then
287 if [ -s ~amavis/.spamassassin/auto-whitelist ]; then
288 echo "CN: Cleaning the Amavis auto-whitelist"
289 su -c '/usr/bin/check_whitelist --clean' - amavis >/dev/null 2>&1 \
295 echo "CN: Importing SpamAssassin and SARE public PGP keys"
296 echo "$(date +'%d-%m-%Y %T'): Importing new SA keys..." >> \
297 /var/log/sa-update.log
298 if [ ! -d /etc/spamassassin/sa-update-keys ]; then
299 mkdir -p /etc/spamassassin/sa-update-keys
300 touch /etc/spamassassin/sa-update-keys/pubring.gpg \
301 /etc/spamassassin/sa-update-keys/secring.gpg
302 chmod -R go-rwx /etc/spamassassin/sa-update-keys
304 sa-update --import /etc/spamassassin/sa-keys.pgp \
305 >>/var/log/sa-update.log 2>&1 || true
307 # clean old RulesDuJour rules
308 echo "CN: Cleaning old RulesDuJour and SARE rules..."
309 rm -rf /etc/spamassassin/*_sare_*.cf /etc/spamassassin/RulesDuJour
310 echo "CN: Please use /etc/spamassassin/sa-update.channels in future!"
312 # get/update the rules
313 echo "CN: Downloading new SpamAssassin rules and updating in background"
314 echo "$(date +'%d-%m-%Y %T'): Fetching new SA rules..." >> \
315 /var/log/sa-update.log
317 --channelfile /etc/spamassassin/sa-update.channels \
320 --gpgkey BDE9DC10 >>/var/log/sa-update.log 2>&1 || true
321 echo "CN: SpamAssassin updates are now logged at /var/log/sa-update.log"
323 # restart the spamasassin
324 if [ "x$restart" = "xyes" ]; then
325 if [ -x /usr/sbin/invoke-rc.d ]; then
326 pkill -f /usr/sbin/spamd || true
327 invoke-rc.d --quiet spamassassin restart
329 /etc/init.d/spamassassin restart
334 if [ "x$restart" = "xyes" -a -x /etc/init.d/amavis ]; then
335 if [ -x /usr/sbin/invoke-rc.d ]; then
336 invoke-rc.d --quiet amavis restart
338 /etc/init.d/amavis restart
342 # dh_installdeb will replace this with shell code automatically
343 # generated by other debhelper scripts.