Stop referencing IPs we haven't had for years
[sysconfig/postfix.git] / post-install
1 #!/bin/sh
2
3 # To view the formatted manual page of this file, type:
4 #       POSTFIXSOURCE/mantools/srctoman - post-install | nroff -man
5
6 #++
7 # NAME
8 #       post-install
9 # SUMMARY
10 #       Postfix post-installation script
11 # SYNOPSIS
12 #       postfix post-install [name=value] command ...
13 # DESCRIPTION
14 #       The post-install script performs the finishing touch of a Postfix
15 #       installation, after the executable programs and configuration
16 #       files are installed. Usage is one of the following:
17 # .IP o
18 #       While installing Postfix from source code on the local machine, the
19 #       script is run by the postfix-install script to update selected file
20 #       or directory permissions and to update Postfix configuration files.
21 # .IP o
22 #       While installing Postfix from a pre-built package, the script is run
23 #       by the package management procedure to set all file or directory
24 #       permissions and to update Postfix configuration files.
25 # .IP o
26 #       The script can be used to change installation parameter settings such
27 #       as mail_owner or setgid_group after Postfix is already installed.
28 # .IP o
29 #       The script can be used to upgrade configuration files and to upgrade
30 #       file/directory permissions of a secondary Postfix instance.
31 # .IP o
32 #       At Postfix start-up time, the script is run from "postfix check" to
33 #       create missing queue directories.
34 # .PP
35 #       The post-install script is controlled by installation parameters.
36 #       Specific parameters are described at the end of this document.
37 #       All installation parameters must be specified ahead of time via
38 #       one of the methods described below.
39 #
40 #       Arguments
41 # .IP create-missing
42 #       Create missing queue directories with ownerships and permissions
43 #       according to the contents of $meta_directory/postfix-files
44 #       and optionally in $meta_directory/postfix-files.d/*, using
45 #       the mail_owner and setgid_group parameter settings from the
46 #       command line, process environment or from the installed
47 #       main.cf file.
48 #
49 #       This is required at Postfix start-up time.
50 # .IP set-permissions
51 #       Set all file/directory ownerships and permissions according to the
52 #       contents of $meta_directory/postfix-files and optionally
53 #       in $meta_directory/postfix-files.d/*, using the mail_owner
54 #       and setgid_group parameter settings from the command line,
55 #       process environment or from the installed main.cf file.
56 #       Implies create-missing.
57 #
58 #       This is required when installing Postfix from a pre-built package,
59 #       or when changing the mail_owner or setgid_group installation parameter
60 #       settings after Postfix is already installed.
61 # .IP upgrade-permissions
62 #       Update ownership and permission of existing files/directories as
63 #       specified in $meta_directory/postfix-files and optionally
64 #       in $meta_directory/postfix-files.d/*, using the mail_owner
65 #       and setgid_group parameter settings from the command line,
66 #       process environment or from the installed main.cf file.
67 #       Implies create-missing.
68 #
69 #       This is required when upgrading an existing Postfix instance.
70 # .IP upgrade-configuration
71 #       Edit the installed main.cf and master.cf files, in order to account
72 #       for missing services and to fix deprecated parameter settings.
73 #
74 #       This is required when upgrading an existing Postfix instance.
75 # .IP upgrade-source
76 #       Short-hand for: upgrade-permissions upgrade-configuration.
77 #
78 #       This is recommended when upgrading Postfix from source code.
79 # .IP upgrade-package
80 #       Short-hand for: set-permissions upgrade-configuration.
81 #
82 #       This is recommended when upgrading Postfix from a pre-built package.
83 # .IP first-install-reminder
84 #       Remind the user that they still need to configure main.cf and the
85 #       aliases file, and that newaliases still needs to be run.
86 #
87 #       This is recommended when Postfix is installed for the first time.
88 # MULTIPLE POSTFIX INSTANCES
89 # .ad
90 # .fi
91 #       Multiple Postfix instances on the same machine can share command and
92 #       daemon program files but must have separate configuration and queue
93 #       directories.
94 #
95 #       To create a secondary Postfix installation on the same machine,
96 #       copy the configuration files from the primary Postfix instance to
97 #       a secondary configuration directory and execute:
98 #
99 #       postfix post-install config_directory=secondary-config-directory \e
100 # .in +4
101 #               queue_directory=secondary-queue-directory \e
102 # .br
103 #               create-missing
104 # .PP
105 #       This creates secondary Postfix queue directories, sets their access
106 #       permissions, and saves the specified installation parameters to the
107 #       secondary main.cf file.
108 #
109 #       Be sure to list the secondary configuration directory in the
110 #       alternate_config_directories parameter in the primary main.cf file.
111 #
112 #       To upgrade a secondary Postfix installation on the same machine,
113 #       execute:
114 #
115 #       postfix post-install config_directory=secondary-config-directory \e
116 # .in +4
117 #               upgrade-permissions upgrade-configuration
118 # INSTALLATION PARAMETER INPUT METHODS
119 # .ad
120 # .fi
121 #       Parameter settings can be specified through a variety of
122 #       mechanisms.  In order of decreasing precedence these are:
123 # .IP "command line"
124 #       Parameter settings can be given as name=value arguments on
125 #       the post-install command line. These have the highest precedence.
126 #       Settings that override the installed main.cf file are saved.
127 # .IP "process environment"
128 #       Parameter settings can be given as name=value environment
129 #       variables.
130 #       Settings that override the installed main.cf file are saved.
131 # .IP "installed configuration files"
132 #       If a parameter is not specified via the command line or via the
133 #       process environment, post-install will attempt to extract its
134 #       value from the already installed Postfix main.cf configuration file.
135 #       These settings have the lowest precedence.
136 # INSTALLATION PARAMETER DESCRIPTION
137 # .ad
138 # .fi
139 #       The description of installation parameters is as follows:
140 # .IP config_directory
141 #       The directory for Postfix configuration files.
142 # .IP daemon_directory
143 #       The directory for Postfix daemon programs. This directory
144 #       should not be in the command search path of any users.
145 # .IP command_directory
146 #       The directory for Postfix administrative commands. This
147 #       directory should be in the command search path of adminstrative users.
148 # .IP queue_directory
149 #       The directory for Postfix queues.
150 # .IP data_directory
151 #       The directory for Postfix writable data files (caches, etc.).
152 # .IP sendmail_path
153 #       The full pathname for the Postfix sendmail command.
154 #       This is the Sendmail-compatible mail posting interface.
155 # .IP newaliases_path
156 #       The full pathname for the Postfix newaliases command.
157 #       This is the Sendmail-compatible command to build alias databases
158 #       for the Postfix local delivery agent.
159 # .IP mailq_path
160 #       The full pathname for the Postfix mailq command.
161 #       This is the Sendmail-compatible command to list the mail queue.
162 # .IP mail_owner
163 #       The owner of the Postfix queue. Its numerical user ID and group ID
164 #       must not be used by any other accounts on the system.
165 # .IP setgid_group
166 #       The group for mail submission and for queue management commands.
167 #       Its numerical group ID must not be used by any other accounts on the
168 #       system, not even by the mail_owner account.
169 # .IP html_directory
170 #       The directory for the Postfix HTML files.
171 # .IP manpage_directory
172 #       The directory for the Postfix on-line manual pages.
173 # .IP sample_directory
174 #       The directory for the Postfix sample configuration files.
175 #       This feature is obsolete as of Postfix 2.1.
176 # .IP readme_directory
177 #       The directory for the Postfix README files.
178 # .IP shlib_directory
179 #       The directory for the Postfix shared-library files, and for
180 #       the Postfix dabatase plugin files with a relative pathname
181 #       in the file dynamicmaps.cf.
182 # .IP meta_directory
183 #       The directory for non-executable files that are shared
184 #       among multiple Postfix instances, such as postfix-files,
185 #       dynamicmaps.cf, as well as the multi-instance template files
186 #       main.cf.proto and master.cf.proto.
187 # SEE ALSO
188 #       postfix-install(1) Postfix primary installation script.
189 # FILES
190 #       $config_directory/main.cf, Postfix installation parameters.
191 #       $meta_directory/postfix-files, installation control file.
192 #       $meta_directory/postfix-files.d/*, optional control files.
193 #       $config_directory/install.cf, obsolete configuration file.
194 # LICENSE
195 # .ad
196 # .fi
197 #       The Secure Mailer license must be distributed with this software.
198 # AUTHOR(S)
199 #       Wietse Venema
200 #       IBM T.J. Watson Research
201 #       P.O. Box 704
202 #       Yorktown Heights, NY 10598, USA
203 #
204 #       Wietse Venema
205 #       Google, Inc.
206 #       111 8th Avenue
207 #       New York, NY 10011, USA
208 #--
209
210 umask 022
211
212 PATH=/bin:/usr/bin:/usr/sbin:/usr/etc:/sbin:/etc:/usr/contrib/bin:/usr/gnu/bin:/usr/ucb:/usr/bsd
213 SHELL=/bin/sh
214 IFS="   
215 "
216 BACKUP_IFS="$IFS"
217 debug=:
218 #debug=echo
219 MOST_PARAMETERS="command_directory daemon_directory data_directory
220     html_directory mail_owner mailq_path manpage_directory
221     newaliases_path queue_directory readme_directory sample_directory
222     sendmail_path setgid_group shlib_directory meta_directory"
223 NON_SHARED="config_directory queue_directory data_directory"
224
225 USAGE="Usage: $0 [name=value] command
226     create-missing          Create missing queue directories.
227     upgrade-source          When installing or upgrading from source code.
228     upgrade-package         When installing or upgrading from pre-built package.
229     first-install-reminder  Remind of mandatory first-time configuration steps.
230     name=value              Specify an installation parameter".
231
232 # Process command-line options and parameter settings. Work around
233 # brain damaged shells. "IFS=value command" should not make the
234 # IFS=value setting permanent. But some broken standard allows it.
235
236 create=; set_perms=; upgrade_perms=; upgrade_conf=; first_install_reminder=
237 obsolete=; keep_list=;
238
239 for arg
240 do
241     case $arg in
242         *["     "]*) echo $0: "Error: argument contains whitespace: '$arg'"
243                      exit 1;;
244                 *=*) IFS= eval $arg; IFS="$BACKUP_IFS";;
245      create-missing) create=1;;
246           set-perm*) create=1; set_perms=1;;
247       upgrade-perm*) create=1; upgrade_perms=1;;
248       upgrade-conf*) upgrade_conf=1;;
249      upgrade-source) create=1; upgrade_conf=1; upgrade_perms=1;;
250     upgrade-package) create=1; upgrade_conf=1; set_perms=1;;
251      first-install*) first_install_reminder=1;;
252                   *) echo "$0: Error: $USAGE" 1>&2; exit 1;;
253     esac
254     shift
255 done
256
257 # Sanity checks.
258
259 test -n "$create$upgrade_conf$first_install_reminder" || {
260     echo "$0: Error: $USAGE" 1>&2
261     exit 1
262 }
263
264 # Bootstrapping problem.
265
266 if [ -n "$command_directory" ]
267 then
268     POSTCONF="$command_directory/postconf"
269 else
270     POSTCONF="postconf"
271 fi
272
273 $POSTCONF -d mail_version >/dev/null 2>/dev/null || {
274     echo $0: Error: no $POSTCONF command found. 1>&2
275     echo Re-run this command as $0 command_directory=/some/where. 1>&2
276     exit 1
277 }
278
279 # Also used to require license etc. files only in the default instance.
280
281 def_config_directory=`$POSTCONF -d -h config_directory` || exit 1
282 test -n "$config_directory" ||
283     config_directory="$def_config_directory"
284
285 test -d "$config_directory" || {
286     echo $0: Error: $config_directory is not a directory. 1>&2
287     exit 1
288 }
289
290 # If this is a secondary instance, don't touch shared files.
291 # XXX Solaris does not have "test -e".
292
293 instances=`test ! -f $def_config_directory/main.cf || 
294     $POSTCONF -c $def_config_directory -h multi_instance_directories | 
295         sed 's/,/ /'` || exit 1
296
297 update_shared_files=1
298 for name in $instances
299 do
300     case "$name" in
301     "$def_config_directory") ;;
302     "$config_directory") update_shared_files=; break;;
303     esac
304 done
305
306 test -f $meta_directory/postfix-files || {
307     echo $0: Error: $meta_directory/postfix-files is not a file. 1>&2
308     exit 1
309 }
310
311 # SunOS5 fmt(1) truncates lines > 1000 characters.
312
313 fake_fmt() {
314     sed '
315     :top
316         /^\(  *\)\([^ ][^ ]*\)  */{
317             s//\1\2\
318 \1/
319             P
320             D
321             b top
322         }
323     ' | fmt
324 }
325
326 case `uname -s` in
327 HP-UX*) FMT=cat;;
328 SunOS*) FMT=fake_fmt;;
329      *) FMT=fmt;;
330 esac
331
332 # If a parameter is not set via the command line or environment,
333 # try to use settings from installed configuration files.
334
335 # Extract parameter settings from the obsolete install.cf file, as
336 # a transitional aid.
337
338 grep setgid_group $config_directory/main.cf >/dev/null 2>&1 || {
339     test -f $config_directory/install.cf  && {
340         for name in sendmail_path newaliases_path mailq_path setgid manpages
341         do
342         eval junk=\$$name
343         case "$junk" in
344         "") eval unset $name;;
345         esac
346            eval : \${$name="\`. $config_directory/install.cf; echo \$$name\`"} \
347                 || exit 1
348         done
349         : ${setgid_group=$setgid}
350         : ${manpage_directory=$manpages}
351     }
352 }
353
354 # Extract parameter settings from the installed main.cf file.
355
356 test -f $config_directory/main.cf && {
357     for name in $MOST_PARAMETERS
358     do
359         eval junk=\$$name
360         case "$junk" in
361         "") eval unset $name;;
362         esac
363         eval : \${$name=\`$POSTCONF -c $config_directory -h $name\`} || exit 1
364     done
365 }
366
367 # Sanity checks
368
369 case $manpage_directory in
370  no) echo $0: Error: manpage_directory no longer accepts \"no\" values. 1>&2
371      echo Try again with \"$0 manpage_directory=/pathname ...\". 1>&2; exit 1;;
372 esac
373
374 case $setgid_group in
375  no) echo $0: Error: setgid_group no longer accepts \"no\" values. 1>&2
376      echo Try again with \"$0 setgid_group=groupname ...\" 1>&2; exit 1;;
377 esac
378
379 for path in "$daemon_directory" "$command_directory" "$queue_directory" \
380     "$sendmail_path" "$newaliases_path" "$mailq_path" "$manpage_directory" \
381     "$meta_directory"
382 do
383    case "$path" in
384    /*) ;;
385     *) echo $0: Error: \"$path\" should be an absolute path name. 1>&2; exit 1;;
386    esac
387 done
388
389 for path in "$html_directory" "$readme_directory" "$shlib_directory"
390 do
391    case "$path" in
392    /*) ;;
393    no) ;;
394     *) echo $0: Error: \"$path\" should be \"no\" or an absolute path name. 1>&2; exit 1;;
395    esac
396 done
397
398 # Find out what parameters were not specified via command line,
399 # via environment, or via installed configuration files.
400
401 missing=
402 for name in $MOST_PARAMETERS
403 do
404     eval test -n \"\$$name\" || missing="$missing $name"
405 done
406
407 # All parameters must be specified at this point.
408
409 test -n "$non_interactive" -a -n "$missing" && {
410     cat <<EOF | ${FMT} 1>&2
411 $0: Error: some required installation parameters are not defined.
412
413 - Either the parameters need to be given in the $config_directory/main.cf
414 file from a recent Postfix installation,
415
416 - Or the parameters need to be specified through the process
417 environment.
418
419 - Or the parameters need to be specified as name=value arguments
420 on the $0 command line,
421
422 The following parameters were missing:
423
424     $missing
425
426 EOF
427     exit 1
428 }
429
430 POSTCONF="$command_directory/postconf"
431
432 # Save settings, allowing command line/environment override.
433
434 # Undo MAIL_VERSION expansion at the end of a parameter value. If
435 # someone really wants the expanded mail version in main.cf, then
436 # we're sorry.
437
438 # Confine side effects from mail_version unexpansion within a subshell.
439
440 (case "$mail_version" in
441 "") mail_version="`$POSTCONF -dhx mail_version`" || exit 1
442 esac
443
444 for name in $MOST_PARAMETERS
445 do
446     eval junk=\$$name
447     case "$junk" in
448     *"$mail_version"*) 
449         case "$pattern" in
450         "") pattern=`echo "$mail_version" | sed 's/\./\\\\./g'` || exit 1
451         esac
452         val=`echo "$junk" | sed "s/$pattern"'$/${mail_version}/g'` || exit 1
453         eval ${name}='"$val"'
454     esac
455 done
456
457 # XXX Maybe update main.cf only with first install, upgrade, set
458 # permissions, and what else? Should there be a warning otherwise?
459
460 override=
461 for name in $MOST_PARAMETERS
462 do
463     eval junk=\"\$$name\"
464     test "$junk" = "`$POSTCONF -c $config_directory -h $name`" || {
465         override=1
466         break
467     }
468 done
469
470 test -n "$override" && {
471     $POSTCONF -c $config_directory -e \
472         "daemon_directory = $daemon_directory" \
473         "command_directory = $command_directory" \
474         "queue_directory = $queue_directory" \
475         "data_directory = $data_directory" \
476         "mail_owner = $mail_owner" \
477         "setgid_group = $setgid_group" \
478         "sendmail_path = $sendmail_path" \
479         "mailq_path = $mailq_path" \
480         "newaliases_path = $newaliases_path" \
481         "html_directory = $html_directory" \
482         "manpage_directory = $manpage_directory" \
483         "sample_directory = $sample_directory" \
484         "readme_directory = $readme_directory" \
485         "shlib_directory = $shlib_directory" \
486         "meta_directory = $meta_directory" \
487     || exit 1
488 } || exit 0) || exit 1
489
490 # Use file/directory status information in $meta_directory/postfix-files.
491
492 test -n "$create" && {
493     postfix_files_d=$meta_directory/postfix-files.d
494     for postfix_file in $meta_directory/postfix-files \
495         `test -d $postfix_files_d && { find $postfix_files_d -type f | sort; }`
496     do
497         exec <$postfix_file || exit 1
498         while IFS=: read path type owner group mode flags junk
499         do
500             IFS="$BACKUP_IFS"
501             set_permission=
502             # Skip comments. Skip shared files, if updating a secondary instance.
503             case $path in
504             [$]*) case "$update_shared_files" in
505                   1) $debug keep non-shared or shared $path;;
506                   *) non_shared=
507                      for name in $NON_SHARED
508                      do
509                          case $path in
510                          "\$$name"*) non_shared=1; break;;
511                          esac
512                      done
513                      case "$non_shared" in
514                       1) $debug keep non-shared $path;;
515                       *) $debug skip shared $path; continue;;
516                      esac;;
517                   esac;;
518                *) continue;;
519             esac
520             # Skip hard links and symbolic links.
521             case $type in
522             [hl]) continue;;
523             [df]) ;;
524                *) echo unknown type $type for $path in $postfix_file 1>&2; exit 1;;
525             esac
526             # Expand $name, and canonicalize null fields.
527             for name in path owner group flags
528             do
529                 eval junk=\${$name}
530                 case $junk in
531                 [$]*) eval $name=$junk;;
532                    -) eval $name=;;
533                    *) ;;
534                 esac
535             done
536             # Skip uninstalled files.
537             case $path in
538             no|no/*) continue;;
539             esac
540             # Pick up the flags.
541             case $flags in *u*) upgrade_flag=1;; *) upgrade_flag=;; esac
542             case $flags in *c*) create_flag=1;; *) create_flag=;; esac
543             case $flags in *r*) recursive="-R";; *) recursive=;; esac
544             case $flags in *o*) obsolete_flag=1;; *) obsolete_flag=;; esac
545             case $flags in *[1i]*) test ! -r "$path" -a "$config_directory" != \
546                                     "$def_config_directory" && continue;; esac
547             # Flag obsolete objects. XXX Solaris 2..9 does not have "test -e".
548             if [ -n "$obsolete_flag" ]
549             then
550                 test -r $path -a "$type" != "d" && obsolete="$obsolete $path"
551                 continue;
552             else
553                 keep_list="$keep_list $path"
554             fi
555             # Create missing directories with proper owner/group/mode settings.
556             if [ -n "$create" -a "$type" = "d" -a -n "$create_flag" -a ! -d "$path" ]
557             then
558                 mkdir $path || exit 1
559                 set_permission=1
560             # Update all owner/group/mode settings.
561             elif [ -n "$set_perms" ]
562             then
563                 set_permission=1
564             # Update obsolete owner/group/mode settings.
565             elif [ -n "$upgrade_perms" -a -n "$upgrade_flag" ]
566             then
567                 set_permission=1
568             fi
569             test -n "$set_permission" && {
570                 chown $recursive $owner $path || exit 1
571                 test -z "$group" || chgrp $recursive $group $path || exit 1
572                 # Don't "chmod -R"; queue file status is encoded in mode bits.
573                 if [ "$type" = "d" -a -n "$recursive" ]
574                 then
575                     find $path -type d -exec chmod $mode "{}" ";"
576                 else
577                     chmod $mode $path
578                 fi || exit 1
579             }
580         done
581         IFS="$BACKUP_IFS"
582     done
583 }
584
585 # Upgrade existing Postfix configuration files if necessary.
586
587 test -n "$upgrade_conf" && {
588
589     # Postfix 2.0.
590     # Add missing relay service to master.cf.
591
592     grep '^relay' $config_directory/master.cf >/dev/null || {
593         echo Editing $config_directory/master.cf, adding missing entry for relay service
594         cat >>$config_directory/master.cf <<EOF || exit 1
595 relay     unix  -       -       n       -       -       smtp
596 EOF
597     }
598
599     # Postfix 1.1.
600     # Add missing flush service to master.cf.
601
602     grep '^flush.*flush' $config_directory/master.cf >/dev/null || {
603         echo Editing $config_directory/master.cf, adding missing entry for flush service
604         cat >>$config_directory/master.cf <<EOF || exit 1
605 flush     unix  -       -       n       1000?   0       flush
606 EOF
607     }
608
609     # Postfix 2.1.
610     # Add missing trace service to master.cf.
611
612     grep 'trace.*bounce' $config_directory/master.cf >/dev/null || {
613         echo Editing $config_directory/master.cf, adding missing entry for trace service
614         cat >>$config_directory/master.cf <<EOF || exit 1
615 trace     unix  -       -       n       -       0       bounce
616 EOF
617     }
618
619     # Postfix 2.1.
620     # Add missing verify service to master.cf.
621
622     grep '^verify.*verify' $config_directory/master.cf >/dev/null || {
623         echo Editing $config_directory/master.cf, adding missing entry for verify service
624         cat >>$config_directory/master.cf <<EOF || exit 1
625 verify    unix  -       -       n       -       1       verify
626 EOF
627     }
628
629     # Postfix 2.1.
630     # Fix verify service process limit.
631
632     grep '^verify.*[    ]0[     ]*verify' \
633         $config_directory/master.cf >/dev/null && {
634             echo Editing $config_directory/master.cf, setting verify process limit to 1
635             ed $config_directory/master.cf <<EOF || exit 1
636 /^verify.*[     ]0[     ]*verify/
637 s/\([   ]\)0\([         ]\)/\11\2/
638 p
639 w
640 q
641 EOF
642     }
643
644     # Postfix 1.1.
645     # Change privileged pickup service into unprivileged.
646
647     grep "^pickup[      ]*fifo[         ]*n[    ]*n" \
648         $config_directory/master.cf >/dev/null && {
649             echo Editing $config_directory/master.cf, making the pickup service unprivileged
650             ed $config_directory/master.cf <<EOF || exit 1
651 /^pickup[       ]*fifo[         ]*n[    ]*n/
652 s/\(n[  ]*\)n/\1-/
653 p
654 w
655 q
656 EOF
657     }
658
659     # Postfix 1.1.
660     # Change private cleanup and flush services into public.
661
662     for name in cleanup flush
663     do
664         grep "^$name[   ]*unix[         ]*[-y]" \
665             $config_directory/master.cf >/dev/null && {
666                 echo Editing $config_directory/master.cf, making the $name service public
667             ed $config_directory/master.cf <<EOF || exit 1
668 /^$name[        ]*unix[         ]*[-y]/
669 s/[-y]/n/
670 p
671 w
672 q
673 EOF
674         }
675     done
676
677     # Postfix 2.2.
678     # File systems have improved since Postfix came out, and all we
679     # require now is that defer and deferred are hashed because those
680     # can contain lots of files.
681
682     found=`$POSTCONF -c $config_directory -h hash_queue_names`
683     missing=
684     (echo "$found" | grep defer >/dev/null)  || missing="$missing defer"
685     (echo "$found" | grep deferred>/dev/null)|| missing="$missing deferred"
686     test -n "$missing" && {
687         echo fixing main.cf hash_queue_names for missing $missing
688         $POSTCONF -c $config_directory -e hash_queue_names="$found$missing" ||
689             exit 1
690     }
691
692     # Turn on safety nets for new features that could bounce mail that
693     # would be accepted by a previous Postfix version.
694
695     # [The "unknown_local_recipient_reject_code = 450" safety net,
696     # introduced with Postfix 2.0 and deleted after Postfix 2.3.]
697
698     # Postfix 2.0.
699     # Add missing proxymap service to master.cf.
700
701     grep '^proxymap.*proxymap' $config_directory/master.cf >/dev/null || {
702         echo Editing $config_directory/master.cf, adding missing entry for proxymap service
703         cat >>$config_directory/master.cf <<EOF || exit 1
704 proxymap  unix  -       -       n       -       -       proxymap
705 EOF
706     }
707
708     # Postfix 2.1.
709     # Add missing anvil service to master.cf.
710
711     grep '^anvil.*anvil' $config_directory/master.cf >/dev/null || {
712         echo Editing $config_directory/master.cf, adding missing entry for anvil service
713         cat >>$config_directory/master.cf <<EOF || exit 1
714 anvil     unix  -       -       n       -       1       anvil
715 EOF
716     }
717
718     # Postfix 2.2.
719     # Add missing scache service to master.cf.
720
721     grep '^scache.*scache' $config_directory/master.cf >/dev/null || {
722         echo Editing $config_directory/master.cf, adding missing entry for scache service
723         cat >>$config_directory/master.cf <<EOF || exit 1
724 scache    unix  -       -       n       -       1       scache
725 EOF
726     }
727
728     # Postfix 2.2.
729     # Add missing discard service to master.cf.
730
731     grep '^discard.*discard' $config_directory/master.cf >/dev/null || {
732         echo Editing $config_directory/master.cf, adding missing entry for discard service
733         cat >>$config_directory/master.cf <<EOF || exit 1
734 discard   unix  -       -       n       -       -       discard
735 EOF
736     }
737
738     # Postfix 2.2.
739     # Update the tlsmgr fifo->unix service.
740
741     grep "^tlsmgr[      ]*fifo[         ]" \
742         $config_directory/master.cf >/dev/null && {
743             echo Editing $config_directory/master.cf, updating the tlsmgr from fifo to unix service
744             ed $config_directory/master.cf <<EOF || exit 1
745 /^tlsmgr[       ]*fifo[         ]/
746 s/fifo/unix/
747 s/[0-9][0-9]*/&?/
748 p
749 w
750 q
751 EOF
752     }
753
754     # Postfix 2.2.
755     # Add missing tlsmgr service to master.cf.
756
757     grep '^tlsmgr.*tlsmgr' $config_directory/master.cf >/dev/null || {
758         echo Editing $config_directory/master.cf, adding missing entry for tlsmgr service
759         cat >>$config_directory/master.cf <<EOF || exit 1
760 tlsmgr    unix  -       -       n       1000?   1       tlsmgr
761 EOF
762     }
763
764     # Postfix 2.2.
765     # Add missing retry service to master.cf.
766
767     grep '^retry.*error' $config_directory/master.cf >/dev/null || {
768         echo Editing $config_directory/master.cf, adding missing entry for retry service
769         cat >>$config_directory/master.cf <<EOF || exit 1
770 retry     unix  -       -       n       -       -       error
771 EOF
772     }
773
774     # Postfix 2.5.
775     # Add missing proxywrite service to master.cf.
776
777     grep '^proxywrite.*proxymap' $config_directory/master.cf >/dev/null || {
778         echo Editing $config_directory/master.cf, adding missing entry for proxywrite service
779         cat >>$config_directory/master.cf <<EOF || exit 1
780 proxywrite unix -       -       n       -       1       proxymap
781 EOF
782     }
783
784     # Postfix 2.5.
785     # Fix a typo in the default master.cf proxywrite entry.
786
787     grep '^proxywrite.*-[       ]*proxymap' $config_directory/master.cf >/dev/null && {
788         echo Editing $config_directory/master.cf, setting proxywrite process limit to 1
789             ed $config_directory/master.cf <<EOF || exit 1
790 /^proxywrite.*-[        ]*proxymap/
791 s/-\([  ]*proxymap\)/1\1/
792 p
793 w
794 q
795 EOF
796     }
797
798     # Postfix 2.8.
799     # Add missing postscreen service to master.cf.
800
801     grep '^#*smtp.*postscreen' $config_directory/master.cf >/dev/null || {
802         echo Editing $config_directory/master.cf, adding missing entry for postscreen TCP service
803         cat >>$config_directory/master.cf <<EOF || exit 1
804 #smtp      inet  n       -       n       -       1       postscreen
805 EOF
806     }
807
808     # Postfix 2.8.
809     # Add missing smtpd (unix-domain) service to master.cf.
810
811     grep '^#*smtpd.*smtpd' $config_directory/master.cf >/dev/null || {
812         echo Editing $config_directory/master.cf, adding missing entry for smtpd unix-domain service
813         cat >>$config_directory/master.cf <<EOF || exit 1
814 #smtpd     pass  -       -       n       -       -       smtpd
815 EOF
816     }
817
818     # Postfix 2.8.
819     # Add temporary dnsblog (unix-domain) service to master.cf.
820
821     grep '^#*dnsblog.*dnsblog' $config_directory/master.cf >/dev/null || {
822         echo Editing $config_directory/master.cf, adding missing entry for dnsblog unix-domain service
823         cat >>$config_directory/master.cf <<EOF || exit 1
824 #dnsblog   unix  -       -       n       -       0       dnsblog
825 EOF
826     }
827
828     # Postfix 2.8.
829     # Add tlsproxy (unix-domain) service to master.cf.
830
831     grep '^#*tlsproxy.*tlsproxy' $config_directory/master.cf >/dev/null || {
832         echo Editing $config_directory/master.cf, adding missing entry for tlsproxy unix-domain service
833         cat >>$config_directory/master.cf <<EOF || exit 1
834 #tlsproxy  unix  -       -       n       -       0       tlsproxy
835 EOF
836     }
837
838     # Report (but do not remove) obsolete files.
839
840     test -n "$obsolete" && {
841         cat <<EOF | ${FMT}
842
843     Note: the following files or directories still exist but are
844     no longer part of Postfix:
845
846     $obsolete
847
848 EOF
849     }
850
851     # Postfix 2.9.
852     # Safety net for incompatible changes in IPv6 defaults.
853     # PLEASE DO NOT REMOVE THIS CODE. ITS PURPOSE IS TO AVOID AN
854     # UNEXPECTED DROP IN PERFORMANCE AFTER UPGRADING FROM POSTFIX
855     # BEFORE 2.9.
856     # This code assumes that the default is "inet_protocols = ipv4"
857     # when IPv6 support is not compiled in. See util/sys_defs.h.
858
859     test "`$POSTCONF -dh inet_protocols`" = "ipv4" ||
860         test -n "`$POSTCONF -c $config_directory -n inet_protocols`" || {
861         cat <<EOF | ${FMT}
862     COMPATIBILITY: editing $config_directory/main.cf, setting
863     inet_protocols=ipv4.  Specify inet_protocols explicitly if you
864     want to enable IPv6.
865     In a future release IPv6 will be enabled by default.
866 EOF
867         $POSTCONF -c $config_directory inet_protocols=ipv4 || exit 1
868     }
869
870 # Disabled because unhelpful down-stream maintainers disable the safety net.
871 #    # Postfix 2.10.
872 #    # Safety net for incompatible changes due to the introduction
873 #    # of the smtpd_relay_restrictions feature to separate the
874 #    # mail relay policy from the spam blocking policy.
875 #    # PLEASE DO NOT REMOVE THIS CODE. ITS PURPOSE IS TO PREVENT
876 #    # INBOUND MAIL FROM UNEXPECTEDLY BOUNCING AFTER UPGRADING FROM
877 #    # POSTFIX BEFORE 2.10.
878 #    test -n "`$POSTCONF -c $config_directory -n smtpd_relay_restrictions`" || {
879 #       cat <<EOF | ${FMT}
880 #    COMPATIBILITY: editing $config_directory/main.cf, overriding
881 #    smtpd_relay_restrictions to prevent inbound mail from
882 #    unexpectedly bouncing.
883 #    Specify an empty smtpd_relay_restrictions value to keep using 
884 #    smtpd_recipient_restrictions as before.
885 #EOF
886 #       $POSTCONF -c $config_directory "smtpd_relay_restrictions = \
887 #           permit_mynetworks permit_sasl_authenticated \
888 #           defer_unauth_destination" || exit 1
889 #    }
890 }
891
892 # A reminder if this is the first time Postfix is being installed.
893
894 test -n "$first_install_reminder" && {
895
896     ALIASES=`$POSTCONF -c $config_directory -h alias_database | sed 's/^[^:]*://'`
897     NEWALIASES_PATH=`$POSTCONF -c $config_directory -h newaliases_path`
898     cat <<EOF | ${FMT}
899
900     Warning: you still need to edit myorigin/mydestination/mynetworks
901     parameter settings in $config_directory/main.cf.
902
903     See also http://www.postfix.org/STANDARD_CONFIGURATION_README.html
904     for information about dialup sites or about sites inside a
905     firewalled network.
906
907     BTW: Check your $ALIASES file and be sure to set up aliases
908     that send mail for root and postmaster to a real person, then
909     run $NEWALIASES_PATH.
910
911 EOF
912
913 }
914
915 exit 0