postfix-install revision 1.3 1 1.1 tron #!/bin/sh
2 1.1 tron
3 1.1 tron # To view the formatted manual page of this file, type:
4 1.1 tron # POSTFIXSOURCE/mantools/srctoman - postfix-install | nroff -man
5 1.1 tron
6 1.1 tron #++
7 1.1 tron # NAME
8 1.1 tron # postfix-install 1
9 1.1 tron # SUMMARY
10 1.1 tron # Postfix installation procedure
11 1.1 tron # SYNOPSIS
12 1.1 tron # sh postfix-install [options] [name=value] ...
13 1.1 tron # DESCRIPTION
14 1.1 tron # The postfix-install script is to be run from the top-level
15 1.1 tron # Postfix source directory. It implements the following operations:
16 1.1 tron # .IP o
17 1.1 tron # Install or upgrade Postfix from source code. This requires
18 1.1 tron # super-user privileges.
19 1.1 tron # .IP o
20 1.1 tron # Build a package that can be distributed to other systems, in order
21 1.1 tron # to install or upgrade Postfix elsewhere. This requires no super-user
22 1.1 tron # privileges. To complete the installation after unpacking the
23 1.1 tron # package, execute as super-user the post-install script in the Postfix
24 1.1 tron # configuration directory.
25 1.1 tron # .PP
26 1.1 tron # The postfix-install script is controlled by installation parameters.
27 1.1 tron # Specific parameters are described at the end of this document.
28 1.1 tron #
29 1.1 tron # By default, postfix-install asks the user for installation
30 1.1 tron # parameter settings. Most settings are stored in the installed
31 1.1 tron # main.cf file. Stored settings are used as site-specific defaults
32 1.1 tron # when the postfix-install script is run later.
33 1.1 tron #
34 1.1 tron # The names of Postfix files and directories, as well as their
35 1.1 tron # ownerships and permissions, are stored in the postfix-files file
36 1.1 tron # in the Postfix configuration directory. This information is used
37 1.1 tron # by the post-install script (also in the configuration directory)
38 1.1 tron # for creating missing queue directories when Postfix is started,
39 1.1 tron # and for setting correct ownership and permissions when Postfix
40 1.1 tron # is installed from a pre-built package or from source code.
41 1.1 tron #
42 1.1 tron # Arguments
43 1.1 tron # .IP -non-interactive
44 1.1 tron # Do not ask the user for parameter settings. Installation parameters
45 1.1 tron # are specified via one of the non-interactive methods described
46 1.1 tron # below.
47 1.1 tron # .IP -package
48 1.1 tron # Build a ready-to-install package. This requires that a
49 1.1 tron # non-default install_root parameter is specified.
50 1.1 tron # INSTALLATION PARAMETER INPUT METHODS
51 1.1 tron # .ad
52 1.1 tron # .fi
53 1.1 tron # Parameter settings can be specified through a variety of
54 1.1 tron # mechanisms. In order of decreasing precedence these are:
55 1.1 tron # .IP "interactive mode"
56 1.1 tron # By default, postfix-install will ask the user for installation
57 1.1 tron # parameter settings. These settings have the highest precedence.
58 1.1 tron # .IP "command line"
59 1.1 tron # Parameter settings can be given as name=value arguments on
60 1.1 tron # the postfix-install command line.
61 1.1 tron # .IP "process environment"
62 1.1 tron # Parameter settings can be given as name=value environment
63 1.1 tron # variables. Environment parameters can also be specified on the
64 1.1 tron # make(1) command line as "make install name=value ...".
65 1.1 tron # .IP "installed configuration files"
66 1.1 tron # If a parameter is not specified via the command line or via the
67 1.1 tron # process environment, postfix-install will attempt to extract its
68 1.1 tron # value from an already installed Postfix main.cf configuration file.
69 1.1 tron # .IP "built-in defaults"
70 1.1 tron # These settings have the lowest precedence.
71 1.1 tron # INSTALLATION PARAMETER DESCRIPTION
72 1.1 tron # .ad
73 1.1 tron # .fi
74 1.1 tron # The description of installation parameters and their built-in
75 1.1 tron # default settings is as follows:
76 1.1 tron # .IP install_root
77 1.1 tron # Prefix that is prepended to the pathnames of installed files.
78 1.1 tron # Specify this ONLY when creating pre-built packages for distribution to
79 1.1 tron # other systems. The built-in default is "/", the local root directory.
80 1.1 tron # This parameter setting is not recorded in the installed main.cf file.
81 1.1 tron # .IP tempdir
82 1.1 tron # Directory for scratch files while installing Postfix.
83 1.1 tron # You must have write permission in this directory.
84 1.1 tron # The built-in default directory name is the current directory.
85 1.1 tron # This parameter setting is not recorded in the installed main.cf file.
86 1.1 tron # .IP config_directory
87 1.1 tron # The final destination directory for Postfix configuration files.
88 1.1 tron # The built-in default directory name is /etc/postfix.
89 1.1 tron # This parameter setting is not recorded in the installed main.cf file
90 1.1 tron # and can be changed only by recompiling Postfix.
91 1.1 tron # .IP data_directory
92 1.1 tron # The final destination directory for Postfix-writable data files such
93 1.1 tron # as caches. This directory should not be shared with non-Postfix
94 1.2 tron # software. The built-in default directory name is /var/db/postfix.
95 1.1 tron # This parameter setting is recorded in the installed main.cf file.
96 1.1 tron # .IP daemon_directory
97 1.1 tron # The final destination directory for Postfix daemon programs. This
98 1.1 tron # directory should not be in the command search path of any users.
99 1.1 tron # The built-in default directory name is /usr/libexec/postfix.
100 1.1 tron # This parameter setting is recorded in the installed main.cf file.
101 1.1 tron # .IP command_directory
102 1.1 tron # The final destination directory for Postfix administrative commands.
103 1.1 tron # This directory should be in the command search path of adminstrative
104 1.1 tron # users. The built-in default directory name is system dependent.
105 1.1 tron # This parameter setting is recorded in the installed main.cf file.
106 1.1 tron # .IP html_directory
107 1.1 tron # The destination directory for the Postfix HTML files.
108 1.1 tron # This parameter setting is recorded in the installed main.cf file.
109 1.1 tron # .IP queue_directory
110 1.1 tron # The final destination directory for Postfix queues.
111 1.1 tron # The built-in default directory name is /var/spool/postfix.
112 1.1 tron # This parameter setting is recorded in the installed main.cf file.
113 1.1 tron # .IP sendmail_path
114 1.1 tron # The final destination pathname for the Postfix sendmail command.
115 1.1 tron # This is the Sendmail-compatible mail posting interface.
116 1.1 tron # The built-in default pathname is system dependent.
117 1.1 tron # This parameter setting is recorded in the installed main.cf file.
118 1.1 tron # .IP newaliases_path
119 1.1 tron # The final destination pathname for the Postfix newaliases command.
120 1.1 tron # This is the Sendmail-compatible command to build alias databases
121 1.1 tron # for the Postfix local delivery agent.
122 1.1 tron # The built-in default pathname is system dependent.
123 1.1 tron # This parameter setting is recorded in the installed main.cf file.
124 1.1 tron # .IP mailq_path
125 1.1 tron # The final destination pathname for the Postfix mailq command.
126 1.1 tron # This is the Sendmail-compatible command to list the mail queue.
127 1.1 tron # The built-in default pathname is system dependent.
128 1.1 tron # This parameter setting is recorded in the installed main.cf file.
129 1.1 tron # .IP mail_owner
130 1.1 tron # The owner of the Postfix queue. Its numerical user ID and group ID
131 1.1 tron # must not be used by any other accounts on the system.
132 1.1 tron # The built-in default account name is postfix.
133 1.1 tron # This parameter setting is recorded in the installed main.cf file.
134 1.1 tron # .IP setgid_group
135 1.1 tron # The group for mail submission and for queue management commands.
136 1.1 tron # Its numerical group ID must not be used by any other accounts on the
137 1.1 tron # system, not even by the mail_owner account.
138 1.1 tron # The built-in default group name is postdrop.
139 1.1 tron # This parameter setting is recorded in the installed main.cf file.
140 1.1 tron # .IP manpage_directory
141 1.1 tron # The destination directory for the Postfix on-line manual pages.
142 1.1 tron # This parameter setting is recorded in the installed main.cf file.
143 1.1 tron # .IP sample_directory
144 1.1 tron # The destination directory for the Postfix sample configuration files.
145 1.1 tron # This parameter is obsolete as of Postfix version 2.1.
146 1.1 tron # This parameter setting is recorded in the installed main.cf file.
147 1.1 tron # .IP readme_directory
148 1.1 tron # The destination directory for the Postfix README files.
149 1.1 tron # This parameter setting is recorded in the installed main.cf file.
150 1.1 tron # SEE ALSO
151 1.1 tron # post-install(1) post-installation procedure
152 1.1 tron # FILES
153 1.1 tron # $config_directory/main.cf, Postfix installation configuration.
154 1.1 tron # $daemon_directory/postfix-files, installation control file.
155 1.1 tron # $config_directory/install.cf, obsolete configuration file.
156 1.1 tron # LICENSE
157 1.1 tron # .ad
158 1.1 tron # .fi
159 1.1 tron # The Secure Mailer license must be distributed with this software.
160 1.1 tron # AUTHOR(S)
161 1.1 tron # Wietse Venema
162 1.1 tron # IBM T.J. Watson Research
163 1.1 tron # P.O. Box 704
164 1.1 tron # Yorktown Heights, NY 10598, USA
165 1.1 tron #--
166 1.1 tron
167 1.1 tron # Initialize.
168 1.1 tron # By now, shells must have functions. Ultrix users must use sh5 or lose.
169 1.1 tron
170 1.1 tron umask 022
171 1.1 tron PATH=/bin:/usr/bin:/usr/sbin:/usr/etc:/sbin:/etc:/usr/contrib/bin:/usr/gnu/bin:/usr/ucb:/usr/bsd
172 1.1 tron SHELL=/bin/sh
173 1.1 tron IFS="
174 1.1 tron "
175 1.1 tron BACKUP_IFS="$IFS"
176 1.1 tron
177 1.1 tron USAGE="Usage: $0 [name=value] [option]
178 1.1 tron -non-interactive Do not ask for installation parameters.
179 1.1 tron -package Build a ready-to-install package.
180 1.1 tron name=value Specify an installation parameter".
181 1.1 tron
182 1.1 tron # Process command-line options and parameter settings. Work around
183 1.1 tron # brain damaged shells. "IFS=value command" should not make the
184 1.1 tron # IFS=value setting permanent. But some broken standard allows it.
185 1.1 tron
186 1.1 tron for arg
187 1.1 tron do
188 1.1 tron case $arg in
189 1.1 tron *=*) IFS= eval $arg; IFS="$BACKUP_IFS";;
190 1.1 tron -non-int*) non_interactive=1;;
191 1.1 tron -package) need_install_root=install_root;;
192 1.1 tron *) echo "$0: Error: $USAGE" 1>&2; exit 1;;
193 1.1 tron esac
194 1.1 tron shift
195 1.1 tron done
196 1.1 tron
197 1.1 tron # Sanity checks.
198 1.1 tron
199 1.1 tron test -z "$non_interactive" -a ! -t 0 && {
200 1.1 tron echo $0: Error: for non-interactive use, run: \"$0 -non-interactive\" 1>&2
201 1.1 tron exit 1
202 1.1 tron }
203 1.1 tron
204 1.1 tron test -x bin/postconf || {
205 1.1 tron echo $0: Error: no bin/postconf file. Did you forget to run \"make\"? 1>&2
206 1.1 tron exit 1
207 1.1 tron }
208 1.1 tron
209 1.1 tron case `uname -s` in
210 1.1 tron HP-UX*) FMT=cat;;
211 1.1 tron *) FMT=fmt;;
212 1.1 tron esac
213 1.1 tron
214 1.1 tron # Disclaimer.
215 1.1 tron
216 1.1 tron test -z "$non_interactive" && cat <<EOF | ${FMT}
217 1.1 tron
218 1.1 tron Warning: if you use this script to install Postfix locally,
219 1.1 tron this script will replace existing sendmail or Postfix programs.
220 1.1 tron Make backups if you want to be able to recover.
221 1.1 tron
222 1.1 tron Before installing files, this script prompts you for some
223 1.1 tron definitions. Most definitions will be remembered, so you have
224 1.1 tron to specify them only once. All definitions should have a
225 1.1 tron reasonable default value.
226 1.1 tron EOF
227 1.1 tron
228 1.1 tron # The following shell functions replace files/symlinks while minimizing
229 1.1 tron # the time that a file does not exist, and avoid copying over files
230 1.1 tron # in order to not disturb running programs. That is certainly desirable
231 1.1 tron # when upgrading Postfix on a live machine. It also avoids surprises
232 1.1 tron # when building a Postfix package for distribution to other systems.
233 1.1 tron
234 1.1 tron compare_or_replace() {
235 1.1 tron mode=$1
236 1.1 tron owner=$2
237 1.1 tron group=$3
238 1.1 tron src=$4
239 1.1 tron dst=$5
240 1.1 tron (cmp $src $dst >/dev/null 2>&1 && echo Skipping $dst...) || {
241 1.1 tron echo Updating $dst...
242 1.1 tron rm -f $tempdir/junk || exit 1
243 1.1 tron cp $src $tempdir/junk || exit 1
244 1.1 tron mv -f $tempdir/junk $dst || exit 1
245 1.1 tron test -z "$owner" || chown $owner $dst || exit 1
246 1.1 tron test -z "$group" || chgrp $group $dst || exit 1
247 1.1 tron chmod $mode $dst || exit 1
248 1.1 tron }
249 1.1 tron }
250 1.1 tron
251 1.1 tron compare_or_symlink() {
252 1.1 tron (cmp $1 $2 >/dev/null 2>&1 && echo Skipping $2...) || {
253 1.1 tron echo Updating $2...
254 1.1 tron rm -f $tempdir/junk || exit 1
255 1.1 tron dest=`echo $1 | sed '
256 1.1 tron s;^'$install_root';;
257 1.1 tron s;/\./;/;g
258 1.1 tron s;//*;/;g
259 1.1 tron s;^/;;
260 1.1 tron '`
261 1.1 tron link=`echo $2 | sed '
262 1.1 tron s;^'$install_root';;
263 1.1 tron s;/\./;/;g
264 1.1 tron s;//*;/;g
265 1.1 tron s;^/;;
266 1.1 tron s;/[^/]*$;/;
267 1.1 tron s;[^/]*/;../;g
268 1.1 tron s;$;'$dest';
269 1.1 tron '`
270 1.1 tron ln -s $link $tempdir/junk || exit 1
271 1.1 tron mv -f $tempdir/junk $2 || {
272 1.1 tron echo $0: Error: your mv command has trouble renaming symlinks. 1>&2
273 1.1 tron echo If you run Linux, upgrade to GNU fileutils-4.0 or better, 1>&2
274 1.1 tron echo or choose a tempdir that is in the same file system as $2. 1>&2
275 1.1 tron echo If you run FreeBSD, upgrade to version 5 or better. 1>&2
276 1.1 tron exit 1
277 1.1 tron }
278 1.1 tron }
279 1.1 tron }
280 1.1 tron
281 1.1 tron compare_or_hardlink() {
282 1.1 tron (cmp $1 $2 >/dev/null 2>&1 && echo Skipping $2...) || {
283 1.1 tron echo Updating $2...
284 1.1 tron rm -f $2 || exit 1
285 1.1 tron ln $1 $2 || exit 1
286 1.1 tron }
287 1.1 tron }
288 1.1 tron
289 1.1 tron check_parent() {
290 1.1 tron for path
291 1.1 tron do
292 1.1 tron dir=`echo $path|sed -e 's/[/][/]*[^/]*$//' -e 's/^$/\//'`
293 1.1 tron test -d $dir || mkdir -p $dir || exit 1
294 1.1 tron done
295 1.1 tron }
296 1.1 tron
297 1.1 tron # How to supress newlines in echo.
298 1.1 tron
299 1.1 tron case `echo -n` in
300 1.1 tron "") n=-n; c=;;
301 1.1 tron *) n=; c='\c';;
302 1.1 tron esac
303 1.1 tron
304 1.1 tron # Prompts.
305 1.1 tron
306 1.1 tron install_root_prompt="the prefix for installed file names. Specify
307 1.1 tron this ONLY if you are building ready-to-install packages for
308 1.3 tron distribution to OTHER machines. See PACKAGE_README for instructions."
309 1.1 tron
310 1.1 tron tempdir_prompt="a directory for scratch files while installing
311 1.1 tron Postfix. You must have write permission in this directory."
312 1.1 tron
313 1.1 tron config_directory_prompt="the final destination directory for
314 1.1 tron installed Postfix configuration files."
315 1.1 tron
316 1.1 tron data_directory_prompt="the final destination directory for
317 1.1 tron Postfix-writable data files such as caches or random numbers. This
318 1.1 tron directory should not be shared with non-Postfix software."
319 1.1 tron
320 1.1 tron daemon_directory_prompt="the final destination directory for
321 1.1 tron installed Postfix daemon programs. This directory should not be
322 1.1 tron in the command search path of any users."
323 1.1 tron
324 1.1 tron command_directory_prompt="the final destination directory for
325 1.1 tron installed Postfix administrative commands. This directory should
326 1.1 tron be in the command search path of adminstrative users."
327 1.1 tron
328 1.1 tron queue_directory_prompt="the final destination directory for Postfix
329 1.1 tron queues."
330 1.1 tron
331 1.1 tron sendmail_path_prompt="the final destination pathname for the
332 1.1 tron installed Postfix sendmail command. This is the Sendmail-compatible
333 1.1 tron mail posting interface."
334 1.1 tron
335 1.1 tron newaliases_path_prompt="the final destination pathname for the
336 1.1 tron installed Postfix newaliases command. This is the Sendmail-compatible
337 1.1 tron command to build alias databases for the Postfix local delivery
338 1.1 tron agent."
339 1.1 tron
340 1.1 tron mailq_path_prompt="the final destination pathname for the installed
341 1.1 tron Postfix mailq command. This is the Sendmail-compatible mail queue
342 1.1 tron listing command."
343 1.1 tron
344 1.1 tron mail_owner_prompt="the owner of the Postfix queue. Specify an
345 1.1 tron account with numerical user ID and group ID values that are not
346 1.1 tron used by any other accounts on the system."
347 1.1 tron
348 1.1 tron setgid_group_prompt="the group for mail submission and for queue
349 1.1 tron management commands. Specify a group name with a numerical group
350 1.1 tron ID that is not shared with other accounts, not even with the Postfix
351 1.1 tron mail_owner account. You can no longer specify \"no\" here."
352 1.1 tron
353 1.1 tron manpage_directory_prompt="the destination directory for the Postfix on-line
354 1.1 tron manual pages. You can no longer specify \"no\" here."
355 1.1 tron
356 1.1 tron readme_directory_prompt="the destination directory for the Postfix
357 1.1 tron README files. Specify \"no\" if you do not want to install these files."
358 1.1 tron
359 1.1 tron html_directory_prompt="the destination directory for the Postfix
360 1.1 tron HTML files. Specify \"no\" if you do not want to install these files."
361 1.1 tron
362 1.1 tron # Default settings, just to get started.
363 1.1 tron
364 1.1 tron : ${install_root=/}
365 1.1 tron : ${tempdir=`pwd`}
366 1.1 tron : ${config_directory=`bin/postconf -h -d config_directory`}
367 1.1 tron
368 1.1 tron # Find out the location of installed configuration files.
369 1.1 tron
370 1.1 tron test -z "$non_interactive" && for name in install_root tempdir config_directory
371 1.1 tron do
372 1.1 tron while :
373 1.1 tron do
374 1.1 tron echo
375 1.1 tron eval echo Please specify \$${name}_prompt | ${FMT}
376 1.1 tron eval echo \$n "$name: [\$$name]\ \$c"
377 1.1 tron read ans
378 1.1 tron case $ans in
379 1.1 tron "") break;;
380 1.1 tron *) case $ans in
381 1.1 tron /*) eval $name=$ans; break;;
382 1.1 tron *) echo; echo $0: Error: $name should be an absolute path name. 1>&2;;
383 1.1 tron esac;;
384 1.1 tron esac
385 1.1 tron done
386 1.1 tron done
387 1.1 tron
388 1.1 tron # In case some systems special-case pathnames beginning with //.
389 1.1 tron
390 1.1 tron case $install_root in
391 1.1 tron /) install_root=
392 1.1 tron esac
393 1.1 tron
394 1.1 tron test -z "$need_install_root" || test -n "$install_root" || {
395 1.1 tron echo $0: Error: invalid package root directory: \"install_root=/\" 1>&2
396 1.1 tron exit 1
397 1.1 tron }
398 1.1 tron
399 1.1 tron CONFIG_DIRECTORY=$install_root$config_directory
400 1.1 tron
401 1.1 tron # If a parameter is not set via the command line or environment,
402 1.1 tron # try to use settings from installed configuration files.
403 1.1 tron
404 1.1 tron # Extract parameter settings from the obsolete install.cf file, as
405 1.1 tron # a transitional aid.
406 1.1 tron
407 1.1 tron grep setgid_group $CONFIG_DIRECTORY/main.cf >/dev/null 2>&1 || {
408 1.1 tron test -f $CONFIG_DIRECTORY/install.cf && {
409 1.1 tron for name in sendmail_path newaliases_path mailq_path setgid manpages
410 1.1 tron do
411 1.1 tron eval junk=\$$name
412 1.1 tron case "$junk" in
413 1.1 tron "") eval unset $name;;
414 1.1 tron esac
415 1.1 tron eval : \${$name="\`. $CONFIG_DIRECTORY/install.cf; echo \$$name\`"} \
416 1.1 tron || exit 1
417 1.1 tron done
418 1.1 tron : ${setgid_group=$setgid}
419 1.1 tron : ${manpage_directory=$manpages}
420 1.1 tron }
421 1.1 tron }
422 1.1 tron
423 1.1 tron CONFIG_PARAMS="command_directory daemon_directory data_directory \
424 1.1 tron html_directory mail_owner mailq_path manpage_directory newaliases_path \
425 1.1 tron queue_directory readme_directory sendmail_path setgid_group"
426 1.1 tron
427 1.1 tron # Extract parameter settings from the installed main.cf file.
428 1.1 tron
429 1.1 tron test -f $CONFIG_DIRECTORY/main.cf && {
430 1.1 tron for name in $CONFIG_PARAMS sample_directory
431 1.1 tron do
432 1.1 tron eval junk=\$$name
433 1.1 tron case "$junk" in
434 1.1 tron "") eval unset $name;;
435 1.1 tron esac
436 1.1 tron eval : \${$name=\`bin/postconf -c $CONFIG_DIRECTORY -h $name\`} ||
437 1.1 tron exit 1
438 1.1 tron done
439 1.1 tron }
440 1.1 tron
441 1.1 tron # Use built-in defaults as the final source of parameter settings.
442 1.1 tron
443 1.1 tron for name in $CONFIG_PARAMS sample_directory
444 1.1 tron do
445 1.1 tron eval junk=\$$name
446 1.1 tron case "$junk" in
447 1.1 tron "") eval unset $name;;
448 1.1 tron esac
449 1.1 tron eval : \${$name=\`bin/postconf -d -h $name\`} || exit 1
450 1.1 tron done
451 1.1 tron
452 1.1 tron # Override settings manually.
453 1.1 tron
454 1.1 tron test -z "$non_interactive" && for name in $CONFIG_PARAMS
455 1.1 tron do
456 1.1 tron while :
457 1.1 tron do
458 1.1 tron echo
459 1.1 tron eval echo Please specify \$${name}_prompt | ${FMT}
460 1.1 tron eval echo \$n "$name: [\$$name]\ \$c"
461 1.1 tron read ans
462 1.1 tron case $ans in
463 1.1 tron "") break;;
464 1.1 tron *) eval $name=$ans; break;;
465 1.1 tron esac
466 1.1 tron done
467 1.1 tron done
468 1.1 tron
469 1.1 tron # Sanity checks
470 1.1 tron
471 1.1 tron case "$setgid_group" in
472 1.1 tron no) (echo $0: Error: the setgid_group parameter no longer accepts
473 1.1 tron echo \"no\" values. Try again with \"setgid_group=groupname\" on the
474 1.1 tron echo command line or execute \"make install\" and specify setgid_group
475 1.1 tron echo interactively.) | ${FMT} 1>&2
476 1.1 tron exit 1;;
477 1.1 tron esac
478 1.1 tron
479 1.1 tron case "$manpage_directory" in
480 1.1 tron no) (echo $0: Error: the manpage_directory parameter no longer accepts
481 1.1 tron echo \"no\" values. Try again with \"manpage_directory=/path/name\"
482 1.1 tron echo on the command line or execute \"make install\" and specify
483 1.1 tron echo manpage_directory interactively.) | ${FMT} 1>&2
484 1.1 tron exit 1;;
485 1.1 tron esac
486 1.1 tron
487 1.1 tron for path in "$html_directory" "$readme_directory"
488 1.1 tron do
489 1.1 tron case "$path" in
490 1.1 tron /*) ;;
491 1.1 tron no) ;;
492 1.1 tron *) echo $0: Error: \"$path\" should be \"no\" or an absolute path name. 1>&2
493 1.1 tron exit 1;;
494 1.1 tron esac
495 1.1 tron done
496 1.1 tron
497 1.1 tron for path in "$daemon_directory" "$data_directory" "$command_directory" "$queue_directory" \
498 1.1 tron "$sendmail_path" "$newaliases_path" "$mailq_path" "$manpage_directory"
499 1.1 tron do
500 1.1 tron case "$path" in
501 1.1 tron /*) ;;
502 1.1 tron *) echo $0: Error: \"$path\" should be an absolute path name. 1>&2; exit 1;;
503 1.1 tron esac
504 1.1 tron done
505 1.1 tron
506 1.1 tron for path in mailq_path newaliases_path sendmail_path
507 1.1 tron do
508 1.1 tron eval test -d $install_root\$$path && {
509 1.1 tron echo $0: Error: \"$path\" specifies a directory. 1>&2
510 1.1 tron exit 1
511 1.1 tron }
512 1.1 tron done
513 1.1 tron
514 1.1 tron for path in command_directory config_directory daemon_directory data_directory \
515 1.1 tron manpage_directory queue_directory html_directory readme_directory
516 1.1 tron do
517 1.1 tron eval test -f $install_root\$$path && {
518 1.1 tron echo $0: Error: \"$path\" specifies a regular file. 1>&2
519 1.1 tron exit 1
520 1.1 tron }
521 1.1 tron done
522 1.1 tron
523 1.1 tron test -d $tempdir || mkdir -p $tempdir || exit 1
524 1.1 tron
525 1.1 tron trap "rm -f $tempdir/junk" 0 1 2 3 15
526 1.1 tron
527 1.1 tron ( rm -f $tempdir/junk && touch $tempdir/junk ) || {
528 1.1 tron echo $0: Error: you have no write permission to $tempdir. 1>&2
529 1.1 tron echo Specify an alternative directory for scratch files. 1>&2
530 1.1 tron exit 1
531 1.1 tron }
532 1.1 tron
533 1.1 tron test -z "$install_root" && {
534 1.1 tron
535 1.1 tron chown root $tempdir/junk >/dev/null 2>&1 || {
536 1.1 tron echo Error: you have no permission to change file ownership. 1>&2
537 1.1 tron exit 1
538 1.1 tron }
539 1.1 tron
540 1.1 tron chown "$mail_owner" $tempdir/junk >/dev/null 2>&1 || {
541 1.1 tron echo $0: Error: \"$mail_owner\" needs an entry in the passwd file. 1>&2
542 1.1 tron echo Remember, \"$mail_owner\" needs a dedicated user and group id. 1>&2
543 1.1 tron exit 1
544 1.1 tron }
545 1.1 tron
546 1.1 tron chgrp "$setgid_group" $tempdir/junk >/dev/null 2>&1 || {
547 1.1 tron echo $0: Error: \"$setgid_group\" needs an entry in the group file. 1>&2
548 1.1 tron echo Remember, \"$setgid_group\" needs a dedicated group id. 1>&2
549 1.1 tron exit 1
550 1.1 tron }
551 1.1 tron
552 1.1 tron }
553 1.1 tron
554 1.1 tron rm -f $tempdir/junk || exit 1
555 1.1 tron
556 1.1 tron trap 0 1 2 3 15
557 1.1 tron
558 1.1 tron # Avoid clumsiness.
559 1.1 tron
560 1.1 tron DAEMON_DIRECTORY=$install_root$daemon_directory
561 1.1 tron COMMAND_DIRECTORY=$install_root$command_directory
562 1.1 tron QUEUE_DIRECTORY=$install_root$queue_directory
563 1.1 tron SENDMAIL_PATH=$install_root$sendmail_path
564 1.1 tron HTML_DIRECTORY=$install_root$html_directory
565 1.1 tron MANPAGE_DIRECTORY=$install_root$manpage_directory
566 1.1 tron README_DIRECTORY=$install_root$readme_directory
567 1.1 tron
568 1.1 tron # Avoid repeated tests for existence of these; default permissions suffice.
569 1.1 tron
570 1.1 tron test -d $DAEMON_DIRECTORY || mkdir -p $DAEMON_DIRECTORY || exit 1
571 1.1 tron test -d $COMMAND_DIRECTORY || mkdir -p $COMMAND_DIRECTORY || exit 1
572 1.1 tron test -d $COMMAND_DIRECTORY || mkdir -p $COMMAND_DIRECTORY || exit 1
573 1.1 tron test "$html_directory" = "no" -o -d $HTML_DIRECTORY ||
574 1.1 tron mkdir -p $HTML_DIRECTORY || exit 1
575 1.1 tron test "$readme_directory" = "no" -o -d $README_DIRECTORY ||
576 1.1 tron mkdir -p $README_DIRECTORY || exit 1
577 1.1 tron
578 1.1 tron # Upgrade or first-time installation?
579 1.1 tron
580 1.1 tron if [ -f $CONFIG_DIRECTORY/main.cf ]
581 1.1 tron then
582 1.1 tron post_install_options="upgrade-source"
583 1.1 tron else
584 1.1 tron post_install_options="first-install"
585 1.1 tron fi
586 1.1 tron
587 1.1 tron # Install files, using information from the postfix-files file.
588 1.1 tron
589 1.1 tron exec < libexec/postfix-files || exit 1
590 1.1 tron while IFS=: read path type owner group mode flags junk
591 1.1 tron do
592 1.1 tron IFS="$BACKUP_IFS"
593 1.1 tron
594 1.1 tron # Skip comments.
595 1.1 tron
596 1.1 tron case $path in
597 1.1 tron [$]*) ;;
598 1.1 tron *) continue;;
599 1.1 tron esac
600 1.1 tron
601 1.1 tron # Skip over files that ought to be removed.
602 1.1 tron # Leave it up to post-install to report them to the user.
603 1.1 tron
604 1.1 tron case $flags in
605 1.1 tron *o*) continue
606 1.1 tron esac
607 1.1 tron
608 1.1 tron # Skip over files that must be preserved.
609 1.1 tron
610 1.1 tron case $flags in
611 1.1 tron *p*) eval test -f $install_root$path && {
612 1.1 tron eval echo "Skipping $install_root$path..."
613 1.1 tron continue
614 1.1 tron };;
615 1.1 tron esac
616 1.1 tron
617 1.1 tron # Save source path before it is clobbered.
618 1.1 tron
619 1.1 tron case $type in
620 1.1 tron [hl]) eval source=$owner;;
621 1.1 tron esac
622 1.1 tron
623 1.1 tron # If installing from source code, apply special permissions or ownership.
624 1.1 tron # If building a package, don't apply special permissions or ownership.
625 1.1 tron
626 1.1 tron case $install_root in
627 1.1 tron "") case $owner in
628 1.1 tron [$]*) eval owner=$owner;;
629 1.1 tron root) owner=;;
630 1.1 tron esac
631 1.1 tron case $group in
632 1.1 tron [$]*) eval group=$group;;
633 1.1 tron -) group=;;
634 1.1 tron esac;;
635 1.1 tron *) case $mode in
636 1.1 tron [1-7]755) mode=755;;
637 1.1 tron esac
638 1.1 tron owner=
639 1.1 tron group=;;
640 1.1 tron esac
641 1.1 tron
642 1.1 tron
643 1.1 tron case $type in
644 1.1 tron
645 1.1 tron # Create/update directory.
646 1.1 tron
647 1.1 tron d) eval path=$install_root$path
648 1.1 tron test "$path" = "${install_root}no" -o -d $path || {
649 1.1 tron mkdir -p $path || exit 1
650 1.1 tron test -z "$owner" || chown $owner $path || exit 1
651 1.1 tron test -z "$group" || chgrp $group $path || exit 1
652 1.1 tron chmod $mode $path || exit 1
653 1.1 tron }
654 1.1 tron continue;;
655 1.1 tron
656 1.1 tron # Create/update regular file.
657 1.1 tron
658 1.1 tron f) echo $path | (IFS=/ read prefix file; IFS="$BACKUP_IFS"
659 1.1 tron case $prefix in
660 1.1 tron '$daemon_directory')
661 1.1 tron compare_or_replace $mode "$owner" "$group" libexec/$file \
662 1.1 tron $DAEMON_DIRECTORY/$file || exit 1;;
663 1.1 tron '$command_directory')
664 1.1 tron compare_or_replace $mode "$owner" "$group" bin/$file \
665 1.1 tron $COMMAND_DIRECTORY/$file || exit 1;;
666 1.1 tron '$config_directory')
667 1.1 tron compare_or_replace $mode "$owner" "$group" conf/$file \
668 1.1 tron $CONFIG_DIRECTORY/$file || exit 1;;
669 1.1 tron '$sendmail_path')
670 1.1 tron check_parent $SENDMAIL_PATH || exit 1
671 1.1 tron compare_or_replace $mode "$owner" "$group" bin/sendmail \
672 1.1 tron $SENDMAIL_PATH || exit 1;;
673 1.1 tron '$html_directory')
674 1.1 tron test "$html_directory" = "no" ||
675 1.1 tron compare_or_replace $mode "$owner" "$group" html/$file \
676 1.1 tron $HTML_DIRECTORY/$file || exit 1;;
677 1.1 tron '$manpage_directory')
678 1.1 tron check_parent $MANPAGE_DIRECTORY/$file || exit 1
679 1.1 tron compare_or_replace $mode "$owner" "$group" man/$file \
680 1.1 tron $MANPAGE_DIRECTORY/$file || exit 1;;
681 1.1 tron '$readme_directory')
682 1.1 tron test "$readme_directory" = "no" ||
683 1.1 tron compare_or_replace $mode "$owner" "$group" README_FILES/$file \
684 1.1 tron $README_DIRECTORY/$file || exit 1;;
685 1.1 tron *) echo $0: Error: unknown entry $path in libexec/postfix-files 1>&2
686 1.1 tron exit 1;;
687 1.1 tron esac) || exit 1
688 1.1 tron continue;;
689 1.1 tron
690 1.1 tron # Hard link. Skip files that are not installed.
691 1.1 tron
692 1.1 tron h) eval echo $path | (
693 1.1 tron IFS=/ read prefix file; IFS="$BACKUP_IFS"
694 1.1 tron test "$prefix" = "no" || (
695 1.1 tron eval dest_path=$install_root$path
696 1.1 tron check_parent $dest_path || exit 1
697 1.1 tron eval source_path=$install_root$source
698 1.1 tron compare_or_hardlink $source_path $dest_path || exit 1
699 1.1 tron )
700 1.1 tron ) || exit 1
701 1.1 tron continue;;
702 1.1 tron
703 1.1 tron # Symbolic link. Skip files that are not installed.
704 1.1 tron
705 1.1 tron l) eval echo $path | (
706 1.1 tron IFS=/ read prefix file; IFS="$BACKUP_IFS"
707 1.1 tron test "$prefix" = "no" || (
708 1.1 tron eval dest_path=$install_root$path
709 1.1 tron check_parent $dest_path || exit 1
710 1.1 tron eval source_path=$install_root$source
711 1.1 tron compare_or_symlink $source_path $dest_path || exit 1
712 1.1 tron )
713 1.1 tron ) || exit 1
714 1.1 tron continue;;
715 1.1 tron
716 1.1 tron *) echo $0: Error: unknown type $type for $path in libexec/postfix-files 1>&2
717 1.1 tron exit 1;;
718 1.1 tron esac
719 1.1 tron
720 1.1 tron done
721 1.1 tron
722 1.1 tron # Save the installation parameters to main.cf even when they haven't
723 1.1 tron # changed from their current default. Defaults can change between
724 1.1 tron # Postfix releases, and software should not suddenly be installed in
725 1.1 tron # the wrong place when Postfix is being upgraded.
726 1.1 tron
727 1.1 tron bin/postconf -c $CONFIG_DIRECTORY -e \
728 1.1 tron "daemon_directory = $daemon_directory" \
729 1.1 tron "data_directory = $data_directory" \
730 1.1 tron "command_directory = $command_directory" \
731 1.1 tron "queue_directory = $queue_directory" \
732 1.1 tron "mail_owner = $mail_owner" \
733 1.1 tron "setgid_group = $setgid_group" \
734 1.1 tron "sendmail_path = $sendmail_path" \
735 1.1 tron "mailq_path = $mailq_path" \
736 1.1 tron "newaliases_path = $newaliases_path" \
737 1.1 tron "html_directory = $html_directory" \
738 1.1 tron "manpage_directory = $manpage_directory" \
739 1.1 tron "sample_directory = $sample_directory" \
740 1.1 tron "readme_directory = $readme_directory" \
741 1.1 tron || exit 1
742 1.1 tron
743 1.1 tron # If Postfix is being installed locally from source code, do the
744 1.1 tron # post-install processing now.
745 1.1 tron
746 1.1 tron test -n "$install_root" || {
747 1.1 tron bin/postfix post-install $post_install_options || exit 1
748 1.1 tron }
749