New configs for Xenial (16.04)
[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
205 umask 022
206
207 PATH=/bin:/usr/bin:/usr/sbin:/usr/etc:/sbin:/etc:/usr/contrib/bin:/usr/gnu/bin:/usr/ucb:/usr/bsd
208 SHELL=/bin/sh
209 IFS="   
210 "
211 BACKUP_IFS="$IFS"
212 debug=:
213 #debug=echo
214 MOST_PARAMETERS="command_directory daemon_directory data_directory
215     html_directory mail_owner mailq_path manpage_directory
216     newaliases_path queue_directory readme_directory sample_directory
217     sendmail_path setgid_group shlib_directory meta_directory"
218 NON_SHARED="config_directory queue_directory data_directory"
219
220 USAGE="Usage: $0 [name=value] command
221     create-missing          Create missing queue directories.
222     upgrade-source          When installing or upgrading from source code.
223     upgrade-package         When installing or upgrading from pre-built package.
224     first-install-reminder  Remind of mandatory first-time configuration steps.
225     name=value              Specify an installation parameter".
226
227 # Process command-line options and parameter settings. Work around
228 # brain damaged shells. "IFS=value command" should not make the
229 # IFS=value setting permanent. But some broken standard allows it.
230
231 create=; set_perms=; upgrade_perms=; upgrade_conf=; first_install_reminder=
232 obsolete=; keep_list=;
233
234 for arg
235 do
236     case $arg in
237         *["     "]*) echo $0: "Error: argument contains whitespace: '$arg'"
238                      exit 1;;
239                 *=*) IFS= eval $arg; IFS="$BACKUP_IFS";;
240      create-missing) create=1;;
241           set-perm*) create=1; set_perms=1;;
242       upgrade-perm*) create=1; upgrade_perms=1;;
243       upgrade-conf*) upgrade_conf=1;;
244      upgrade-source) create=1; upgrade_conf=1; upgrade_perms=1;;
245     upgrade-package) create=1; upgrade_conf=1; set_perms=1;;
246      first-install*) first_install_reminder=1;;
247                   *) echo "$0: Error: $USAGE" 1>&2; exit 1;;
248     esac
249     shift
250 done
251
252 # Sanity checks.
253
254 test -n "$create$upgrade_conf$first_install_reminder" || {
255     echo "$0: Error: $USAGE" 1>&2
256     exit 1
257 }
258
259 # Bootstrapping problem.
260
261 if [ -n "$command_directory" ]
262 then
263     POSTCONF="$command_directory/postconf"
264 else
265     POSTCONF="postconf"
266 fi
267
268 $POSTCONF -d mail_version >/dev/null 2>/dev/null || {
269     echo $0: Error: no $POSTCONF command found. 1>&2
270     echo Re-run this command as $0 command_directory=/some/where. 1>&2
271     exit 1
272 }
273
274 # Also used to require license etc. files only in the default instance.
275
276 def_config_directory=`$POSTCONF -d -h config_directory` || exit 1
277 test -n "$config_directory" ||
278     config_directory="$def_config_directory"
279
280 test -d "$config_directory" || {
281     echo $0: Error: $config_directory is not a directory. 1>&2
282     exit 1
283 }
284
285 # If this is a secondary instance, don't touch shared files.
286 # XXX Solaris does not have "test -e".
287
288 instances=`test ! -f $def_config_directory/main.cf || 
289     $POSTCONF -c $def_config_directory -h multi_instance_directories | 
290         sed 's/,/ /'` || exit 1
291
292 update_shared_files=1
293 for name in $instances
294 do
295     case "$name" in
296     "$def_config_directory") ;;
297     "$config_directory") update_shared_files=; break;;
298     esac
299 done
300
301 test -f $meta_directory/postfix-files || {
302     echo $0: Error: $meta_directory/postfix-files is not a file. 1>&2
303     exit 1
304 }
305
306 # SunOS5 fmt(1) truncates lines > 1000 characters.
307
308 fake_fmt() {
309     sed '
310     :top
311         /^\(  *\)\([^ ][^ ]*\)  */{
312             s//\1\2\
313 \1/
314             P
315             D
316             b top
317         }
318     ' | fmt
319 }
320
321 case `uname -s` in
322 HP-UX*) FMT=cat;;
323 SunOS*) FMT=fake_fmt;;
324      *) FMT=fmt;;
325 esac
326
327 # If a parameter is not set via the command line or environment,
328 # try to use settings from installed configuration files.
329
330 # Extract parameter settings from the obsolete install.cf file, as
331 # a transitional aid.
332
333 grep setgid_group $config_directory/main.cf >/dev/null 2>&1 || {
334     test -f $config_directory/install.cf  && {
335         for name in sendmail_path newaliases_path mailq_path setgid manpages
336         do
337         eval junk=\$$name
338         case "$junk" in
339         "") eval unset $name;;
340         esac
341            eval : \${$name="\`. $config_directory/install.cf; echo \$$name\`"} \
342                 || exit 1
343         done
344         : ${setgid_group=$setgid}
345         : ${manpage_directory=$manpages}
346     }
347 }
348
349 # Extract parameter settings from the installed main.cf file.
350
351 test -f $config_directory/main.cf && {
352     for name in $MOST_PARAMETERS
353     do
354         eval junk=\$$name
355         case "$junk" in
356         "") eval unset $name;;
357         esac
358         eval : \${$name=\`$POSTCONF -c $config_directory -h $name\`} || exit 1
359     done
360 }
361
362 # Sanity checks
363
364 case $manpage_directory in
365  no) echo $0: Error: manpage_directory no longer accepts \"no\" values. 1>&2
366      echo Try again with \"$0 manpage_directory=/pathname ...\". 1>&2; exit 1;;
367 esac
368
369 case $setgid_group in
370  no) echo $0: Error: setgid_group no longer accepts \"no\" values. 1>&2
371      echo Try again with \"$0 setgid_group=groupname ...\" 1>&2; exit 1;;
372 esac
373
374 for path in "$daemon_directory" "$command_directory" "$queue_directory" \
375     "$sendmail_path" "$newaliases_path" "$mailq_path" "$manpage_directory" \
376     "$meta_directory"
377 do
378    case "$path" in
379    /*) ;;
380     *) echo $0: Error: \"$path\" should be an absolute path name. 1>&2; exit 1;;
381    esac
382 done
383
384 for path in "$html_directory" "$readme_directory" "$shlib_directory"
385 do
386    case "$path" in
387    /*) ;;
388    no) ;;
389     *) echo $0: Error: \"$path\" should be \"no\" or an absolute path name. 1>&2; exit 1;;
390    esac
391 done
392
393 # Find out what parameters were not specified via command line,
394 # via environment, or via installed configuration files.
395
396 missing=
397 for name in $MOST_PARAMETERS
398 do
399     eval test -n \"\$$name\" || missing="$missing $name"
400 done
401
402 # All parameters must be specified at this point.
403
404 test -n "$non_interactive" -a -n "$missing" && {
405     cat <<EOF | ${FMT} 1>&2
406 $0: Error: some required installation parameters are not defined.
407
408 - Either the parameters need to be given in the $config_directory/main.cf
409 file from a recent Postfix installation,
410
411 - Or the parameters need to be specified through the process
412 environment.
413
414 - Or the parameters need to be specified as name=value arguments
415 on the $0 command line,
416
417 The following parameters were missing:
418
419     $missing
420
421 EOF
422     exit 1
423 }
424
425 POSTCONF="$command_directory/postconf"
426
427 # Save settings, allowing command line/environment override.
428
429 # Undo MAIL_VERSION expansion at the end of a parameter value. If
430 # someone really wants the expanded mail version in main.cf, then
431 # we're sorry.
432
433 # Confine side effects from mail_version unexpansion within a subshell.
434
435 (case "$mail_version" in
436 "") mail_version="`$POSTCONF -dhx mail_version`" || exit 1
437 esac
438
439 for name in $MOST_PARAMETERS
440 do
441     eval junk=\$$name
442     case "$junk" in
443     *"$mail_version"*) 
444         case "$pattern" in
445         "") pattern=`echo "$mail_version" | sed 's/\./\\\\./g'` || exit 1
446         esac
447         val=`echo "$junk" | sed "s/$pattern"'$/${mail_version}/g'` || exit 1
448         eval ${name}='"$val"'
449     esac
450 done
451
452 # XXX Maybe update main.cf only with first install, upgrade, set
453 # permissions, and what else? Should there be a warning otherwise?
454
455 override=
456 for name in $MOST_PARAMETERS
457 do
458     eval junk=\"\$$name\"
459     test "$junk" = "`$POSTCONF -c $config_directory -h $name`" || {
460         override=1
461         break
462     }
463 done
464
465 test -n "$override" && {
466     $POSTCONF -c $config_directory -e \
467         "daemon_directory = $daemon_directory" \
468         "command_directory = $command_directory" \
469         "queue_directory = $queue_directory" \
470         "data_directory = $data_directory" \
471         "mail_owner = $mail_owner" \
472         "setgid_group = $setgid_group" \
473         "sendmail_path = $sendmail_path" \
474         "mailq_path = $mailq_path" \
475         "newaliases_path = $newaliases_path" \
476         "html_directory = $html_directory" \
477         "manpage_directory = $manpage_directory" \
478         "sample_directory = $sample_directory" \
479         "readme_directory = $readme_directory" \
480         "shlib_directory = $shlib_directory" \
481         "meta_directory = $meta_directory" \
482     || exit 1
483 } || exit 0) || exit 1
484
485 # Use file/directory status information in $meta_directory/postfix-files.
486
487 test -n "$create" && {
488     postfix_files_d=$meta_directory/postfix-files.d
489     for postfix_file in $meta_directory/postfix-files \
490         `test -d $postfix_files_d && { find $postfix_files_d -type f | sort; }`
491     do
492         exec <$postfix_file || exit 1
493         while IFS=: read path type owner group mode flags junk
494         do
495             IFS="$BACKUP_IFS"
496             set_permission=
497             # Skip comments. Skip shared files, if updating a secondary instance.
498             case $path in
499             [$]*) case "$update_shared_files" in
500                   1) $debug keep non-shared or shared $path;;
501                   *) non_shared=
502                      for name in $NON_SHARED
503                      do
504                          case $path in
505                          "\$$name"*) non_shared=1; break;;
506                          esac
507                      done
508                      case "$non_shared" in
509                       1) $debug keep non-shared $path;;
510                       *) $debug skip shared $path; continue;;
511                      esac;;
512                   esac;;
513                *) continue;;
514             esac
515             # Skip hard links and symbolic links.
516             case $type in
517             [hl]) continue;;
518             [df]) ;;
519                *) echo unknown type $type for $path in $postfix_file 1>&2; exit 1;;
520             esac
521             # Expand $name, and canonicalize null fields.
522             for name in path owner group flags
523             do
524                 eval junk=\${$name}
525                 case $junk in
526                 [$]*) eval $name=$junk;;
527                    -) eval $name=;;
528                    *) ;;
529                 esac
530             done
531             # Skip uninstalled files.
532             case $path in
533             no|no/*) continue;;
534             esac
535             # Pick up the flags.
536             case $flags in *u*) upgrade_flag=1;; *) upgrade_flag=;; esac
537             case $flags in *c*) create_flag=1;; *) create_flag=;; esac
538             case $flags in *r*) recursive="-R";; *) recursive=;; esac
539             case $flags in *o*) obsolete_flag=1;; *) obsolete_flag=;; esac
540             case $flags in *[1i]*) test ! -r "$path" -a "$config_directory" != \
541                                     "$def_config_directory" && continue;; esac
542             # Flag obsolete objects. XXX Solaris 2..9 does not have "test -e".
543             if [ -n "$obsolete_flag" ]
544             then
545                 test -r $path -a "$type" != "d" && obsolete="$obsolete $path"
546                 continue;
547             else
548                 keep_list="$keep_list $path"
549             fi
550             # Create missing directories with proper owner/group/mode settings.
551             if [ -n "$create" -a "$type" = "d" -a -n "$create_flag" -a ! -d "$path" ]
552             then
553                 mkdir $path || exit 1
554                 set_permission=1
555             # Update all owner/group/mode settings.
556             elif [ -n "$set_perms" ]
557             then
558                 set_permission=1
559             # Update obsolete owner/group/mode settings.
560             elif [ -n "$upgrade_perms" -a -n "$upgrade_flag" ]
561             then
562                 set_permission=1
563             fi
564             test -n "$set_permission" && {
565                 chown $recursive $owner $path || exit 1
566                 test -z "$group" || chgrp $recursive $group $path || exit 1
567                 # Don't "chmod -R"; queue file status is encoded in mode bits.
568                 if [ "$type" = "d" -a -n "$recursive" ]
569                 then
570                     find $path -type d -exec chmod $mode "{}" ";"
571                 else
572                     chmod $mode $path
573                 fi || exit 1
574             }
575         done
576         IFS="$BACKUP_IFS"
577     done
578 }
579
580 # Upgrade existing Postfix configuration files if necessary.
581
582 test -n "$upgrade_conf" && {
583
584     # Postfix 2.0.
585     # Add missing relay service to master.cf.
586
587     grep '^relay' $config_directory/master.cf >/dev/null || {
588         echo Editing $config_directory/master.cf, adding missing entry for relay service
589         cat >>$config_directory/master.cf <<EOF || exit 1
590 relay     unix  -       -       n       -       -       smtp
591 EOF
592     }
593
594     # Postfix 1.1.
595     # Add missing flush service to master.cf.
596
597     grep '^flush.*flush' $config_directory/master.cf >/dev/null || {
598         echo Editing $config_directory/master.cf, adding missing entry for flush service
599         cat >>$config_directory/master.cf <<EOF || exit 1
600 flush     unix  -       -       n       1000?   0       flush
601 EOF
602     }
603
604     # Postfix 2.1.
605     # Add missing trace service to master.cf.
606
607     grep 'trace.*bounce' $config_directory/master.cf >/dev/null || {
608         echo Editing $config_directory/master.cf, adding missing entry for trace service
609         cat >>$config_directory/master.cf <<EOF || exit 1
610 trace     unix  -       -       n       -       0       bounce
611 EOF
612     }
613
614     # Postfix 2.1.
615     # Add missing verify service to master.cf.
616
617     grep '^verify.*verify' $config_directory/master.cf >/dev/null || {
618         echo Editing $config_directory/master.cf, adding missing entry for verify service
619         cat >>$config_directory/master.cf <<EOF || exit 1
620 verify    unix  -       -       n       -       1       verify
621 EOF
622     }
623
624     # Postfix 2.1.
625     # Fix verify service process limit.
626
627     grep '^verify.*[    ]0[     ]*verify' \
628         $config_directory/master.cf >/dev/null && {
629             echo Editing $config_directory/master.cf, setting verify process limit to 1
630             ed $config_directory/master.cf <<EOF || exit 1
631 /^verify.*[     ]0[     ]*verify/
632 s/\([   ]\)0\([         ]\)/\11\2/
633 p
634 w
635 q
636 EOF
637     }
638
639     # Postfix 1.1.
640     # Change privileged pickup service into unprivileged.
641
642     grep "^pickup[      ]*fifo[         ]*n[    ]*n" \
643         $config_directory/master.cf >/dev/null && {
644             echo Editing $config_directory/master.cf, making the pickup service unprivileged
645             ed $config_directory/master.cf <<EOF || exit 1
646 /^pickup[       ]*fifo[         ]*n[    ]*n/
647 s/\(n[  ]*\)n/\1-/
648 p
649 w
650 q
651 EOF
652     }
653
654     # Postfix 1.1.
655     # Change private cleanup and flush services into public.
656
657     for name in cleanup flush
658     do
659         grep "^$name[   ]*unix[         ]*[-y]" \
660             $config_directory/master.cf >/dev/null && {
661                 echo Editing $config_directory/master.cf, making the $name service public
662             ed $config_directory/master.cf <<EOF || exit 1
663 /^$name[        ]*unix[         ]*[-y]/
664 s/[-y]/n/
665 p
666 w
667 q
668 EOF
669         }
670     done
671
672     # Postfix 2.2.
673     # File systems have improved since Postfix came out, and all we
674     # require now is that defer and deferred are hashed because those
675     # can contain lots of files.
676
677     found=`$POSTCONF -c $config_directory -h hash_queue_names`
678     missing=
679     (echo "$found" | grep defer >/dev/null)  || missing="$missing defer"
680     (echo "$found" | grep deferred>/dev/null)|| missing="$missing deferred"
681     test -n "$missing" && {
682         echo fixing main.cf hash_queue_names for missing $missing
683         $POSTCONF -c $config_directory -e hash_queue_names="$found$missing" ||
684             exit 1
685     }
686
687     # Turn on safety nets for new features that could bounce mail that
688     # would be accepted by a previous Postfix version.
689
690     # [The "unknown_local_recipient_reject_code = 450" safety net,
691     # introduced with Postfix 2.0 and deleted after Postfix 2.3.]
692
693     # Postfix 2.0.
694     # Add missing proxymap service to master.cf.
695
696     grep '^proxymap.*proxymap' $config_directory/master.cf >/dev/null || {
697         echo Editing $config_directory/master.cf, adding missing entry for proxymap service
698         cat >>$config_directory/master.cf <<EOF || exit 1
699 proxymap  unix  -       -       n       -       -       proxymap
700 EOF
701     }
702
703     # Postfix 2.1.
704     # Add missing anvil service to master.cf.
705
706     grep '^anvil.*anvil' $config_directory/master.cf >/dev/null || {
707         echo Editing $config_directory/master.cf, adding missing entry for anvil service
708         cat >>$config_directory/master.cf <<EOF || exit 1
709 anvil     unix  -       -       n       -       1       anvil
710 EOF
711     }
712
713     # Postfix 2.2.
714     # Add missing scache service to master.cf.
715
716     grep '^scache.*scache' $config_directory/master.cf >/dev/null || {
717         echo Editing $config_directory/master.cf, adding missing entry for scache service
718         cat >>$config_directory/master.cf <<EOF || exit 1
719 scache    unix  -       -       n       -       1       scache
720 EOF
721     }
722
723     # Postfix 2.2.
724     # Add missing discard service to master.cf.
725
726     grep '^discard.*discard' $config_directory/master.cf >/dev/null || {
727         echo Editing $config_directory/master.cf, adding missing entry for discard service
728         cat >>$config_directory/master.cf <<EOF || exit 1
729 discard   unix  -       -       n       -       -       discard
730 EOF
731     }
732
733     # Postfix 2.2.
734     # Update the tlsmgr fifo->unix service.
735
736     grep "^tlsmgr[      ]*fifo[         ]" \
737         $config_directory/master.cf >/dev/null && {
738             echo Editing $config_directory/master.cf, updating the tlsmgr from fifo to unix service
739             ed $config_directory/master.cf <<EOF || exit 1
740 /^tlsmgr[       ]*fifo[         ]/
741 s/fifo/unix/
742 s/[0-9][0-9]*/&?/
743 p
744 w
745 q
746 EOF
747     }
748
749     # Postfix 2.2.
750     # Add missing tlsmgr service to master.cf.
751
752     grep '^tlsmgr.*tlsmgr' $config_directory/master.cf >/dev/null || {
753         echo Editing $config_directory/master.cf, adding missing entry for tlsmgr service
754         cat >>$config_directory/master.cf <<EOF || exit 1
755 tlsmgr    unix  -       -       n       1000?   1       tlsmgr
756 EOF
757     }
758
759     # Postfix 2.2.
760     # Add missing retry service to master.cf.
761
762     grep '^retry.*error' $config_directory/master.cf >/dev/null || {
763         echo Editing $config_directory/master.cf, adding missing entry for retry service
764         cat >>$config_directory/master.cf <<EOF || exit 1
765 retry     unix  -       -       n       -       -       error
766 EOF
767     }
768
769     # Postfix 2.5.
770     # Add missing proxywrite service to master.cf.
771
772     grep '^proxywrite.*proxymap' $config_directory/master.cf >/dev/null || {
773         echo Editing $config_directory/master.cf, adding missing entry for proxywrite service
774         cat >>$config_directory/master.cf <<EOF || exit 1
775 proxywrite unix -       -       n       -       1       proxymap
776 EOF
777     }
778
779     # Postfix 2.5.
780     # Fix a typo in the default master.cf proxywrite entry.
781
782     grep '^proxywrite.*-[       ]*proxymap' $config_directory/master.cf >/dev/null && {
783         echo Editing $config_directory/master.cf, setting proxywrite process limit to 1
784             ed $config_directory/master.cf <<EOF || exit 1
785 /^proxywrite.*-[        ]*proxymap/
786 s/-\([  ]*proxymap\)/1\1/
787 p
788 w
789 q
790 EOF
791     }
792
793     # Postfix 2.8.
794     # Add missing postscreen service to master.cf.
795
796     grep '^#*smtp.*postscreen' $config_directory/master.cf >/dev/null || {
797         echo Editing $config_directory/master.cf, adding missing entry for postscreen TCP service
798         cat >>$config_directory/master.cf <<EOF || exit 1
799 #smtp      inet  n       -       n       -       1       postscreen
800 EOF
801     }
802
803     # Postfix 2.8.
804     # Add missing smtpd (unix-domain) service to master.cf.
805
806     grep '^#*smtpd.*smtpd' $config_directory/master.cf >/dev/null || {
807         echo Editing $config_directory/master.cf, adding missing entry for smtpd unix-domain service
808         cat >>$config_directory/master.cf <<EOF || exit 1
809 #smtpd     pass  -       -       n       -       -       smtpd
810 EOF
811     }
812
813     # Postfix 2.8.
814     # Add temporary dnsblog (unix-domain) service to master.cf.
815
816     grep '^#*dnsblog.*dnsblog' $config_directory/master.cf >/dev/null || {
817         echo Editing $config_directory/master.cf, adding missing entry for dnsblog unix-domain service
818         cat >>$config_directory/master.cf <<EOF || exit 1
819 #dnsblog   unix  -       -       n       -       0       dnsblog
820 EOF
821     }
822
823     # Postfix 2.8.
824     # Add tlsproxy (unix-domain) service to master.cf.
825
826     grep '^#*tlsproxy.*tlsproxy' $config_directory/master.cf >/dev/null || {
827         echo Editing $config_directory/master.cf, adding missing entry for tlsproxy unix-domain service
828         cat >>$config_directory/master.cf <<EOF || exit 1
829 #tlsproxy  unix  -       -       n       -       0       tlsproxy
830 EOF
831     }
832
833     # Report (but do not remove) obsolete files.
834
835     test -n "$obsolete" && {
836         cat <<EOF | ${FMT}
837
838     Note: the following files or directories still exist but are
839     no longer part of Postfix:
840
841     $obsolete
842
843 EOF
844     }
845
846     # Postfix 2.9.
847     # Safety net for incompatible changes in IPv6 defaults.
848     # PLEASE DO NOT REMOVE THIS CODE. ITS PURPOSE IS TO AVOID AN
849     # UNEXPECTED DROP IN PERFORMANCE AFTER UPGRADING FROM POSTFIX
850     # BEFORE 2.9.
851     # This code assumes that the default is "inet_protocols = ipv4"
852     # when IPv6 support is not compiled in. See util/sys_defs.h.
853
854     test "`$POSTCONF -dh inet_protocols`" = "ipv4" ||
855         test -n "`$POSTCONF -c $config_directory -n inet_protocols`" || {
856         cat <<EOF | ${FMT}
857     COMPATIBILITY: editing $config_directory/main.cf, setting
858     inet_protocols=ipv4.  Specify inet_protocols explicitly if you
859     want to enable IPv6.
860     In a future release IPv6 will be enabled by default.
861 EOF
862         $POSTCONF -c $config_directory inet_protocols=ipv4 || exit 1
863     }
864
865 # Disabled because unhelpful down-stream maintainers disable the safety net.
866 #    # Postfix 2.10.
867 #    # Safety net for incompatible changes due to the introduction
868 #    # of the smtpd_relay_restrictions feature to separate the
869 #    # mail relay policy from the spam blocking policy.
870 #    # PLEASE DO NOT REMOVE THIS CODE. ITS PURPOSE IS TO PREVENT
871 #    # INBOUND MAIL FROM UNEXPECTEDLY BOUNCING AFTER UPGRADING FROM
872 #    # POSTFIX BEFORE 2.10.
873 #    test -n "`$POSTCONF -c $config_directory -n smtpd_relay_restrictions`" || {
874 #       cat <<EOF | ${FMT}
875 #    COMPATIBILITY: editing $config_directory/main.cf, overriding
876 #    smtpd_relay_restrictions to prevent inbound mail from
877 #    unexpectedly bouncing.
878 #    Specify an empty smtpd_relay_restrictions value to keep using 
879 #    smtpd_recipient_restrictions as before.
880 #EOF
881 #       $POSTCONF -c $config_directory "smtpd_relay_restrictions = \
882 #           permit_mynetworks permit_sasl_authenticated \
883 #           defer_unauth_destination" || exit 1
884 #    }
885 }
886
887 # A reminder if this is the first time Postfix is being installed.
888
889 test -n "$first_install_reminder" && {
890
891     ALIASES=`$POSTCONF -c $config_directory -h alias_database | sed 's/^[^:]*://'`
892     NEWALIASES_PATH=`$POSTCONF -c $config_directory -h newaliases_path`
893     cat <<EOF | ${FMT}
894
895     Warning: you still need to edit myorigin/mydestination/mynetworks
896     parameter settings in $config_directory/main.cf.
897
898     See also http://www.postfix.org/STANDARD_CONFIGURATION_README.html
899     for information about dialup sites or about sites inside a
900     firewalled network.
901
902     BTW: Check your $ALIASES file and be sure to set up aliases
903     that send mail for root and postmaster to a real person, then
904     run $NEWALIASES_PATH.
905
906 EOF
907
908 }
909
910 exit 0