5 # To view the formatted manual page of this file, type:
6 # POSTFIXSOURCE/mantools/srctoman - post-install | nroff -man
12 # Postfix post-installation script
14 # postfix post-install [name=value] command ...
16 # The post-install script performs the finishing touch of a Postfix
17 # installation, after the executable programs and configuration
18 # files are installed. Usage is one of the following:
20 # While installing Postfix from source code on the local machine, the
21 # script is run by the postfix-install script to update selected file
22 # or directory permissions and to update Postfix configuration files.
24 # While installing Postfix from a pre-built package, the script is run
25 # by the package management procedure to set all file or directory
26 # permissions and to update Postfix configuration files.
28 # The script can be used to change installation parameter settings such
29 # as mail_owner or setgid_group after Postfix is already installed.
31 # The script can be used to upgrade configuration files and to upgrade
32 # file/directory permissions of a secondary Postfix instance.
34 # At Postfix start-up time, the script is run from "postfix check" to
35 # create missing queue directories.
37 # The post-install script is controlled by installation parameters.
38 # Specific parameters are described at the end of this document.
39 # All installation parameters must be specified ahead of time via
40 # one of the methods described below.
44 # Create missing queue directories with ownerships and permissions
45 # according to the contents of $daemon_directory/postfix-files, using
46 # the mail_owner and setgid_group parameter settings from the command
47 # line, process environment or from the installed main.cf file.
49 # This is required at Postfix start-up time.
51 # Set all file/directory ownerships and permissions according to the
52 # contents of $daemon_directory/postfix-files, using the mail_owner
53 # and setgid_group parameter settings from the command line, process
54 # environment or from the installed main.cf file. Implies create-missing.
56 # This is required when installing Postfix from a pre-built package,
57 # or when changing the mail_owner or setgid_group installation parameter
58 # settings after Postfix is already installed.
59 # .IP upgrade-permissions
60 # Update ownership and permission of existing files/directories as
61 # specified in $daemon_directory/postfix-files, using the mail_owner
62 # and setgid_group parameter settings from the command line, process
63 # environment or from the installed main.cf file. Implies create-missing.
65 # This is required when upgrading an existing Postfix instance.
66 # .IP upgrade-configuration
67 # Edit the installed main.cf and master.cf files, in order to account
68 # for missing services and to fix deprecated parameter settings.
70 # This is required when upgrading an existing Postfix instance.
72 # Short-hand for: upgrade-permissions upgrade-configuration.
74 # This is recommended when upgrading Postfix from source code.
76 # Short-hand for: set-permissions upgrade-configuration.
78 # This is recommended when upgrading Postfix from a pre-built package.
79 # .IP first-install-reminder
80 # Remind the user that they still need to configure main.cf and the
81 # aliases file, and that newaliases still needs to be run.
83 # This is recommended when Postfix is installed for the first time.
84 # MULTIPLE POSTFIX INSTANCES
87 # Multiple Postfix instances on the same machine can share command and
88 # daemon program files but must have separate configuration and queue
91 # To create a secondary Postfix installation on the same machine,
92 # copy the configuration files from the primary Postfix instance to
93 # a secondary configuration directory and execute:
95 # postfix post-install config_directory=secondary-config-directory \e
97 # queue_directory=secondary-queue-directory \e
101 # This creates secondary Postfix queue directories, sets their access
102 # permissions, and saves the specified installation parameters to the
103 # secondary main.cf file.
105 # Be sure to list the secondary configuration directory in the
106 # alternate_config_directories parameter in the primary main.cf file.
108 # To upgrade a secondary Postfix installation on the same machine,
111 # postfix post-install config_directory=secondary-config-directory \e
113 # upgrade-permissions upgrade-configuration
114 # INSTALLATION PARAMETER INPUT METHODS
117 # Parameter settings can be specified through a variety of
118 # mechanisms. In order of decreasing precedence these are:
120 # Parameter settings can be given as name=value arguments on
121 # the post-install command line. These have the highest precedence.
122 # Settings that override the installed main.cf file are saved.
123 # .IP "process environment"
124 # Parameter settings can be given as name=value environment
126 # Settings that override the installed main.cf file are saved.
127 # .IP "installed configuration files"
128 # If a parameter is not specified via the command line or via the
129 # process environment, post-install will attempt to extract its
130 # value from the already installed Postfix main.cf configuration file.
131 # These settings have the lowest precedence.
132 # INSTALLATION PARAMETER DESCRIPTION
135 # The description of installation parameters is as follows:
136 # .IP config_directory
137 # The directory for Postfix configuration files.
138 # .IP daemon_directory
139 # The directory for Postfix daemon programs. This directory
140 # should not be in the command search path of any users.
141 # .IP command_directory
142 # The directory for Postfix administrative commands. This
143 # directory should be in the command search path of adminstrative users.
144 # .IP queue_directory
145 # The directory for Postfix queues.
147 # The directory for Postfix writable data files (caches, etc.).
149 # The full pathname for the Postfix sendmail command.
150 # This is the Sendmail-compatible mail posting interface.
151 # .IP newaliases_path
152 # The full pathname for the Postfix newaliases command.
153 # This is the Sendmail-compatible command to build alias databases
154 # for the Postfix local delivery agent.
156 # The full pathname for the Postfix mailq command.
157 # This is the Sendmail-compatible command to list the mail queue.
159 # The owner of the Postfix queue. Its numerical user ID and group ID
160 # must not be used by any other accounts on the system.
162 # The group for mail submission and for queue management commands.
163 # Its numerical group ID must not be used by any other accounts on the
164 # system, not even by the mail_owner account.
166 # The directory for the Postfix HTML files.
167 # .IP manpage_directory
168 # The directory for the Postfix on-line manual pages.
169 # .IP sample_directory
170 # The directory for the Postfix sample configuration files.
171 # This feature is obsolete as of Postfix 2.1.
172 # .IP readme_directory
173 # The directory for the Postfix README files.
175 # postfix-install(1) Postfix primary installation script.
177 # $config_directory/main.cf, Postfix installation parameters.
178 # $daemon_directory/postfix-files, installation control file.
179 # $config_directory/install.cf, obsolete configuration file.
183 # The Secure Mailer license must be distributed with this software.
186 # IBM T.J. Watson Research
188 # Yorktown Heights, NY 10598, USA
193 PATH
=/bin
:/usr
/bin
:/usr
/sbin
:/usr
/etc
:/sbin
:/etc
:/usr
/contrib
/bin
:/usr
/gnu
/bin
:/usr
/ucb
:/usr
/bsd
200 MOST_PARAMETERS
="command_directory daemon_directory data_directory
201 html_directory mail_owner mailq_path manpage_directory
202 newaliases_path queue_directory readme_directory sample_directory
203 sendmail_path setgid_group"
204 NON_SHARED
="config_directory queue_directory data_directory"
206 USAGE
="Usage: $0 [name=value] command
207 create-missing Create missing queue directories.
208 upgrade-source When installing or upgrading from source code.
209 upgrade-package When installing or upgrading from pre-built package.
210 first-install-reminder Remind of mandatory first-time configuration steps.
211 name=value Specify an installation parameter".
213 # Process command-line options and parameter settings. Work around
214 # brain damaged shells. "IFS=value command" should not make the
215 # IFS=value setting permanent. But some broken standard allows it.
217 create
=; set_perms
=; upgrade_perms
=; upgrade_conf
=; first_install_reminder
=
218 obsolete
=; keep_list
=;
223 *=*) IFS
= eval $arg; IFS
="$BACKUP_IFS";;
224 create-missing
) create
=1;;
225 set-perm
*) create
=1; set_perms
=1;;
226 upgrade-perm
*) create
=1; upgrade_perms
=1;;
227 upgrade-conf
*) upgrade_conf
=1;;
228 upgrade-source
) create
=1; upgrade_conf
=1; upgrade_perms
=1;;
229 upgrade-package
) create
=1; upgrade_conf
=1; set_perms
=1;;
230 first-install
*) first_install_reminder
=1;;
231 *) echo "$0: Error: $USAGE" 1>&2; exit 1;;
238 test -n "$create$upgrade_conf$first_install_reminder" ||
{
239 echo "$0: Error: $USAGE" 1>&2
243 # Bootstrapping problem.
245 if [ -n "$command_directory" ]
247 POSTCONF
="$command_directory/postconf"
252 $POSTCONF -d mail_version
>/dev
/null
2>/dev
/null ||
{
253 echo $0: Error
: no
$POSTCONF command found.
1>&2
254 echo Re-run this
command as
$0 command_directory
=/some
/where.
1>&2
258 # Also used to require license etc. files only in the default instance.
260 def_config_directory
=`$POSTCONF -d -h config_directory` ||
exit 1
261 test -n "$config_directory" ||
262 config_directory
="$def_config_directory"
264 test -d "$config_directory" ||
{
265 echo $0: Error
: $config_directory is not a directory.
1>&2
269 # If this is a secondary instance, don't touch shared files.
270 # XXX Solaris does not have "test -e".
272 instances
=`test ! -f $def_config_directory/main.cf ||
273 $POSTCONF -c $def_config_directory -h multi_instance_directories |
274 sed 's/,/ /'` ||
exit 1
276 update_shared_files
=1
277 for name
in $instances
280 "$def_config_directory") ;;
281 "$config_directory") update_shared_files
=; break;;
285 test -f $daemon_directory/postfix-files ||
{
286 echo $0: Error
: $daemon_directory/postfix-files is not a
file.
1>&2
290 # SunOS5 fmt(1) truncates lines > 1000 characters.
295 /^\( *\)\([^ ][^ ]*\) */{
307 SunOS
*) FMT
=fake_fmt
;;
311 # If a parameter is not set via the command line or environment,
312 # try to use settings from installed configuration files.
314 # Extract parameter settings from the obsolete install.cf file, as
315 # a transitional aid.
317 grep setgid_group
$config_directory/main.cf
>/dev
/null
2>&1 ||
{
318 test -f $config_directory/install.cf
&& {
319 for name
in sendmail_path newaliases_path mailq_path setgid manpages
323 "") eval unset $name;;
325 eval : \
${$name="\`. $config_directory/install.cf; echo \$$name\`"} \
328 : ${setgid_group=$setgid}
329 : ${manpage_directory=$manpages}
333 # Extract parameter settings from the installed main.cf file.
335 test -f $config_directory/main.cf
&& {
336 for name
in $MOST_PARAMETERS
340 "") eval unset $name;;
342 eval : \
${$name=\`$POSTCONF -c $config_directory -h $name\`} ||
exit 1
348 case $manpage_directory in
349 no
) echo $0: Error
: manpage_directory no longer accepts
\"no
\" values.
1>&2
350 echo Try again with
\"$0 manpage_directory
=/pathname ...
\".
1>&2; exit 1;;
353 case $setgid_group in
354 no
) echo $0: Error
: setgid_group no longer accepts
\"no
\" values.
1>&2
355 echo Try again with
\"$0 setgid_group
=groupname ...
\" 1>&2; exit 1;;
358 for path
in "$daemon_directory" "$command_directory" "$queue_directory" \
359 "$sendmail_path" "$newaliases_path" "$mailq_path" "$manpage_directory"
363 *) echo $0: Error
: \"$path\" should be an absolute path name.
1>&2; exit 1;;
367 for path
in "$html_directory" "$readme_directory"
372 *) echo $0: Error
: \"$path\" should be
\"no
\" or an absolute path name.
1>&2; exit 1;;
376 # Find out what parameters were not specified via command line,
377 # via environment, or via installed configuration files.
380 for name
in $MOST_PARAMETERS
382 eval test -n \"\$
$name\" || missing
="$missing $name"
385 # All parameters must be specified at this point.
387 test -n "$non_interactive" -a -n "$missing" && {
388 cat <<EOF | ${FMT} 1>&2
389 $0: Error: some required installation parameters are not defined.
391 - Either the parameters need to be given in the $config_directory/main.cf
392 file from a recent Postfix installation,
394 - Or the parameters need to be specified through the process
397 - Or the parameters need to be specified as name=value arguments
398 on the $0 command line,
400 The following parameters were missing:
408 POSTCONF
="$command_directory/postconf"
410 # Save settings, allowing command line/environment override.
413 for name
in $MOST_PARAMETERS
415 eval test \"\$
$name\" = \"`$POSTCONF -c $config_directory -h $name`\" ||
{
421 test -n "$override" && {
422 $POSTCONF -c $config_directory -e \
423 "daemon_directory = $daemon_directory" \
424 "command_directory = $command_directory" \
425 "queue_directory = $queue_directory" \
426 "data_directory = $data_directory" \
427 "mail_owner = $mail_owner" \
428 "setgid_group = $setgid_group" \
429 "sendmail_path = $sendmail_path" \
430 "mailq_path = $mailq_path" \
431 "newaliases_path = $newaliases_path" \
432 "html_directory = $html_directory" \
433 "manpage_directory = $manpage_directory" \
434 "sample_directory = $sample_directory" \
435 "readme_directory = $readme_directory" \
439 # Use file/directory status information in $daemon_directory/postfix-files.
441 test -n "$create" && {
442 exec <$daemon_directory/postfix-files ||
exit 1
443 while IFS
=: read path
type owner group mode flags junk
447 # Skip comments. Skip shared files, if updating a secondary instance.
449 [$
]*) case "$update_shared_files" in
450 1) $debug keep non-shared or shared
$path;;
452 for name
in $NON_SHARED
455 "\$$name"*) non_shared
=1; break;;
458 case "$non_shared" in
459 1) $debug keep non-shared
$path;;
460 *) $debug skip shared
$path; continue;;
465 # Skip hard links and symbolic links.
469 *) echo unknown
type $type for $path in $daemon_directory/postfix-files1
>&2; exit 1;;
471 # Expand $name, and canonicalize null fields.
472 for name
in path owner group flags
476 [$
]*) eval $name=$junk;;
481 # Skip uninstalled files.
486 case $flags in *u
*) upgrade_flag
=1;; *) upgrade_flag
=;; esac
487 case $flags in *c
*) create_flag
=1;; *) create_flag
=;; esac
488 case $flags in *r
*) recursive
="-R";; *) recursive
=;; esac
489 case $flags in *o
*) obsolete_flag
=1;; *) obsolete_flag
=;; esac
490 case $flags in *[1i
]*) test ! -r "$path" -a "$config_directory" != \
491 "$def_config_directory" && continue;; esac
492 # Flag obsolete objects. XXX Solaris 2..9 does not have "test -e".
493 if [ -n "$obsolete_flag" ]
495 test -r $path -a "$type" != "d" && obsolete
="$obsolete $path"
498 keep_list
="$keep_list $path"
500 # Create missing directories with proper owner/group/mode settings.
501 if [ -n "$create" -a "$type" = "d" -a -n "$create_flag" -a ! -d "$path" ]
503 mkdir
$path ||
exit 1
505 # Update all owner/group/mode settings.
506 elif [ -n "$set_perms" ]
509 # Update obsolete owner/group/mode settings.
510 elif [ -n "$upgrade_perms" -a -n "$upgrade_flag" ]
514 test -n "$set_permission" && {
515 chown
$recursive $owner $path ||
exit 1
516 test -z "$group" || chgrp
$recursive $group $path ||
exit 1
517 # Don't "chmod -R"; queue file status is encoded in mode bits.
518 if [ "$type" = "d" -a -n "$recursive" ]
520 find $path -type d
-exec chmod $mode "{}" ";"
529 # Upgrade existing Postfix configuration files if necessary.
531 test -n "$upgrade_conf" && {
534 # Add missing relay service to master.cf.
536 grep '^relay' $config_directory/master.cf
>/dev
/null ||
{
537 echo Editing
$config_directory/master.cf
, adding missing entry
for relay service
538 cat >>$config_directory/master.cf
<<EOF || exit 1
539 relay unix - - n - - smtp
544 # Add missing flush service to master.cf.
546 grep '^flush.*flush' $config_directory/master.cf
>/dev
/null ||
{
547 echo Editing
$config_directory/master.cf
, adding missing entry
for flush service
548 cat >>$config_directory/master.cf
<<EOF || exit 1
549 flush unix - - n 1000? 0 flush
554 # Add missing trace service to master.cf.
556 grep 'trace.*bounce' $config_directory/master.cf
>/dev
/null ||
{
557 echo Editing
$config_directory/master.cf
, adding missing entry
for trace service
558 cat >>$config_directory/master.cf
<<EOF || exit 1
559 trace unix - - n - 0 bounce
564 # Add missing verify service to master.cf.
566 grep '^verify.*verify' $config_directory/master.cf
>/dev
/null ||
{
567 echo Editing
$config_directory/master.cf
, adding missing entry
for verify service
568 cat >>$config_directory/master.cf
<<EOF || exit 1
569 verify unix - - n - 1 verify
574 # Fix verify service process limit.
576 grep '^verify.*[ ]0[ ]*verify' \
577 $config_directory/master.cf
>/dev
/null
&& {
578 echo Editing
$config_directory/master.cf
, setting verify process limit to
1
579 ed
$config_directory/master.cf
<<EOF || exit 1
580 /^verify.*[ ]0[ ]*verify/
581 s/\([ ]\)0\([ ]\)/\11\2/
589 # Change privileged pickup service into unprivileged.
591 grep "^pickup[ ]*fifo[ ]*n[ ]*n" \
592 $config_directory/master.cf
>/dev
/null
&& {
593 echo Editing
$config_directory/master.cf
, making the pickup service unprivileged
594 ed
$config_directory/master.cf
<<EOF || exit 1
595 /^pickup[ ]*fifo[ ]*n[ ]*n/
604 # Change private cleanup and flush services into public.
606 for name
in cleanup flush
608 grep "^$name[ ]*unix[ ]*[-y]" \
609 $config_directory/master.cf
>/dev
/null
&& {
610 echo Editing
$config_directory/master.cf
, making the
$name service public
611 ed
$config_directory/master.cf
<<EOF || exit 1
612 /^$name[ ]*unix[ ]*[-y]/
622 # File systems have improved since Postfix came out, and all we
623 # require now is that defer and deferred are hashed because those
624 # can contain lots of files.
626 found
=`$POSTCONF -c $config_directory -h hash_queue_names`
628 (echo "$found" |
grep defer
>/dev
/null
) || missing
="$missing defer"
629 (echo "$found" |
grep deferred
>/dev
/null
)|| missing
="$missing deferred"
630 test -n "$missing" && {
631 echo fixing main.cf hash_queue_names
for missing
$missing
632 $POSTCONF -c $config_directory -e hash_queue_names
="$found$missing" ||
636 # Turn on safety nets for new features that could bounce mail that
637 # would be accepted by a previous Postfix version.
639 # [The "unknown_local_recipient_reject_code = 450" safety net,
640 # introduced with Postfix 2.0 and deleted after Postfix 2.3.]
643 # Add missing proxymap service to master.cf.
645 grep '^proxymap.*proxymap' $config_directory/master.cf
>/dev
/null ||
{
646 echo Editing
$config_directory/master.cf
, adding missing entry
for proxymap service
647 cat >>$config_directory/master.cf
<<EOF || exit 1
648 proxymap unix - - n - - proxymap
653 # Add missing anvil service to master.cf.
655 grep '^anvil.*anvil' $config_directory/master.cf
>/dev
/null ||
{
656 echo Editing
$config_directory/master.cf
, adding missing entry
for anvil service
657 cat >>$config_directory/master.cf
<<EOF || exit 1
658 anvil unix - - n - 1 anvil
663 # Add missing scache service to master.cf.
665 grep '^scache.*scache' $config_directory/master.cf
>/dev
/null ||
{
666 echo Editing
$config_directory/master.cf
, adding missing entry
for scache service
667 cat >>$config_directory/master.cf
<<EOF || exit 1
668 scache unix - - n - 1 scache
673 # Add missing discard service to master.cf.
675 grep '^discard.*discard' $config_directory/master.cf
>/dev
/null ||
{
676 echo Editing
$config_directory/master.cf
, adding missing entry
for discard service
677 cat >>$config_directory/master.cf
<<EOF || exit 1
678 discard unix - - n - - discard
683 # Update the tlsmgr fifo->unix service.
685 grep "^tlsmgr[ ]*fifo[ ]" \
686 $config_directory/master.cf
>/dev
/null
&& {
687 echo Editing
$config_directory/master.cf
, updating the tlsmgr from fifo to unix service
688 ed
$config_directory/master.cf
<<EOF || exit 1
699 # Add missing tlsmgr service to master.cf.
701 grep '^tlsmgr.*tlsmgr' $config_directory/master.cf
>/dev
/null ||
{
702 echo Editing
$config_directory/master.cf
, adding missing entry
for tlsmgr service
703 cat >>$config_directory/master.cf
<<EOF || exit 1
704 tlsmgr unix - - n 1000? 1 tlsmgr
709 # Add missing retry service to master.cf.
711 grep '^retry.*error' $config_directory/master.cf
>/dev
/null ||
{
712 echo Editing
$config_directory/master.cf
, adding missing entry
for retry service
713 cat >>$config_directory/master.cf
<<EOF || exit 1
714 retry unix - - n - - error
719 # Add missing proxywrite service to master.cf.
721 grep '^proxywrite.*proxymap' $config_directory/master.cf
>/dev
/null ||
{
722 echo Editing
$config_directory/master.cf
, adding missing entry
for proxywrite service
723 cat >>$config_directory/master.cf
<<EOF || exit 1
724 proxywrite unix - - n - 1 proxymap
729 # Fix a typo in the default master.cf proxywrite entry.
731 grep '^proxywrite.*-[ ]*proxymap' $config_directory/master.cf
>/dev
/null
&& {
732 echo Editing
$config_directory/master.cf
, setting proxywrite process limit to
1
733 ed
$config_directory/master.cf
<<EOF || exit 1
734 /^proxywrite.*-[ ]*proxymap/
735 s/-\([ ]*proxymap\)/1\1/
742 # Report (but do not remove) obsolete files.
744 test -n "$obsolete" && {
747 Note: the following files or directories still exist but are
748 no longer part of Postfix:
757 # A reminder if this is the first time Postfix is being installed.
759 test -n "$first_install_reminder" && {
761 ALIASES
=`$POSTCONF -c $config_directory -h alias_database | sed 's/^[^:]*://'`
762 NEWALIASES_PATH
=`$POSTCONF -c $config_directory -h newaliases_path`
765 Warning: you still need to edit myorigin/mydestination/mynetworks
766 parameter settings in $config_directory/main.cf.
768 See also http://www.postfix.org/STANDARD_CONFIGURATION_README.html
769 for information about dialup sites or about sites inside a
772 BTW: Check your $ALIASES file and be sure to set up aliases
773 that send mail for root and postmaster to a real person, then
774 run $NEWALIASES_PATH.