source: bearmail/debian/bearmail-antispam.postinst @ 454

Last change on this file since 454 was 454, checked in by ben, 11 years ago

cleaning

File size: 3.2 KB
Line 
1#!/bin/bash
2set -e
3
4BMPMAS="/etc/bearmail/postfix/master.cf"
5BMPMAI="/etc/bearmail/postfix/main.cf"
6BMDDIR="/etc/bearmail/dspam/"
7BMPAL="/etc/aliases"
8BMDSD="/var/spool/dspam-bearmail"
9
10
11chown dspam:dspam /etc/bearmail/dspam/*{.conf,.prefs}
12
13if [ "$1" = "configure" ]; then
14  # create spool dir and add bearmail to dspam
15  [ -d "$BMDSD" ] || install -m 770 -o dspam -g dspam -d $BMDSD
16  if [ ! "$(grep "^bearmail:" /etc/group | grep dspam)" ] ; then
17    invoke-rc.d dspam stop
18    adduser dspam bearmail
19  fi
20   
21  # check if bearmail was activate
22  if [ -L /etc/mailmap ] ; then
23    bearmail-switch suspend
24    BEARMAIL_ON="1"
25  fi
26
27  # configure master.cf :
28  if [ ! "$(grep "^## bearmail-antispam - EOC" $BMPMAS)" ]; then
29    sed -e '\!^## bearmail-antispam$!a\
30# bearmail dspam filter\
31bearmail_dspam     unix  -       -       n       -       10      lmtp\
32 -o smtp_send_xforward_command=yes\
33 -o disable_mime_output_conversion=yes\
34 -o smtp_generic_maps=\
35\
36# dspam outgoing port\
37127.0.0.1:10027 inet    n       -       n       -       -       smtpd\
38  -o smtpd_authorized_xforward_hosts=127.0.0.0/8\
39  -o smtpd_client_restrictions=\
40  -o smtpd_helo_restrictions=\
41  -o smtpd_sender_restrictions=\
42  -o smtpd_recipient_restrictions=permit_mynetworks,reject\
43  -o mynetworks=127.0.0.0/8\
44  -o receive_override_options=no_unknown_recipient_checks\
45\
46#\
47## bearmail-antispam - EOC
48' -i $BMPMAS
49    sed '/./,/^$/!d' -i $BMPMAS
50  fi
51
52  # configure main.cf
53  if [ ! "$(grep "^# bearmail-antispam - EOC" $BMPMAI)" ]; then
54    sed -e '\!^# bearmail-antispam$!a\
55dspam_destination_recipient_limit = 1\
56# bearmail-antispam - EOC
57' -i $BMPMAI
58  fi
59  if [ ! "$(grep "bearmail-dspam_incoming" $BMPMAI)" ] ; then
60    sed -e '\!^# RCPT TO access restrictions - EOC$!i\
61  check_policy_service inet:127.0.0.1:60000\
62  check_recipient_access pcre:/etc/postfix/bearmail-dspam_incoming
63' -i $BMPMAI
64    sed '/./,/^$/!d' -i $BMPMAI
65  fi
66
67  # conf default dspam
68  if [ "$(grep "^START=no" /etc/default/dspam)" ] ; then
69    sed -e "s/^START=no/START=yes/" -i /etc/default/dspam
70  fi
71
72#  # configure aliases
73  if [ "$(grep "bearmail-dspam_retrain" $BMPAL |grep -v "#")" ]; then
74    if [ ! "$(grep "^bm-spam:.*bearmail-dspam_retrain_spam" $BMPAL)" ]; then
75      echo "Warning: it seems that you changed bearmail-dspam_retrain_spam in $BMPAL"
76      echo "Be sure that you RTFM."
77    fi
78    if [ ! "$(grep "^bm-ham:.*bearmail-dspam_retrain_ham" $BMPAL)" ]; then
79      echo "Warning: it seems that you changed bearmail-dspam_retrain_ham in $BMPAL"
80      echo "Be sure that you RTFM."
81    fi
82  fi
83  if [ ! "$(grep "bearmail-dspam_retrain" $BMPAL |grep -v "#")" ]; then
84    if [ "$(grep "^bm-spam:" $BMPAL)" ]; then
85      echo "Warning: bm-spam exists in $BMPAL but is not configured for bearmail"
86      echo "Please RTFM"
87    else
88      echo "bm-spam: |/usr/lib/bearmail/bearmail-dspam_retrain_spam" >> $BMPAL
89      newaliases
90    fi
91    if [ "$(grep "^bm-ham:" $BMPAL)" ]; then
92      echo "Warning: bm-ham exists in $BMPAL but is not configured for bearmail"
93      echo "Please RTFM"
94    else
95      echo "bm-ham: |/usr/lib/bearmail/bearmail-dspam_retrain_ham" >> $BMPAL
96      newaliases
97    fi
98  fi
99
100  # restart bearmail if needed
101  if [ "$BEARMAIL_ON" ]; then
102    echo "Restarting bearmail"
103    bearmail-switch on
104  fi
105fi 
106#DEBHELPER#
Note: See TracBrowser for help on using the repository browser.