3
# Debian Postfix postinst
4
# LaMont Jones <lamont@debian.org>
5
# Based on debconf code by Colin Walters <walters@cis.ohio-state.edu>,
6
# and John Goerzen <jgoerzen@progenylinux.com>.
9
. /usr/share/debconf/confmodule
10
CHROOT=/var/spool/postfix
11
config_directory="/etc/postfix" # make variable expansion easier...
15
. /usr/share/postfix/postinst.functions
17
set_maildrop_perms() {
18
MAILDROP=${CHROOT}/maildrop
19
SCRIPT=/etc/postfix/postfix-script
20
POSTDROP=/usr/sbin/postdrop
22
if ! chown postfix:postdrop $MAILDROP 2>/dev/null; then
23
addgroup --system postdrop
24
chown postfix:postdrop $MAILDROP
26
dpkg-statoverride --remove $POSTDROP >/dev/null 2>&1 || true
27
dpkg-statoverride --remove /var/spool/postfix/public >/dev/null 2>&1 || true
28
dpkg-statoverride --remove /usr/sbin/postqueue >/dev/null 2>&1 || true
29
dpkg-statoverride --update --add root postdrop 02555 $POSTDROP
30
dpkg-statoverride --update --add postfix postdrop 02710 /var/spool/postfix/public
31
dpkg-statoverride --update --add root postdrop 02555 /usr/sbin/postqueue
36
db_fset postfix/main_mailer_type changed $1
37
db_fset postfix/root_address changed $1
38
db_fset postfix/destinations changed $1
39
db_fset postfix/mailname changed $1
40
db_fset postfix/relayhost changed $1
41
db_fset postfix/chattr changed $1
42
db_fset postfix/mynetworks changed $1
43
db_fset postfix/procmail changed $1
44
db_fset postfix/mailbox_limit changed $1
45
db_fset postfix/recipient_delim changed $1
61
chown $2 $1 && chmod $3 $1
65
# get all of the hash and btree maps.
66
maps=$(postconf -h | sed -e 's/[,[:space:]]/\
67
/g' -e 's/^proxy://' -e '/:/p' | sort -u )
73
echo "attempting conversion of $i"
74
echo " saving old db in ${f}.db3"
85
# Need to handle some changes in services.
86
MASTER=/etc/postfix/master.cf
87
if grep -qE '^cleanup[[:space:]]+unix[[:space:]]+-' ${MASTER}; then
88
echo "in master.cf:"; echoed=y
89
echo " forcing pickup=unprivileged, cleanup=public, flush=public"
90
sed 's/^\(cleanup[[:space:]]*unix[[:space:]]*\)-/\1n/
91
s/^\(flush[[:space:]]*unix[[:space:]]*\)-/\1n/
92
s/^\(pickup[[:space:]]*fifo[[:space:]]*.[[:space:]]*\)n/\1-/
93
' ${MASTER} > ${MASTER}.$$
94
mv ${MASTER}.$$ ${MASTER}
97
if ! grep -qE '^flush[[:space:]]' ${MASTER}; then
98
[ -n $echoed ] || echo "in master.cf:"; echoed=y
99
echo " adding missing entry for flush service"
100
echo "flush unix n - - 1000? 0 flush" \
104
if ! grep -qE '^proxymap[[:space:]]' ${MASTER}; then
105
[ -n $echoed ] || echo "in master.cf:"; echoed=y
106
echo " adding missing entry for proxymap service"
107
echo "proxymap unix - - n - - proxymap" \
110
if ! grep -qE '^trace[[:space:]]' ${MASTER}; then
111
[ -n $echoed ] || echo "in master.cf:"; echoed=y
112
echo " adding missing entry for trace service"
113
echo "trace unix - - - - 0 bounce" \
117
if ! grep -qE '^verify[[:space:]]' ${MASTER}; then
118
[ -n $echoed ] || echo "in master.cf:"; echoed=y
119
echo " adding missing entry for verify service"
120
echo "verify unix - - - - 1 verify" \
127
# postinst processing
141
abort-remove|abort-deconfigure)
146
echo "postinst called with unknown argument \`$1'" >&2
152
NEWALIASES="y" # run newaliases at the end of things
154
update-rc.d postfix defaults > /dev/null
155
update-inetd --disable smtp
159
dpkg-divert --package postfix --remove --rename \
160
--divert /usr/share/man/man8/smtpd.real.8.gz \
161
/usr/share/man/man8/smtpd.8.gz > /dev/null 2>&1
164
# make sure that the postfix user exists. Simplest portable way to check is to
165
# chown something, so we'll create the directories that we need here.
166
makedir private root:root 700
167
chgrp postfix private 2>/dev/null ||
168
addgroup --system postfix
169
chown postfix private 2>/dev/null ||
170
adduser --system --home ${CHROOT} --no-create-home --disabled-password --ingroup postfix postfix
172
# need to have postfix in the right group, but old revs do it wrong..
173
if [ "$(id -gn postfix)" != "postfix" ]; then
174
usermod -g postfix postfix
177
chown postfix:root private
179
db_fget postfix/chattr changed
180
if [ "$RET" = "true" ]; then
181
db_get postfix/chattr && chat="$RET"
182
echo "setting synchronous mail queue updates: $chat"
183
if [ "$chat" = "true" ]; then
190
for dir in pid public; do
191
makedir ${dir} postfix:root 755
193
for dir in incoming active bounce defer deferred flush saved corrupt; do
194
makedir ${dir} postfix:root 700
195
if [ -n "$chat" ]; then
196
chattr $chat $dir 2>/dev/null || true
202
if [ ! -f dynamicmaps.cf ]; then
203
echo "Creating /etc/postfix/dynamicmaps.cf"
204
cat << EOF > dynamicmaps.cf
205
# Postfix dynamic maps configuration file.
207
# The first match found is the one that is used. Wildcards are not supported
208
# as of postfix 2.0.2
210
#type location of .so file open function (mkmap func)
211
#==== ================================ ============= ============
215
# handle dynamicmaps.cf upgrade - we checked with the user in preinst.
216
if [ -f /var/spool/postfix/dynamicmaps_upgrade ]; then
218
if ! grep -qi 'wildcards are not supported' dynamicmaps.cf; then
219
echo '# *** Wildcards are not supported as of postfix 2.0.2 ***'
222
sed '/^\*[[:space:]]/d' dynamicmaps.cf
223
) > dynamicmaps.cf.$$
224
mv dynamicmaps.cf.$$ dynamicmaps.cf
225
# Need to add all of them, since we may need them to configure... sigh.
231
addmap sdbm mkmap_sdbm_open
235
db_fget postfix/main_mailer_type changed && mailer_changed="$RET"
236
db_get postfix/main_mailer_type && mailer="$RET"
238
if [ ! -f master.cf ]; then
240
"Local only"|"Satellite system")
241
cp /usr/share/postfix/master.cf.local master.cf
244
cp /usr/share/postfix/master.cf.dist master.cf
249
if [ "$mailer" != "No configuration" ]; then # [
250
if [ -f main.cf ]; then
253
cp /usr/share/postfix/main.cf.debian main.cf
256
fi # !No configuration ]
258
# cleanup from braindamage.
259
if [ -d /etc/postfix/maildrop ]; then
260
rmdir /etc/postfix/maildrop 2>/dev/null
263
set_maildrop_perms postdrop
264
if [ -f /var/spool/postfix/db-upgrade ]; then
265
rm /var/spool/postfix/db-upgrade
266
db_get postfix/db_upgrade_warning && convert="$RET"
267
if [ "$convert" = "true" ]; then
270
echo "DB files not converted, Postfix restart may fail."
274
if [ "$mailer" != "No configuration" ]; then # [
275
myhostname=$(hostname --fqdn 2>/dev/null || echo "")
276
if [ -z "$myhostname" ]; then
277
if [ -r /etc/hostname ];then
278
myhostname=$(cat /etc/hostname)
279
if [ $hostname = ${hostname%.*} -a -f /etc/resolv.conf ]; then
280
mydom=$(awk '/^(search|domain)/ { print $2;quit;}' \
282
myhostname="$myhostname${mydom:+.$mydom}"
288
mydomain=${myhostname#*.}
290
if [ -n "$NEWCONF" ]; then
291
fset_all_changed true
292
alias_maps=hash:/etc/aliases
293
nis_status=$(dpkg -l nis 2>/dev/null | sed -n '$p')
294
if [ "X$nis_status" != "X${nis_status#i}" ] && [ -x /usr/bin/ypcat ] &&
295
/usr/bin/ypcat mail.aliases >/dev/null 2>&1; then
296
alias_maps="hash:/etc/aliases, nis:mail.aliases"
298
It appears that you have an NIS map for mail aliases; using that in
299
addition to /etc/aliases.
303
if [ -n "$myhostname" ]; then
304
echo "setting myhostname: $myhostname"
305
set_postconf "myhostname=$myhostname"
307
echo "setting alias maps"
308
set_postconf "alias_maps=$alias_maps"
309
echo "setting alias database"
310
set_postconf "alias_database=hash:/etc/aliases"
313
db_fget postfix/mailname changed
314
if [ "$RET" = "true" ]; then
315
db_get postfix/mailname && mailname="$RET"
316
if [ -f /etc/mailname ] && [ "X$(cat /etc/mailname)" = "X$mailname" ]; then
321
if [ "X${mailname%.*}" != "X${mailname}" ]; then
322
if [ -n "$MAILNAME" ]; then
323
echo "changing /etc/mailname"
324
echo $mailname > /etc/mailname
326
echo "setting myorigin"
327
set_postconf "myorigin=/etc/mailname"
329
echo "mailname is not a fully qualified domain name. Not changing /etc/mailname."
332
db_fget postfix/destinations changed
333
if [ "$RET" = "true" ]; then
334
db_get postfix/destinations && destinations="$RET"
335
echo "setting destinations: $destinations"
336
set_postconf "mydestination=$destinations"
338
db_fget postfix/relayhost changed
339
if [ "$RET" = "true" ]; then
340
db_get postfix/relayhost && relayhost="$RET"
341
echo "setting relayhost: $relayhost"
342
set_postconf "relayhost=$relayhost"
344
db_fget postfix/mynetworks changed
345
if [ "$RET" = "true" ]; then
346
db_get postfix/mynetworks && mynetworks="$RET"
347
if [ -z "$RET" ]; then
348
echo "deleting mynetworks"
349
if grep -q '^mynetworks[[:space:]]*=' main.cf; then
350
# need to remove it, get postconf to do the hard part.
351
postconf -e 'mynetworks=127.0.0.0/8'
352
perl -i -ne 'print unless /^mynetworks\s*=/' main.cf
355
echo "setting mynetworks: $mynetworks"
356
set_postconf "mynetworks=$mynetworks"
359
db_fget postfix/procmail changed
360
if [ "$RET" = "true" ]; then
361
db_get postfix/procmail && useprocmail="$RET"
362
if [ "x$useprocmail" = "xtrue" ]; then
363
echo "setting mailbox_command"
364
set_postconf 'mailbox_command=procmail -a "$EXTENSION"'
366
echo "clearing mailbox_command"
367
set_postconf "mailbox_command="
370
db_fget postfix/mailbox_limit changed
371
if [ "$RET" = "true" ]; then
372
db_get postfix/mailbox_limit && mailbox_limit="$RET"
373
echo "setting mailbox_size_limit: $mailbox_limit"
374
set_postconf "mailbox_size_limit=$mailbox_limit"
377
db_fget postfix/recipient_delim changed
378
if [ "$RET" = "true" ]; then
379
db_get postfix/recipient_delim && recip="$RET"
380
echo "setting recipient_delimiter: $recip"
381
set_postconf "recipient_delimiter=$recip"
384
if [ -z "$CHANGES" ]; then
385
MSG="configuration was not changed"
386
else if [ -n "$NEWCONF" ]; then
387
MSG="is now set up with a default configuration"
389
MSG="is now set up with the changes above"
392
else # ] No configuration [
393
if [ -f main.cf ]; then
394
MSG="configuration was untouched"
396
MSG="was not set up. Start with
397
cp /usr/share/postfix/main.cf.debian /etc/postfix/main.cf
399
# make sure that we don't try anything stupid below.
401
rm -f /var/spool/postfix/restart /var/spool/postfix/reload
403
fi # not 'No configuration' ]
405
if [ ! -f /etc/aliases ]; then # no /etc/aliases [
406
echo "/etc/aliases does not exist, creating it."
407
cat << EOF > /etc/aliases
408
# See man 5 aliases for format
411
if [ "$mailer" != "No configuration" ]; then # [
412
db_fget postfix/root_address changed
413
if [ "$RET" = "true" ]; then
414
db_get postfix/root_address && root_addr="$RET"
415
ret=$(echo $RET | tr '[A-Z]' '[a-z]')
416
if [ "$ret" != "none" ]; then
417
echo "root: $RET" >> /etc/aliases
420
fi # not 'No configuration' ]
421
fi # ] no /etc/aliases
423
fset_all_changed false
427
Postfix $MSG. If you need to make changes, edit
428
/etc/postfix/main.cf (and others) as needed. To view Postfix configuration
429
values, see postconf(1).
431
After modifying main.cf, be sure to run '/etc/init.d/postfix reload'.
435
# all done with debconf here.
440
if [ -n "$NEWALIASES" ]; then
441
echo "Running newaliases"
442
rm -f /etc/aliases.db # handle the roll to db2.0
444
# newaliases chokes if hostname not set
445
if [ -z "$(postconf -h myhostname||true)" ]; then
446
cp -a main.cf main.cf.dpkg.$$
447
postconf -e 'myhostname=ubuntu'
449
mv main.cf.dpkg.$$ main.cf
455
rm -f /var/spool/postfix/root_address
458
if [ -f /var/spool/postfix/restart ]; then
459
rm -f /var/spool/postfix/restart
460
/etc/init.d/postfix start
462
# or maybe just restart postfix
463
if [ -f /var/spool/postfix/reload ]; then
464
rm -f /var/spool/postfix/reload
465
/etc/init.d/postfix restart