Imported Debian patch 4.84-8
[hcoop/debian/exim4.git] / debian / exim4-config.postinst
CommitLineData
de45f55a
AM
1#!/bin/sh
2
3set -e
4export exim4postinstisrunning=true
5. /usr/share/debconf/confmodule
6
7if [ -n "$EX4DEBUG" ]; then
8 echo "now debugging $0 $@"
9 set -x
10fi
11
12UE4CC="/etc/exim4/update-exim4.conf.conf"
13
14db_version 2.0
15
16get_value() {
17 db_get $1
18 code="$?"
19 if [ "$code" -eq "0" ]; then
20 :
21 else
22 echo "Error getting debconf answer $1: debconf code=$code" >&2
23 exit $code
24 fi
25}
26
27write_header() {
28 cat <<EOF > $UE4CC
29# $UE4CC
30#
31# Edit this file and /etc/mailname by hand and execute update-exim4.conf
32# yourself or use 'dpkg-reconfigure exim4-config'
33#
34# Please note that this is _not_ a dpkg-conffile and that automatic changes
35# to this file might happen. The code handling this will honor your local
36# changes, so this is usually fine, but will break local schemes that mess
37# around with multiple versions of the file.
38#
39# update-exim4.conf uses this file to determine variable values to generate
40# exim configuration macros for the configuration file.
41#
42# Most settings found in here do have corresponding questions in the
43# Debconf configuration, but not all of them.
44#
45# This is a Debian specific file
46
47EOF
48}
49
50addrootalias() {
51# remove leading and ending whitespace, shrink multiple whitespace, separate
52# entries with commas
53poma="$(echo "$1" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/[[:space:];][[:space:]]*/,/g')"
54if [ "none" != "$poma" ] && [ "" != "$poma" ]; then
55 echo "root: ${poma}" >> /etc/aliases
56fi
57}
58
59#initialize /etc/aliases
60writealiases() {
61echo '# /etc/aliases' > /etc/aliases.tmp
62echo 'mailer-daemon: postmaster' >> /etc/aliases.tmp
63for i in postmaster nobody hostmaster usenet news webmaster www ftp abuse noc security ; do
64 echo "${i}: root"
65done >> /etc/aliases.tmp
66mv /etc/aliases.tmp /etc/aliases
67}
68
69alias stripwhitespace="sed -e 's/^[[:blank:]]*//' -e 's/[[:blank:]]*$//'"
70
71# return success if md5sum matches file
72unmodified() {
73 [ "$#" -eq 1 ] || return 1
74 [ -f "$1" ] || return 1
75 # first line, without the leading '# '.
76 checksum_current="$(sed -n -e '1s/^# //' -e '1p;1q' "$1")"
77
78 # md5sum over the rest of the file.
79 # some versions of md5sum produce
80 # '68b329da9893e34099c7d8ad5cb9c940 -' others don't add the dash.
81 # '68b329da9893e34099c7d8ad5cb9c940'
82 checksum_new="$(sed -n '2,$p' "$1" | md5sum | cut -d\ -f1)"
83
84 if [ "${checksum_current}" = "${checksum_new}" ] ; then
85 return 0
86 else
87 return 1
88 fi
89}
90
91convert_to_long ()
92{
93 case "$1" in
94 internet)
95 echo -n "internet site; mail is sent and received directly using SMTP"
96 ;;
97 smarthost)
98 echo -n "mail sent by smarthost; received via SMTP or fetchmail"
99 ;;
100 satellite)
101 echo -n "mail sent by smarthost; no local mail"
102 ;;
103 local)
104 echo -n "local delivery only; not on a network"
105 ;;
106 none)
107 echo -n "no configuration at this time"
108 ;;
109 esac
110}
111
112convert_to_short ()
113{
114 case "$1" in
115 "internet site; mail is sent and received directly using SMTP")
116 echo -n "internet"
117 ;;
118 "mail sent by smarthost; received via SMTP or fetchmail")
119 echo -n "smarthost"
120 ;;
121 "mail sent by smarthost; no local mail")
122 echo -n "satellite"
123 ;;
124 "local delivery only; not on a network")
125 echo -n "local"
126 ;;
127 "no configuration at this time")
128 echo -n "none"
129 ;;
130 esac
131}
132
133convert_transport_to_long ()
134{
135 case "$1" in
136 maildir_home)
137 echo -n "Maildir format in home directory"
138 ;;
139 mail_spool)
140 echo -n "mbox format in /var/mail/"
141 ;;
142 *)
143 echo -n "locally customized"
144 ;;
145 esac
146}
147convert_transport_to_short ()
148{
149 case "$1" in
150 "Maildir format in home directory")
151 echo -n "maildir_home"
152 ;;
153 "mbox format in /var/mail/")
154 echo -n "mail_spool"
155 ;;
156 *)
157 echo -n "custom"
158 ;;
159 esac
160}
161
162# remove orphaned autogenerated conffile if unmodified. 4.20-2.
163if [ "$1" = "configure" ] && \
164 dpkg --compare-versions "$2" le-nl "4.20-1" ; then
165
166 for i in /etc/exim4/conf.d/rewrite/30_exim4-config_email-addresses \
167 /etc/exim4/conf.d/rewrite/35_exim4-config_masquerade ; do
168 if unmodified "$i"; then
169 echo "Removing orphaned unmodified configfile $i" 1>&2
170 rm "$i"
171 fi
172 done
173
174fi
175if [ "$1" = "configure" ] && \
176 dpkg --compare-versions "$2" le-nl "4.20-2" ; then
177 if unmodified "/etc/exim4/conf.d/main/03_exim4-config_neverusers"; then
178 echo "Removing orphaned unmodified configfile /etc/exim4/conf.d/main/03_exim4-config_neverusers" 1>&2
179 rm "/etc/exim4/conf.d/main/03_exim4-config_neverusers"
180 fi
181fi
182
183# Disable orphaned inetd-entries from exim (v3) caused by bugs #202670
184# and #182206.
185if [ "$1" = "configure" ] &&\
186 [ -x /usr/sbin/update-inetd ] && [ ! -x /usr/sbin/exim ] && \
187 grep -E -q '^smtp[[:space:]]*stream[[:space:]]*tcp[[:space:]]*nowait[[:space:]]*mail[[:space:]]*/usr/sbin/+exim exim -bs' /etc/inetd.conf
188then
189 update-inetd --comment-chars \#disabled\# \
190 --pattern '/usr/sbin/exim exim -bs' --disable smtp
191fi
192
193if [ "$1" = "configure" ] &&\
194 ! getent passwd Debian-exim > /dev/null ; then
195 echo 'Adding system-user for exim (v4)' 1>&2
196 adduser --system --group --quiet --home /var/spool/exim4 \
197 --no-create-home --disabled-login --force-badname Debian-exim
198fi
199
200# fix permissions of /etc/exim4/passwd.client
201if [ "$1" = "configure" ] ; then
202 if ! dpkg-statoverride --list /etc/exim4/passwd.client > /dev/null 2>&1
203 then
204 dpkg-statoverride --update --add root Debian-exim 0640 \
205 /etc/exim4/passwd.client
206 fi
207
208 if dpkg --compare-versions "$2" le "4.30-1" ; then
209 find /etc/exim4 -user mail \( -type f -or -type d \) -print |\
210 while read i ;
211 do
212 if ! dpkg-statoverride --list "$i" > /dev/null ; then
213 chown Debian-exim "$i"
214 fi
215 done
216 find /etc/exim4 -group mail \( -type f -or -type d \) -print |\
217 while read i ;
218 do
219 if ! dpkg-statoverride --list "$i" > /dev/null ; then
220 chgrp Debian-exim "$i"
221 fi
222 done
223 fi
224fi
225
226case "$1" in
227 configure)
228 # Configure Exim##############################
229 ##############################################
230 # valid config directives
231 dc_directives="dc_eximconfig_configtype dc_other_hostnames dc_local_interfaces dc_readhost dc_relay_domains dc_minimaldns dc_relay_nets dc_smarthost CFILEMODE dc_use_split_config dc_hide_mailname dc_mailname_in_oh dc_localdelivery"
232 # Generate config-file if it does not yet exist
233 if [ ! -e $UE4CC ] ; then
234 write_header
235 for variable in ${dc_directives} ; do
236 echo "${variable}="
237 done >> $UE4CC
238 fi
239
240 # If this is a fresh installation generate dummy files, which
241 # will be overwritten by update-exim4.conf
242 # if we add stuff later, we have to compare versions:
243 # if [ -z "$2" ] || [ "$2" = "<unknown>" ] || dpkg --compare-versions "$2" lt "4.14-0.4" ; then
244 # for file in /etc/exim4/conf.d/main/03_exim4-config_neverusers ;do
245 # if [ ! -f "$file" ] ; then
246 # echo "# d41d8cd98f00b204e9800998ecf8427e" > "$file"
247 # chmod 644 "$file"
248 # fi
249 # done
250 #fi
251
252 # generate defaultfile
253 update-exim4defaults --init
254
255 # source $UE4CC - needed for not
256 # debconf-managed values in there.
257 . $UE4CC
258
259 # Substitute values from debconf db
260 db_get exim4/dc_eximconfig_configtype || true
261 dc_eximconfig_configtype="$(convert_to_short "$RET")"
262 db_get exim4/dc_local_interfaces || true
263 dc_local_interfaces="$(printf '%s\n' "$RET" | stripwhitespace)"
264 db_get exim4/dc_other_hostnames || true
265 dc_other_hostnames="$(printf '%s\n' "$RET" | stripwhitespace)"
266 db_get exim4/dc_readhost || true
267 dc_readhost="$(printf '%s\n' "$RET" | stripwhitespace)"
268 db_get exim4/dc_relay_domains || true
269 dc_relay_domains="$(printf '%s\n' "$RET" | stripwhitespace)"
270 db_get exim4/dc_relay_nets || true
271 dc_relay_nets="$(printf '%s\n' "$RET" | stripwhitespace)"
272 db_get exim4/dc_smarthost || true
273 dc_smarthost="$(printf '%s\n' "$RET" | stripwhitespace)"
274 db_get exim4/dc_minimaldns || true
275 dc_minimaldns="$(printf '%s\n' "$RET" | stripwhitespace)"
276 db_get exim4/mailname || true
277 mailname="$(printf '%s\n' "$RET" | stripwhitespace)"
278 db_get exim4/use_split_config || true
279 dc_use_split_config="$(printf '%s\n' "$RET" | stripwhitespace)"
280 db_get exim4/hide_mailname || true
281 dc_hide_mailname="$(printf '%s\n' "$RET" | stripwhitespace)"
282
283 # overwrite dc_localdelivery with value stored in debconf db unless
284 # it is set to something else than maildir_home or mail_spool.
285 if [ "${dc_localdelivery}" = "" ] ||
286 [ "$(convert_transport_to_long ${dc_localdelivery})" != "locally customized" ] ; then
287 db_get exim4/dc_localdelivery || true
288 dc_localdelivery="$(convert_transport_to_short "$RET")"
289 fi
290
291 if [ -r /var/lib/exim4/addmailname2oh ] ; then
292 # .config added mailname to other hostnames, 2nd run of config script
293 # will have overwritten this change in debcond-db, therefore we need
294 # to store this externally, too.
295 . /var/lib/exim4/addmailname2oh
296 rm -f /var/lib/exim4/addmailname2oh
297 fi
298 db_fget "exim4/dc_other_hostnames" mailname || true
299 dc_mailname_in_oh="$RET"
300
301 [ "${CFILEMODE}" = "" ] && CFILEMODE=644
302
303 db_get exim4/dc_postmaster
304 dc_postmaster="$(printf '%s\n' "$RET" | stripwhitespace)"
305
306 if [ ! -e /etc/aliases ] ; then
307 writealiases
308 fi
309 if ! grep -q '^root:[[:space:]]*[[:alnum:]]' /etc/aliases && \
310 [ "${dc_postmaster}" != "none" ]; then
311 addrootalias "${dc_postmaster}"
312 fi
313
314 ### write configuration to files #
315 # add missing items
316 for variable in ${dc_directives} ; do
317 if ! grep -E -q "^[[:space:]]*${variable}=" $UE4CC ; then
318 echo "${variable}=''" >> $UE4CC
319 fi
320 done
321 # insert new values, remove outdated ones.
322
323 # Use environment variables to communicate data to awk, to
324 # avoid shell (or awk or sed) string expansion which may
325 # expand escape sequences. Note that the variables named in
326 # ${dc_directives} (but not the variable names themselves) may
327 # contain escaped characters like \N.
328
329 export dc_directives ${dc_directives}
330
331 awk '
332 BEGIN {
333 split( ENVIRON["dc_directives"], directives, "[ \t]" );
334 }
335 {
336 written = 0;
337 for ( i in directives )
338 {
339 regex = "^[ \t]*" directives[i] "=";
340 if ( ( $0 ~ regex ) && ( ! written ) )
341 {
342 # Add single quotes (\0x27) around the value.
343 print directives[i] "=\x27" ENVIRON[directives[i]] "\x27";
344 written = 1;
345 break;
346 }
347 }
348 if ( ! written )
349 print $0;
350 }' < ${UE4CC} > ${UE4CC}.tmp
351
352 mv ${UE4CC}.tmp $UE4CC
353
354 echo $mailname > /etc/mailname
355 ### configuration files written ##
356
357
358 if [ "${dc_eximconfig_configtype}" != "none" ]; then
359 update-exim4.conf
360 fi
361 # If dpkg-reconfigure was used implement the changes by restarting
362 # the daemon.
363 if [ "${DEBCONF_RECONFIGURE}" = "1" ] ; then
364 if [ -x /etc/init.d/exim4 ]; then
365 # use restart instead of reload, as changing listening
366 # interfaces cannot be done with HUP.
367 db_stop
368 if [ -n "$EX4DEBUG" ]; then
369 netstat -tulpen
370 ls -al /var/run/exim4/
371 cat /var/run/exim4/exim.pid
372 pidof exim4
373 fi
374 if [ "$dc_eximconfig_configtype" = "none" ]; then
375 # we may have broken config here, ignore errors
376 invoke-rc.d exim4 restart || true
377 else
378 # we must have working config here, honor errors
379 invoke-rc.d exim4 restart
380 fi
381 if [ -n "$EX4DEBUG" ]; then
382 netstat -tulpen
383 ls -al /var/run/exim4/
384 cat /var/run/exim4/exim.pid
385 pidof exim4
386 if pidof exim4; then
387 echo >&2 "WARN: There are some exim4 processes still running after stopping exim"
388 fi
389 fi
390 fi
391 fi
392
393 ;;
394esac
395
396# remove orphaned conffile if unmodified. 4.20-2.
397if [ "$1" = "configure" ] && \
398 dpkg --compare-versions "$2" le-nl "4.20-1" && \
399 [ -e /etc/exim4/email-addresses ] && \
400 [ "$(md5sum /etc/exim4/email-addresses | cut -d\ -f1)" = "6bea09fbb18e4676012105fa5fc726c6" ]
401then
402 echo "Removing orphaned unmodified configfile /etc/exim4/email-addresses" 1>&2
403 rm /etc/exim4/email-addresses
404fi
405
406
407#DEBHELPER#