odvajanje samo razmakom (radi i s zarezom, ali defaultna konfiguracija koristi razmak)
[postfix-cn.git] / debian / postinst
1 #!/bin/sh
2
3 set -e
4
5 [ "$1" = "configure" ] || exit 0
6 [ "$DEBIAN_SCRIPT_DEBUG" ] && set -vx
7
8 # Load CARNet Tools
9 . /usr/share/carnet-tools/functions.sh
10 # Load Debconf
11 . /usr/share/debconf/confmodule
12
13 db_get postfix-cn/rbl || true
14 rbl="$RET"
15
16 # Tue, 19 Dec 2006 10:31:01 +0100
17 # relays.ordb.org se gasi 2006-12-31
18 if echo $rbl | grep -q relays.ordb.org; then
19   rbl="`echo $rbl | sed 's/relays.ordb.org, //g'`"
20   # za svaki slucaj, ako je na kraju
21   rbl="`echo $rbl | sed 's/relays.ordb.org//g'`"
22   db_set postfix-cn/rbl "$rbl" || true
23 fi
24
25 # Thu, 21 Dec 2006 09:03:50 +0100
26 # opm.blitzed.org je ugasen 2006-05
27 if echo $rbl | grep -q opm.blitzed.org; then
28   rbl="`echo $rbl | sed 's/opm.blitzed.org, //g'`"
29   # za svaki slucaj, ako je na kraju
30   rbl="`echo $rbl | sed 's/opm.blitzed.org//g'`"
31   db_set postfix-cn/rbl "$rbl" || true
32 fi
33
34 # Wed, 12 Jun 2013 15:15:28 +0200
35 # dnsbl.njabl.org je ugasen 2013-03
36 if echo $rbl | grep -q dnsbl.njabl.org; then
37   rbl="`echo $rbl | sed 's/dnsbl.njabl.org, //g'`"
38   # za svaki slucaj, ako je na kraju
39   rbl="`echo $rbl | sed 's/dnsbl.njabl.org//g'`"
40   db_set postfix-cn/rbl "$rbl" || true
41 fi
42
43 db_get postfix-cn/matchgecos || true
44
45 db_get postfix-cn/matchgecos || true
46 matchgecos="$RET"
47
48 hostname="`hostname`"
49 fqdn="`hostname --fqdn`"
50 domain="`dnsdomainname`"
51 mailname="`cat /etc/mailname 2> /dev/null || hostname --fqdn`"
52 cp_get_netaddr || true
53 netaddr="$RET"
54
55 # ako ne postoje konfiguracijske datoteke, napravi ih
56 [ -f /etc/postfix/master.cf ] || touch /etc/postfix/master.cf
57 [ -f /etc/postfix/main.cf ] || touch /etc/postfix/main.cf
58
59 # spremi pocetnu verziju
60 cp -pf /etc/postfix/master.cf /etc/postfix/master.cf.dpkg-tmp.$$
61 cp -pf /etc/postfix/main.cf /etc/postfix/main.cf.dpkg-tmp.$$
62
63 # srediti master.cf za TLS
64 if [ -f /etc/postfix/master.cf ]; then
65   cp_check_and_sed '^#tlsmgr' \
66                    's/^#tlsmgr/tlsmgr/g' \
67                    /etc/postfix/master.cf || true
68
69   cp_check_and_sed '^#smtps' \
70                    's/^#smtps/smtps/g' \
71                    /etc/postfix/master.cf || true
72 fi
73
74 # ovo manje/vise uzima kao default, ali u slucaju da je multihomed stroj,
75 # i eventualno je sprckan, mozda nesto nece raditi kako spada pa cemo konfigurirati
76 postconf -e myhostname="$fqdn"
77 postconf -e mydomain="$domain"
78 postconf -e myorigin="$mailname"
79
80 # zbog problema sa squirrelmailom
81 postconf -e append_dot_mydomain="yes"
82 postconf -e append_at_myorigin="yes"
83
84 # dodaj 127.0.0.0/8, netaddr i ipv6-localhost
85 mynetworks="`postconf -h mynetworks`"
86 for i in "127.0.0.0/8" "$netaddr" "[::1]/128"; do
87   if ! echo $mynetworks | grep -q $i; then
88    mynetworks="$mynetworks $i"
89   fi
90 done
91 postconf -e mynetworks="$mynetworks"
92
93 # obrisati $mydomain, ako je upgrade sa starije verzije
94 # te srediti mydestination
95 if dpkg --compare-versions "$2" lt 2.3.8-2; then
96   mydestination="`postconf -h mydestination`"
97   if echo $mydestination | grep -q ", \$mydomain"; then
98     mydestination="`echo $mydestination | sed 's/, \$mydomain//g'`"
99   fi
100   if ! echo $mydestination | grep -q "localhost.\$mydomain"; then
101     mydestination="$mydestination, localhost.\$mydomain"
102   fi
103   if ! echo $mydestination | grep -q "\$myhostname"; then
104     mydestination="\$myhostname, $mydestination"
105   fi
106   postconf -e mydestination="$mydestination"
107 fi
108
109 # default je: $myhostname, localhost.$mydomain, localhost
110 # treba dodati jos ", $mydomain", ako je host mx
111 cp_get_mx_domain || true
112 mx_domain="$RET"
113 if [ "$mx_domain" != "$fqdn" ]; then
114   mydestination="`postconf -h mydestination`"
115   if ! echo $mydestination | grep -q ", \$mydomain"; then
116     postconf -e mydestination="$mydestination, \$mydomain"
117   fi
118   postconf -e relay_domains="\$mydestination"
119   if [ "$mx_domain" != "$domain" ]; then
120     if dpkg --compare-versions "$2" lt 2.1.5-8; then
121       cp_echo "CN: This host is MX for more than one domain! postfix-cn package will"
122       cp_echo "CN: only set up $mx_domain, you HAVE TO add the other domains manually"
123       cp_echo "CN: to mydestination variable in /etc/postfix/main.cf, if you haven't"
124       cp_echo "CN: done that already or you may lose mail."
125     fi
126   fi
127 fi
128
129 # sredi $alias_maps
130 if [ "$matchgecos" = "true" ]; then
131   aliasmaps="hash:/etc/aliases hash:/var/lib/postfix-cn/aliases_gecos"
132 elif [ "$matchgecos" = "false" ]; then
133   aliasmaps="hash:/etc/aliases"
134   alias_maps="`postconf -h alias_maps | \
135                sed -e 's#hash:/var/lib/postfix-cn/aliases_gecos,*##g' -e 's/,*[[:space:]]*$//g'`"
136   postconf -e alias_maps="$alias_maps"
137 fi
138
139 for i in $aliasmaps; do
140   alias_maps="`postconf -h alias_maps`"
141   if ! echo $alias_maps | grep -q "$i"; then
142     postconf -e alias_maps="$alias_maps, $i"
143   fi
144 done
145
146 postconf -e alias_database="hash:/etc/aliases"
147 postconf -e local_recipient_maps="proxy:unix:passwd.byname \$alias_maps"
148
149 # jos malo
150 postconf -e recipient_delimiter="+"
151 postconf -e smtpd_helo_required="yes"
152 postconf -e smtpd_helo_restrictions="permit_mynetworks"
153 postconf -e in_flow_delay="2s"
154 postconf -e initial_destination_concurrency="10"
155 postconf -e default_destination_concurrency_limit="30"
156 postconf -e smtpd_recipient_limit="400"
157 postconf -e hash_queue_depth="3"
158
159 if dpkg --compare-versions "$2" lt 2.1.5-6; then
160   postconf -e bounce_queue_lifetime="5d"
161   postconf -e maximal_queue_lifetime="5d"
162 fi
163
164 # ako netko zeli maknuti maskiranje, da mu ga nova verzija ne doda
165 if dpkg --compare-versions "$2" lt 2.1.5-2; then
166   postconf -e masquerade_domains="\$mydomain"
167 fi
168
169 # sredi smtpd_recipient_restrictions
170 smtpd_recipient_restrictions="reject_invalid_hostname, \
171                               reject_unknown_sender_domain, \
172                               reject_unknown_recipient_domain, \
173                               reject_unauth_pipelining, \
174                               permit_sasl_authenticated, \
175                               permit_mynetworks, \
176                               reject_unauth_destination"
177
178 # dodaj samo rbl-ove iz debconfa
179 if [ "$rbl" ]; then
180   for i in `echo $rbl | tr -d ,`; do
181     smtpd_recipient_restrictions="$smtpd_recipient_restrictions, reject_rbl_client $i"
182   done
183 fi
184
185 # dodaj permit na kraj
186 smtpd_recipient_restrictions="$smtpd_recipient_restrictions, permit"
187 postconf -e smtpd_recipient_restrictions="$smtpd_recipient_restrictions"
188
189 # SASL stuff
190 postconf -e smtpd_sasl_auth_enable="yes"
191 postconf -e smtpd_sasl_security_options="noanonymous"
192 postconf -e smtpd_sasl_local_domain="\$myhostname"
193 postconf -e broken_sasl_auth_clients="yes"
194
195 [ -d /etc/postfix/sasl/ ] || mkdir -p /etc/postfix/sasl/
196 if [ ! -f /etc/postfix/sasl/smtpd.conf ]; then
197   cat - > /etc/postfix/sasl/smtpd.conf <<EOF
198 pwcheck_method: saslauthd
199 mech_list: plain login
200 EOF
201   restart_postfix="yes"
202 fi
203
204 if [ -f /etc/default/saslauthd ]; then
205   cp_check_and_sed "^START=no" \
206                    "s/^START=no/START=yes/g" \
207                    /etc/default/saslauthd && restart_saslauthd="yes"
208
209   cp_check_and_sed "^#[[:blank:]]*START=" \
210                    "s/^#[[:blank:]]*START=.*$/START=yes/g" \
211                    /etc/default/saslauthd && restart_saslauthd="yes"
212
213   if ! grep -q "^START.*yes" /etc/default/saslauthd; then
214     echo "START=yes" >> /etc/default/saslauthd
215     restart_saslauthd="yes"
216   fi
217
218   if ! grep -q "^OPTIONS.*/var/spool/postfix/var/run/saslauthd" /etc/default/saslauthd; then
219     echo "OPTIONS=\"-c -m /var/spool/postfix/var/run/saslauthd\"" >> /etc/default/saslauthd
220     restart_saslauthd="yes"
221   fi
222
223   if ! grep -q "&& ln -s" /etc/default/saslauthd; then
224     echo "[ ! -L /var/run/saslauthd -a -d /var/spool/postfix/var/run/saslauthd -a ! -d /var/run/saslauthd ] && ln -s /var/spool/postfix/var/run/saslauthd /var/run/saslauthd || true" >> /etc/default/saslauthd
225     restart_saslauthd="yes"
226   fi
227
228   if [ ! -L /var/run/saslauthd ]; then
229     mkdir -p /var/spool/postfix/var/run/
230     if [ -d /var/run/saslauthd -a ! -d /var/spool/postfix/var/run/saslauthd ]; then
231       mv /var/run/saslauthd /var/spool/postfix/var/run/
232     elif [ -d /var/run/saslauthd -a -d /var/spool/postfix/var/run/saslauthd ]; then
233       rm -rf /var/run/saslauthd/
234     fi
235     # XXX jos kad bi ln -s u /var/run/ radio (bootclean.sh)
236     if [ -d /var/spool/postfix/var/run/saslauthd -a ! -d /var/run/saslauthd ]; then
237       ln -s /var/spool/postfix/var/run/saslauthd /var/run/saslauthd
238     fi
239     restart_saslauthd="yes"
240   fi
241
242   if [ ! -d /var/spool/postfix/var/run/saslauthd ]; then
243     mkdir -p /var/spool/postfix/var/run/saslauthd
244     restart_saslauthd="yes"
245   fi
246
247   if ! dpkg-statoverride --list /var/spool/postfix/var/run/saslauthd > /dev/null; then
248     dpkg-statoverride --update --add root sasl 710 /var/spool/postfix/var/run/saslauthd
249   fi
250 fi
251
252 # restart saslauthd
253 if [ "$restart_saslauthd" = "yes" ]; then
254   if [ -x /usr/sbin/invoke-rc.d ]; then
255     [ -x /etc/init.d/saslauthd ] && invoke-rc.d saslauthd restart
256   else
257     [ -x /etc/init.d/saslauthd ] && /etc/init.d/saslauthd restart
258   fi
259 fi
260
261 # TLS stuff
262 postconf -e smtp_tls_security_level="may"
263 postconf -e smtp_tls_session_cache_database="sdbm:/var/lib/postfix/smtp_scache"
264 postconf -e smtp_tls_session_cache_timeout="3600s"
265 postconf -e smtpd_tls_security_level="may"
266 postconf -e smtpd_tls_session_cache_database="sdbm:/var/lib/postfix/smtpd_scache"
267 postconf -e smtpd_tls_session_cache_timeout="3600s"
268 postconf -e tls_random_source="dev:/dev/urandom"
269 postconf -e smtpd_tls_exclude_ciphers="aNULL"
270 postconf -e smtpd_tls_mandatory_exclude_ciphers="aNULL"
271
272 # nije potrebno generiranje certifikata jer postfix koristi paket ssl-cert
273 # ako je postavljen snakeoil certifikat za smtpd_tls_* postavi isti za smtp_tls_*
274 smtpd_tls_cert_file="`postconf -h smtpd_tls_cert_file`"
275 if [ "$smtpd_tls_cert_file" = "/etc/ssl/certs/ssl-cert-snakeoil.pem" ]; then
276   postconf -e smtp_tls_cert_file="/etc/ssl/certs/ssl-cert-snakeoil.pem"
277   postconf -e smtp_tls_key_file="/etc/ssl/private/ssl-cert-snakeoil.key"
278 fi
279
280 # ako je prazan, postavi na defaultni iz paketa ssl-cert
281 smtpd_tls_cert_file="`postconf -h smtpd_tls_cert_file`"
282 if [ -z "$smtpd_tls_cert_file" ]; then
283   postconf -e smtpd_tls_cert_file="/etc/ssl/certs/ssl-cert-snakeoil.pem"
284   postconf -e smtpd_tls_key_file="/etc/ssl/private/ssl-cert-snakeoil.key"
285 fi
286 smtp_tls_cert_file="`postconf -h smtp_tls_cert_file`"
287 if [ -z "$smtp_tls_cert_file" ]; then
288   postconf -e smtp_tls_cert_file="/etc/ssl/certs/ssl-cert-snakeoil.pem"
289   postconf -e smtp_tls_key_file="/etc/ssl/private/ssl-cert-snakeoil.key"
290 fi
291
292 # prije bilo u /etc/postfix/, od verzije 2.1.5-2 je u /var/spool/postfix
293 [ -f /etc/postfix/smtp_scache.dir ] && rm -f /etc/postfix/smtp_scache.dir
294 [ -f /etc/postfix/smtp_scache.pag ] && rm -f /etc/postfix/smtp_scache.pag
295 [ -f /etc/postfix/smtpd_scache.dir ] && rm -f /etc/postfix/smtpd_scache.dir
296 [ -f /etc/postfix/smtpd_scache.pag ] && rm -f /etc/postfix/smtpd_scache.pag
297 # prije bilo u /var/spool/postfix/, od verzije 2.5.5 je u /var/lib/postfix
298 [ -f /var/spool/postfix/smtp_scache.dir ] && rm -f /var/spool/postfix/smtp_scache.dir
299 [ -f /var/spool/postfix/smtp_scache.pag ] && rm -f /var/spool/postfix/smtp_scache.pag
300 [ -f /var/spool/postfix/smtpd_scache.dir ] && rm -f /var/spool/postfix/smtpd_scache.dir
301 [ -f /var/spool/postfix/smtpd_scache.pag ] && rm -f /var/spool/postfix/smtpd_scache.pag
302
303 # debconf stop
304 db_go || true
305 db_stop || true
306
307 # ako postoji amavis, sredi
308 if [ -x /usr/share/amavisd-cn/postfixize.sh ]; then
309   /usr/share/amavisd-cn/postfixize.sh
310 fi
311
312 # provjeri da li postoji sendmail-base
313 if ! dpkg -l sendmail-base | grep -q '^.n'; then
314   cp_echo ""
315   cp_echo "CN: Package sendmail-base detected."
316   cp_echo "CN: Please, purge this package with command:"
317   cp_echo "CN: # dpkg --purge sendmail-base"
318   cp_echo ""
319 fi
320
321 # sendmailov /etc/mail/access
322 if [ -f /etc/mail/access -a /etc/mail/access.db ]; then
323   cp_echo ""
324   cp_echo "CN: Sendmail's access file (/etc/mail/access) detected."
325   cp_echo "CN: Please, upgrade your's /etc/postfix/access."
326   cp_echo "CN: http://www.postfix.org/SMTPD_ACCESS_README.html"
327   cp_echo ""
328 fi
329
330 if ! id postfix | grep -q sasl; then
331   adduser postfix sasl > /dev/null
332   restart_postfix="yes"
333 fi
334
335 # ako ima razlika, backupiraj stari, ako ne, obrisi privremeni backup
336 if ! cmp -s /etc/postfix/master.cf /etc/postfix/master.cf.dpkg-tmp.$$; then
337   cp_echo "CN: Backing up old version of /etc/postfix/master.cf in /var/backups/..."
338   cp_backup_conffile /etc/postfix/master.cf.dpkg-tmp.$$ master.cf
339   restart_postfix="yes"
340 fi
341 rm -f /etc/postfix/master.cf.dpkg-tmp.$$
342
343 if ! cmp -s /etc/postfix/main.cf /etc/postfix/main.cf.dpkg-tmp.$$; then
344   cp_echo "CN: Backing up old version of /etc/postfix/main.cf in /var/backups/..."
345   cp_backup_conffile /etc/postfix/main.cf.dpkg-tmp.$$ main.cf
346   restart_postfix="yes"
347 fi
348 rm -f /etc/postfix/main.cf.dpkg-tmp.$$
349
350 if ! grep -q "retry     unix  -       -       -       -       -       error" /etc/postfix/master.cf; then
351   echo "CN: Please, add this line in /etc/postfix/master.cf and restart Postfix."
352   echo "retry     unix  -       -       -       -       -       error"
353   echo
354 fi
355
356 # kreiraj aliases_gecos
357 if [ -x /usr/share/postfix-cn/make-aliases-gecos.sh ]; then
358   if [ "$matchgecos" = "true" ]; then
359     echo "CN: Creating GECOS alias map..."
360     /usr/share/postfix-cn/make-aliases-gecos.sh
361   fi
362 fi
363
364 # restart 
365 if [ "$restart_postfix" = "yes" ]; then
366   if [ -x /usr/sbin/invoke-rc.d ]; then
367     [ -x /etc/init.d/postfix ] && invoke-rc.d postfix restart
368   else
369     [ -x /etc/init.d/postfix ] && /etc/init.d/postfix restart
370   fi
371 fi
372 cp_mail postfix-cn
373
374 #DEBHELPER#