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