Commit | Line | Data |
---|---|---|
de45f55a AM |
1 | #!/bin/sh |
2 | ||
3 | set -e | |
4 | export exim4postinstisrunning=true | |
5 | . /usr/share/debconf/confmodule | |
6 | ||
7 | if [ -n "$EX4DEBUG" ]; then | |
8 | echo "now debugging $0 $@" | |
9 | set -x | |
10 | fi | |
11 | ||
12 | UE4CC="/etc/exim4/update-exim4.conf.conf" | |
13 | ||
14 | db_version 2.0 | |
15 | ||
16 | get_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 | ||
27 | write_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 | ||
47 | EOF | |
48 | } | |
49 | ||
50 | addrootalias() { | |
51 | # remove leading and ending whitespace, shrink multiple whitespace, separate | |
52 | # entries with commas | |
53 | poma="$(echo "$1" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//' -e 's/[[:space:];][[:space:]]*/,/g')" | |
54 | if [ "none" != "$poma" ] && [ "" != "$poma" ]; then | |
55 | echo "root: ${poma}" >> /etc/aliases | |
56 | fi | |
57 | } | |
58 | ||
59 | #initialize /etc/aliases | |
60 | writealiases() { | |
61 | echo '# /etc/aliases' > /etc/aliases.tmp | |
62 | echo 'mailer-daemon: postmaster' >> /etc/aliases.tmp | |
63 | for i in postmaster nobody hostmaster usenet news webmaster www ftp abuse noc security ; do | |
64 | echo "${i}: root" | |
65 | done >> /etc/aliases.tmp | |
66 | mv /etc/aliases.tmp /etc/aliases | |
67 | } | |
68 | ||
69 | alias stripwhitespace="sed -e 's/^[[:blank:]]*//' -e 's/[[:blank:]]*$//'" | |
70 | ||
71 | # return success if md5sum matches file | |
72 | unmodified() { | |
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 | ||
91 | convert_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 | ||
112 | convert_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 | ||
133 | convert_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 | } | |
147 | convert_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. | |
163 | if [ "$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 | ||
174 | fi | |
175 | if [ "$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 | |
181 | fi | |
182 | ||
183 | # Disable orphaned inetd-entries from exim (v3) caused by bugs #202670 | |
184 | # and #182206. | |
185 | if [ "$1" = "configure" ] &&\ | |
89fb561f AM |
186 | which update-inetd > /dev/null && which exim > /dev/null && \ |
187 | [ -f /etc/inetd.conf ] && \ | |
de45f55a AM |
188 | grep -E -q '^smtp[[:space:]]*stream[[:space:]]*tcp[[:space:]]*nowait[[:space:]]*mail[[:space:]]*/usr/sbin/+exim exim -bs' /etc/inetd.conf |
189 | then | |
190 | update-inetd --comment-chars \#disabled\# \ | |
191 | --pattern '/usr/sbin/exim exim -bs' --disable smtp | |
192 | fi | |
193 | ||
194 | if [ "$1" = "configure" ] &&\ | |
195 | ! getent passwd Debian-exim > /dev/null ; then | |
196 | echo 'Adding system-user for exim (v4)' 1>&2 | |
197 | adduser --system --group --quiet --home /var/spool/exim4 \ | |
198 | --no-create-home --disabled-login --force-badname Debian-exim | |
199 | fi | |
200 | ||
201 | # fix permissions of /etc/exim4/passwd.client | |
202 | if [ "$1" = "configure" ] ; then | |
203 | if ! dpkg-statoverride --list /etc/exim4/passwd.client > /dev/null 2>&1 | |
204 | then | |
205 | dpkg-statoverride --update --add root Debian-exim 0640 \ | |
206 | /etc/exim4/passwd.client | |
207 | fi | |
208 | ||
209 | if dpkg --compare-versions "$2" le "4.30-1" ; then | |
210 | find /etc/exim4 -user mail \( -type f -or -type d \) -print |\ | |
211 | while read i ; | |
212 | do | |
213 | if ! dpkg-statoverride --list "$i" > /dev/null ; then | |
214 | chown Debian-exim "$i" | |
215 | fi | |
216 | done | |
217 | find /etc/exim4 -group mail \( -type f -or -type d \) -print |\ | |
218 | while read i ; | |
219 | do | |
220 | if ! dpkg-statoverride --list "$i" > /dev/null ; then | |
221 | chgrp Debian-exim "$i" | |
222 | fi | |
223 | done | |
224 | fi | |
225 | fi | |
226 | ||
227 | case "$1" in | |
228 | configure) | |
229 | # Configure Exim############################## | |
230 | ############################################## | |
231 | # valid config directives | |
232 | 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" | |
233 | # Generate config-file if it does not yet exist | |
234 | if [ ! -e $UE4CC ] ; then | |
235 | write_header | |
236 | for variable in ${dc_directives} ; do | |
237 | echo "${variable}=" | |
238 | done >> $UE4CC | |
239 | fi | |
240 | ||
241 | # If this is a fresh installation generate dummy files, which | |
242 | # will be overwritten by update-exim4.conf | |
243 | # if we add stuff later, we have to compare versions: | |
244 | # if [ -z "$2" ] || [ "$2" = "<unknown>" ] || dpkg --compare-versions "$2" lt "4.14-0.4" ; then | |
245 | # for file in /etc/exim4/conf.d/main/03_exim4-config_neverusers ;do | |
246 | # if [ ! -f "$file" ] ; then | |
247 | # echo "# d41d8cd98f00b204e9800998ecf8427e" > "$file" | |
248 | # chmod 644 "$file" | |
249 | # fi | |
250 | # done | |
251 | #fi | |
252 | ||
253 | # generate defaultfile | |
254 | update-exim4defaults --init | |
255 | ||
256 | # source $UE4CC - needed for not | |
257 | # debconf-managed values in there. | |
258 | . $UE4CC | |
259 | ||
260 | # Substitute values from debconf db | |
261 | db_get exim4/dc_eximconfig_configtype || true | |
262 | dc_eximconfig_configtype="$(convert_to_short "$RET")" | |
263 | db_get exim4/dc_local_interfaces || true | |
264 | dc_local_interfaces="$(printf '%s\n' "$RET" | stripwhitespace)" | |
265 | db_get exim4/dc_other_hostnames || true | |
266 | dc_other_hostnames="$(printf '%s\n' "$RET" | stripwhitespace)" | |
267 | db_get exim4/dc_readhost || true | |
268 | dc_readhost="$(printf '%s\n' "$RET" | stripwhitespace)" | |
269 | db_get exim4/dc_relay_domains || true | |
270 | dc_relay_domains="$(printf '%s\n' "$RET" | stripwhitespace)" | |
271 | db_get exim4/dc_relay_nets || true | |
272 | dc_relay_nets="$(printf '%s\n' "$RET" | stripwhitespace)" | |
273 | db_get exim4/dc_smarthost || true | |
274 | dc_smarthost="$(printf '%s\n' "$RET" | stripwhitespace)" | |
275 | db_get exim4/dc_minimaldns || true | |
276 | dc_minimaldns="$(printf '%s\n' "$RET" | stripwhitespace)" | |
277 | db_get exim4/mailname || true | |
278 | mailname="$(printf '%s\n' "$RET" | stripwhitespace)" | |
279 | db_get exim4/use_split_config || true | |
280 | dc_use_split_config="$(printf '%s\n' "$RET" | stripwhitespace)" | |
281 | db_get exim4/hide_mailname || true | |
282 | dc_hide_mailname="$(printf '%s\n' "$RET" | stripwhitespace)" | |
283 | ||
284 | # overwrite dc_localdelivery with value stored in debconf db unless | |
285 | # it is set to something else than maildir_home or mail_spool. | |
286 | if [ "${dc_localdelivery}" = "" ] || | |
287 | [ "$(convert_transport_to_long ${dc_localdelivery})" != "locally customized" ] ; then | |
288 | db_get exim4/dc_localdelivery || true | |
289 | dc_localdelivery="$(convert_transport_to_short "$RET")" | |
290 | fi | |
291 | ||
292 | if [ -r /var/lib/exim4/addmailname2oh ] ; then | |
293 | # .config added mailname to other hostnames, 2nd run of config script | |
294 | # will have overwritten this change in debcond-db, therefore we need | |
295 | # to store this externally, too. | |
296 | . /var/lib/exim4/addmailname2oh | |
297 | rm -f /var/lib/exim4/addmailname2oh | |
298 | fi | |
299 | db_fget "exim4/dc_other_hostnames" mailname || true | |
300 | dc_mailname_in_oh="$RET" | |
301 | ||
302 | [ "${CFILEMODE}" = "" ] && CFILEMODE=644 | |
303 | ||
304 | db_get exim4/dc_postmaster | |
305 | dc_postmaster="$(printf '%s\n' "$RET" | stripwhitespace)" | |
306 | ||
307 | if [ ! -e /etc/aliases ] ; then | |
308 | writealiases | |
309 | fi | |
310 | if ! grep -q '^root:[[:space:]]*[[:alnum:]]' /etc/aliases && \ | |
311 | [ "${dc_postmaster}" != "none" ]; then | |
312 | addrootalias "${dc_postmaster}" | |
313 | fi | |
314 | ||
315 | ### write configuration to files # | |
316 | # add missing items | |
317 | for variable in ${dc_directives} ; do | |
318 | if ! grep -E -q "^[[:space:]]*${variable}=" $UE4CC ; then | |
319 | echo "${variable}=''" >> $UE4CC | |
320 | fi | |
321 | done | |
322 | # insert new values, remove outdated ones. | |
323 | ||
324 | # Use environment variables to communicate data to awk, to | |
325 | # avoid shell (or awk or sed) string expansion which may | |
326 | # expand escape sequences. Note that the variables named in | |
327 | # ${dc_directives} (but not the variable names themselves) may | |
328 | # contain escaped characters like \N. | |
329 | ||
330 | export dc_directives ${dc_directives} | |
331 | ||
332 | awk ' | |
333 | BEGIN { | |
334 | split( ENVIRON["dc_directives"], directives, "[ \t]" ); | |
335 | } | |
336 | { | |
337 | written = 0; | |
338 | for ( i in directives ) | |
339 | { | |
340 | regex = "^[ \t]*" directives[i] "="; | |
341 | if ( ( $0 ~ regex ) && ( ! written ) ) | |
342 | { | |
343 | # Add single quotes (\0x27) around the value. | |
344 | print directives[i] "=\x27" ENVIRON[directives[i]] "\x27"; | |
345 | written = 1; | |
346 | break; | |
347 | } | |
348 | } | |
349 | if ( ! written ) | |
350 | print $0; | |
351 | }' < ${UE4CC} > ${UE4CC}.tmp | |
352 | ||
353 | mv ${UE4CC}.tmp $UE4CC | |
354 | ||
355 | echo $mailname > /etc/mailname | |
356 | ### configuration files written ## | |
357 | ||
358 | ||
359 | if [ "${dc_eximconfig_configtype}" != "none" ]; then | |
360 | update-exim4.conf | |
361 | fi | |
362 | # If dpkg-reconfigure was used implement the changes by restarting | |
363 | # the daemon. | |
364 | if [ "${DEBCONF_RECONFIGURE}" = "1" ] ; then | |
365 | if [ -x /etc/init.d/exim4 ]; then | |
366 | # use restart instead of reload, as changing listening | |
367 | # interfaces cannot be done with HUP. | |
368 | db_stop | |
369 | if [ -n "$EX4DEBUG" ]; then | |
370 | netstat -tulpen | |
89fb561f AM |
371 | ls -al /run/exim4/ |
372 | cat /run/exim4/exim.pid | |
de45f55a AM |
373 | pidof exim4 |
374 | fi | |
375 | if [ "$dc_eximconfig_configtype" = "none" ]; then | |
376 | # we may have broken config here, ignore errors | |
377 | invoke-rc.d exim4 restart || true | |
378 | else | |
379 | # we must have working config here, honor errors | |
380 | invoke-rc.d exim4 restart | |
381 | fi | |
382 | if [ -n "$EX4DEBUG" ]; then | |
383 | netstat -tulpen | |
89fb561f AM |
384 | ls -al /run/exim4/ |
385 | cat /run/exim4/exim.pid | |
de45f55a AM |
386 | pidof exim4 |
387 | if pidof exim4; then | |
388 | echo >&2 "WARN: There are some exim4 processes still running after stopping exim" | |
389 | fi | |
390 | fi | |
391 | fi | |
392 | fi | |
393 | ||
394 | ;; | |
395 | esac | |
396 | ||
397 | # remove orphaned conffile if unmodified. 4.20-2. | |
398 | if [ "$1" = "configure" ] && \ | |
399 | dpkg --compare-versions "$2" le-nl "4.20-1" && \ | |
400 | [ -e /etc/exim4/email-addresses ] && \ | |
401 | [ "$(md5sum /etc/exim4/email-addresses | cut -d\ -f1)" = "6bea09fbb18e4676012105fa5fc726c6" ] | |
402 | then | |
403 | echo "Removing orphaned unmodified configfile /etc/exim4/email-addresses" 1>&2 | |
404 | rm /etc/exim4/email-addresses | |
405 | fi | |
406 | ||
407 | ||
408 | #DEBHELPER# |