postfix-install revision 1.6 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.6 christos # the postfix-install command line. This mode will replace
61 1.6 christos # the string MAIL_VERSION at the end of a configuration
62 1.6 christos # parameter value with the Postfix release version (Postfix
63 1.6 christos # 3.0 and later).
64 1.1 tron # .IP "process environment"
65 1.1 tron # Parameter settings can be given as name=value environment
66 1.6 christos # variables. Environment parameters can also be specified on
67 1.6 christos # the make(1) command line as "make install name=value ...".
68 1.6 christos # This mode will replace the string MAIL_VERSION at the end
69 1.6 christos # of a configuration parameter value with the Postfix release
70 1.6 christos # version (Postfix 3.0 and later).
71 1.1 tron # .IP "installed configuration files"
72 1.1 tron # If a parameter is not specified via the command line or via the
73 1.1 tron # process environment, postfix-install will attempt to extract its
74 1.1 tron # value from an already installed Postfix main.cf configuration file.
75 1.1 tron # .IP "built-in defaults"
76 1.1 tron # These settings have the lowest precedence.
77 1.1 tron # INSTALLATION PARAMETER DESCRIPTION
78 1.1 tron # .ad
79 1.1 tron # .fi
80 1.1 tron # The description of installation parameters and their built-in
81 1.1 tron # default settings is as follows:
82 1.1 tron # .IP install_root
83 1.1 tron # Prefix that is prepended to the pathnames of installed files.
84 1.1 tron # Specify this ONLY when creating pre-built packages for distribution to
85 1.1 tron # other systems. The built-in default is "/", the local root directory.
86 1.1 tron # This parameter setting is not recorded in the installed main.cf file.
87 1.1 tron # .IP tempdir
88 1.1 tron # Directory for scratch files while installing Postfix.
89 1.1 tron # You must have write permission in this directory.
90 1.1 tron # The built-in default directory name is the current directory.
91 1.1 tron # This parameter setting is not recorded in the installed main.cf file.
92 1.1 tron # .IP config_directory
93 1.1 tron # The final destination directory for Postfix configuration files.
94 1.1 tron # The built-in default directory name is /etc/postfix.
95 1.1 tron # This parameter setting is not recorded in the installed main.cf file
96 1.1 tron # and can be changed only by recompiling Postfix.
97 1.1 tron # .IP data_directory
98 1.1 tron # The final destination directory for Postfix-writable data files such
99 1.1 tron # as caches. This directory should not be shared with non-Postfix
100 1.2 tron # software. The built-in default directory name is /var/db/postfix.
101 1.1 tron # This parameter setting is recorded in the installed main.cf file.
102 1.1 tron # .IP daemon_directory
103 1.1 tron # The final destination directory for Postfix daemon programs. This
104 1.1 tron # directory should not be in the command search path of any users.
105 1.1 tron # The built-in default directory name is /usr/libexec/postfix.
106 1.1 tron # This parameter setting is recorded in the installed main.cf file.
107 1.1 tron # .IP command_directory
108 1.1 tron # The final destination directory for Postfix administrative commands.
109 1.1 tron # This directory should be in the command search path of adminstrative
110 1.1 tron # users. The built-in default directory name is system dependent.
111 1.1 tron # This parameter setting is recorded in the installed main.cf file.
112 1.1 tron # .IP html_directory
113 1.5 tron # The final destination directory for the Postfix HTML files.
114 1.1 tron # This parameter setting is recorded in the installed main.cf file.
115 1.1 tron # .IP queue_directory
116 1.1 tron # The final destination directory for Postfix queues.
117 1.1 tron # The built-in default directory name is /var/spool/postfix.
118 1.1 tron # This parameter setting is recorded in the installed main.cf file.
119 1.1 tron # .IP sendmail_path
120 1.1 tron # The final destination pathname for the Postfix sendmail command.
121 1.1 tron # This is the Sendmail-compatible mail posting interface.
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 newaliases_path
125 1.1 tron # The final destination pathname for the Postfix newaliases command.
126 1.1 tron # This is the Sendmail-compatible command to build alias databases
127 1.1 tron # for the Postfix local delivery agent.
128 1.1 tron # The built-in default pathname is system dependent.
129 1.1 tron # This parameter setting is recorded in the installed main.cf file.
130 1.1 tron # .IP mailq_path
131 1.1 tron # The final destination pathname for the Postfix mailq command.
132 1.1 tron # This is the Sendmail-compatible command to list the mail queue.
133 1.1 tron # The built-in default pathname is system dependent.
134 1.1 tron # This parameter setting is recorded in the installed main.cf file.
135 1.1 tron # .IP mail_owner
136 1.1 tron # The owner of the Postfix queue. Its numerical user ID and group ID
137 1.1 tron # must not be used by any other accounts on the system.
138 1.1 tron # The built-in default account name is postfix.
139 1.1 tron # This parameter setting is recorded in the installed main.cf file.
140 1.1 tron # .IP setgid_group
141 1.1 tron # The group for mail submission and for queue management commands.
142 1.1 tron # Its numerical group ID must not be used by any other accounts on the
143 1.1 tron # system, not even by the mail_owner account.
144 1.1 tron # The built-in default group name is postdrop.
145 1.1 tron # This parameter setting is recorded in the installed main.cf file.
146 1.1 tron # .IP manpage_directory
147 1.5 tron # The final destination directory for the Postfix on-line manual pages.
148 1.1 tron # This parameter setting is recorded in the installed main.cf file.
149 1.1 tron # .IP sample_directory
150 1.5 tron # The final destination directory for the Postfix sample configuration
151 1.5 tron # files. This parameter is obsolete as of Postfix version 2.1.
152 1.1 tron # This parameter setting is recorded in the installed main.cf file.
153 1.6 christos # .IP meta_directory
154 1.6 christos # The final destination directory for non-executable files
155 1.6 christos # that are shared among multiple Postfix instances, such
156 1.6 christos # as postfix-files, dynamicmaps.cf, as well as the multi-instance
157 1.6 christos # template files main.cf.proto and master.cf.proto. This
158 1.6 christos # directory should contain only Postfix-related files.
159 1.1 tron # .IP readme_directory
160 1.5 tron # The final destination directory for the Postfix README files.
161 1.1 tron # This parameter setting is recorded in the installed main.cf file.
162 1.6 christos # .IP shlib_directory
163 1.6 christos # The final destination directory for Postfix shared-library
164 1.6 christos # files, and the default directory for Postfix database plugin
165 1.6 christos # files with a relative pathname in the file dynamicmaps.cf.
166 1.6 christos # This directory should contain only Postfix-related files.
167 1.6 christos # The shlib_directory parameter built-in default value is
168 1.6 christos # specified at compile time. If you change this at installation
169 1.6 christos # time, then additional configuration will be required with
170 1.6 christos # ldconfig(1) or equivalent.
171 1.1 tron # SEE ALSO
172 1.1 tron # post-install(1) post-installation procedure
173 1.1 tron # FILES
174 1.1 tron # $config_directory/main.cf, Postfix installation configuration.
175 1.6 christos # $meta_directory/postfix-files, installation control file.
176 1.1 tron # $config_directory/install.cf, obsolete configuration file.
177 1.1 tron # LICENSE
178 1.1 tron # .ad
179 1.1 tron # .fi
180 1.1 tron # The Secure Mailer license must be distributed with this software.
181 1.1 tron # AUTHOR(S)
182 1.1 tron # Wietse Venema
183 1.1 tron # IBM T.J. Watson Research
184 1.1 tron # P.O. Box 704
185 1.1 tron # Yorktown Heights, NY 10598, USA
186 1.6 christos #
187 1.6 christos # Wietse Venema
188 1.6 christos # Google, Inc.
189 1.6 christos # 111 8th Avenue
190 1.6 christos # New York, NY 10011, USA
191 1.1 tron #--
192 1.1 tron
193 1.1 tron # Initialize.
194 1.1 tron # By now, shells must have functions. Ultrix users must use sh5 or lose.
195 1.1 tron
196 1.1 tron umask 022
197 1.1 tron PATH=/bin:/usr/bin:/usr/sbin:/usr/etc:/sbin:/etc:/usr/contrib/bin:/usr/gnu/bin:/usr/ucb:/usr/bsd
198 1.1 tron SHELL=/bin/sh
199 1.1 tron IFS="
200 1.1 tron "
201 1.1 tron BACKUP_IFS="$IFS"
202 1.1 tron
203 1.5 tron # This script uses outputs from Postfix and non-Postfix commands.
204 1.5 tron # Override all LC_* settings and LANG for robustness.
205 1.5 tron LC_ALL=C; export LC_ALL
206 1.5 tron
207 1.6 christos if [ -n "$SHLIB_ENV_VAR" ]; then
208 1.6 christos junk="${SHLIB_ENV_VAL}"
209 1.6 christos eval export "$SHLIB_ENV_VAR=\$junk"
210 1.6 christos fi
211 1.6 christos
212 1.1 tron USAGE="Usage: $0 [name=value] [option]
213 1.1 tron -non-interactive Do not ask for installation parameters.
214 1.1 tron -package Build a ready-to-install package.
215 1.1 tron name=value Specify an installation parameter".
216 1.1 tron
217 1.1 tron # Process command-line options and parameter settings. Work around
218 1.1 tron # brain damaged shells. "IFS=value command" should not make the
219 1.1 tron # IFS=value setting permanent. But some broken standard allows it.
220 1.1 tron
221 1.1 tron for arg
222 1.1 tron do
223 1.1 tron case $arg in
224 1.6 christos *[" "]*) echo "$0: Error: argument contains whitespace: '$arg'"; exit 1;;
225 1.6 christos *=*) IFS= eval $arg; IFS="$BACKUP_IFS";;
226 1.6 christos -non-int*) non_interactive=1;;
227 1.6 christos -package) need_install_root=install_root;;
228 1.6 christos *) echo "$0: Error: $USAGE" 1>&2; exit 1;;
229 1.1 tron esac
230 1.1 tron shift
231 1.1 tron done
232 1.1 tron
233 1.1 tron # Sanity checks.
234 1.1 tron
235 1.1 tron test -z "$non_interactive" -a ! -t 0 && {
236 1.1 tron echo $0: Error: for non-interactive use, run: \"$0 -non-interactive\" 1>&2
237 1.1 tron exit 1
238 1.1 tron }
239 1.1 tron
240 1.1 tron test -x bin/postconf || {
241 1.1 tron echo $0: Error: no bin/postconf file. Did you forget to run \"make\"? 1>&2
242 1.1 tron exit 1
243 1.1 tron }
244 1.1 tron
245 1.6 christos CONFIG_PARAMS="command_directory daemon_directory data_directory \
246 1.6 christos html_directory mail_owner mailq_path manpage_directory newaliases_path \
247 1.6 christos queue_directory readme_directory sendmail_path setgid_group shlib_directory \
248 1.6 christos meta_directory"
249 1.6 christos
250 1.6 christos # Expand the string MAIL_VERSION at the end of "make install" etc.
251 1.6 christos # name=value command-line arguments (and consequently, in environment
252 1.6 christos # settings), for consistency with "make makefiles".
253 1.6 christos
254 1.6 christos # Note that MAIL_VERSION) does not anchor the match at the end.
255 1.6 christos
256 1.6 christos for name in $CONFIG_PARAMS sample_directory install_root tempdir
257 1.6 christos do
258 1.6 christos eval junk=\$$name
259 1.6 christos case "$junk" in
260 1.6 christos *MAIL_VERSION*)
261 1.6 christos case "$mail_version" in
262 1.6 christos "") mail_version="`bin/postconf -dhx mail_version`" || exit 1
263 1.6 christos esac
264 1.6 christos val=`echo "$junk" | sed 's/MAIL_VERSION$/'"$mail_version/g"` || exit 1
265 1.6 christos case "$val" in
266 1.6 christos *MAIL_VERSION*)
267 1.6 christos echo "MAIL_VERSION not at end of parameter value: $junk" 1>&2; exit 1
268 1.6 christos esac
269 1.6 christos eval ${name}='"$val"'
270 1.6 christos esac
271 1.6 christos done
272 1.6 christos
273 1.1 tron case `uname -s` in
274 1.1 tron HP-UX*) FMT=cat;;
275 1.1 tron *) FMT=fmt;;
276 1.1 tron esac
277 1.1 tron
278 1.1 tron # Disclaimer.
279 1.1 tron
280 1.1 tron test -z "$non_interactive" && cat <<EOF | ${FMT}
281 1.1 tron
282 1.1 tron Warning: if you use this script to install Postfix locally,
283 1.1 tron this script will replace existing sendmail or Postfix programs.
284 1.1 tron Make backups if you want to be able to recover.
285 1.1 tron
286 1.1 tron Before installing files, this script prompts you for some
287 1.1 tron definitions. Most definitions will be remembered, so you have
288 1.1 tron to specify them only once. All definitions should have a
289 1.1 tron reasonable default value.
290 1.1 tron EOF
291 1.1 tron
292 1.1 tron # The following shell functions replace files/symlinks while minimizing
293 1.1 tron # the time that a file does not exist, and avoid copying over files
294 1.1 tron # in order to not disturb running programs. That is certainly desirable
295 1.1 tron # when upgrading Postfix on a live machine. It also avoids surprises
296 1.1 tron # when building a Postfix package for distribution to other systems.
297 1.1 tron
298 1.1 tron compare_or_replace() {
299 1.1 tron mode=$1
300 1.1 tron owner=$2
301 1.1 tron group=$3
302 1.1 tron src=$4
303 1.1 tron dst=$5
304 1.1 tron (cmp $src $dst >/dev/null 2>&1 && echo Skipping $dst...) || {
305 1.1 tron echo Updating $dst...
306 1.1 tron rm -f $tempdir/junk || exit 1
307 1.1 tron cp $src $tempdir/junk || exit 1
308 1.1 tron mv -f $tempdir/junk $dst || exit 1
309 1.1 tron test -z "$owner" || chown $owner $dst || exit 1
310 1.1 tron test -z "$group" || chgrp $group $dst || exit 1
311 1.1 tron chmod $mode $dst || exit 1
312 1.1 tron }
313 1.1 tron }
314 1.1 tron
315 1.6 christos myreadlink() {
316 1.6 christos ls -ld -- "$@" 2>/dev/null | awk '
317 1.6 christos /->/ { print $NF; next }
318 1.6 christos { exit(1) }
319 1.6 christos '
320 1.6 christos }
321 1.6 christos
322 1.1 tron compare_or_symlink() {
323 1.6 christos case $1 in
324 1.6 christos /*) dest=`echo $1 | sed '
325 1.1 tron s;^'$install_root';;
326 1.1 tron s;/\./;/;g
327 1.1 tron s;//*;/;g
328 1.1 tron s;^/;;
329 1.1 tron '`
330 1.1 tron link=`echo $2 | sed '
331 1.1 tron s;^'$install_root';;
332 1.1 tron s;/\./;/;g
333 1.1 tron s;//*;/;g
334 1.1 tron s;^/;;
335 1.1 tron s;/[^/]*$;/;
336 1.1 tron s;[^/]*/;../;g
337 1.1 tron s;$;'$dest';
338 1.1 tron '`
339 1.6 christos ;;
340 1.6 christos *) link=$1
341 1.6 christos ;;
342 1.6 christos esac
343 1.6 christos (test $link = "`myreadlink $2`" >/dev/null 2>&1 && echo Skipping $2...) || {
344 1.6 christos echo Updating $2...
345 1.6 christos # We create the symlink in place instead of using mv because:
346 1.6 christos # 1) some systems cannot move symlinks between file systems;
347 1.6 christos # 2) we cannot use mv to replace a symlink-to-directory;
348 1.6 christos # 3) "ln -n" is not in POSIX, therefore it's not portable.
349 1.6 christos # rm+ln is less atomic but this affects compatibility symlinks only.
350 1.6 christos rm -f $2 && ln -sf $link $2 || exit 1
351 1.1 tron }
352 1.1 tron }
353 1.1 tron
354 1.1 tron compare_or_hardlink() {
355 1.1 tron (cmp $1 $2 >/dev/null 2>&1 && echo Skipping $2...) || {
356 1.1 tron echo Updating $2...
357 1.1 tron rm -f $2 || exit 1
358 1.1 tron ln $1 $2 || exit 1
359 1.1 tron }
360 1.1 tron }
361 1.1 tron
362 1.1 tron check_parent() {
363 1.1 tron for path
364 1.1 tron do
365 1.1 tron dir=`echo $path|sed -e 's/[/][/]*[^/]*$//' -e 's/^$/\//'`
366 1.1 tron test -d $dir || mkdir -p $dir || exit 1
367 1.1 tron done
368 1.1 tron }
369 1.1 tron
370 1.1 tron # How to supress newlines in echo.
371 1.1 tron
372 1.1 tron case `echo -n` in
373 1.1 tron "") n=-n; c=;;
374 1.1 tron *) n=; c='\c';;
375 1.1 tron esac
376 1.1 tron
377 1.1 tron # Prompts.
378 1.1 tron
379 1.1 tron install_root_prompt="the prefix for installed file names. Specify
380 1.1 tron this ONLY if you are building ready-to-install packages for
381 1.3 tron distribution to OTHER machines. See PACKAGE_README for instructions."
382 1.1 tron
383 1.1 tron tempdir_prompt="a directory for scratch files while installing
384 1.1 tron Postfix. You must have write permission in this directory."
385 1.1 tron
386 1.1 tron config_directory_prompt="the final destination directory for
387 1.1 tron installed Postfix configuration files."
388 1.1 tron
389 1.1 tron data_directory_prompt="the final destination directory for
390 1.1 tron Postfix-writable data files such as caches or random numbers. This
391 1.1 tron directory should not be shared with non-Postfix software."
392 1.1 tron
393 1.1 tron daemon_directory_prompt="the final destination directory for
394 1.1 tron installed Postfix daemon programs. This directory should not be
395 1.1 tron in the command search path of any users."
396 1.1 tron
397 1.1 tron command_directory_prompt="the final destination directory for
398 1.1 tron installed Postfix administrative commands. This directory should
399 1.1 tron be in the command search path of adminstrative users."
400 1.1 tron
401 1.1 tron queue_directory_prompt="the final destination directory for Postfix
402 1.1 tron queues."
403 1.1 tron
404 1.1 tron sendmail_path_prompt="the final destination pathname for the
405 1.1 tron installed Postfix sendmail command. This is the Sendmail-compatible
406 1.1 tron mail posting interface."
407 1.1 tron
408 1.1 tron newaliases_path_prompt="the final destination pathname for the
409 1.1 tron installed Postfix newaliases command. This is the Sendmail-compatible
410 1.1 tron command to build alias databases for the Postfix local delivery
411 1.1 tron agent."
412 1.1 tron
413 1.1 tron mailq_path_prompt="the final destination pathname for the installed
414 1.1 tron Postfix mailq command. This is the Sendmail-compatible mail queue
415 1.1 tron listing command."
416 1.1 tron
417 1.1 tron mail_owner_prompt="the owner of the Postfix queue. Specify an
418 1.1 tron account with numerical user ID and group ID values that are not
419 1.1 tron used by any other accounts on the system."
420 1.1 tron
421 1.1 tron setgid_group_prompt="the group for mail submission and for queue
422 1.1 tron management commands. Specify a group name with a numerical group
423 1.1 tron ID that is not shared with other accounts, not even with the Postfix
424 1.1 tron mail_owner account. You can no longer specify \"no\" here."
425 1.1 tron
426 1.5 tron manpage_directory_prompt="the final destination directory for the
427 1.5 tron Postfix on-line manual pages. You can no longer specify \"no\"
428 1.5 tron here."
429 1.1 tron
430 1.5 tron readme_directory_prompt="the final destination directory for the Postfix
431 1.1 tron README files. Specify \"no\" if you do not want to install these files."
432 1.1 tron
433 1.5 tron html_directory_prompt="the final destination directory for the Postfix
434 1.1 tron HTML files. Specify \"no\" if you do not want to install these files."
435 1.1 tron
436 1.6 christos shlib_directory_prompt="the final destination directory for Postfix
437 1.6 christos shared-library files."
438 1.6 christos
439 1.6 christos meta_directory_prompt="the final destination directory for
440 1.6 christos non-executable files that are shared among multiple Postfix instances,
441 1.6 christos such as postfix-files, dynamicmaps.cf, as well as the multi-instance
442 1.6 christos template files main.cf.proto and master.cf.proto."
443 1.6 christos
444 1.1 tron # Default settings, just to get started.
445 1.1 tron
446 1.1 tron : ${install_root=/}
447 1.1 tron : ${tempdir=`pwd`}
448 1.4 tron : ${config_directory=`bin/postconf -c conf -h -d config_directory`}
449 1.1 tron
450 1.1 tron # Find out the location of installed configuration files.
451 1.1 tron
452 1.1 tron test -z "$non_interactive" && for name in install_root tempdir config_directory
453 1.1 tron do
454 1.1 tron while :
455 1.1 tron do
456 1.1 tron echo
457 1.1 tron eval echo Please specify \$${name}_prompt | ${FMT}
458 1.1 tron eval echo \$n "$name: [\$$name]\ \$c"
459 1.1 tron read ans
460 1.1 tron case $ans in
461 1.1 tron "") break;;
462 1.1 tron *) case $ans in
463 1.1 tron /*) eval $name=$ans; break;;
464 1.1 tron *) echo; echo $0: Error: $name should be an absolute path name. 1>&2;;
465 1.1 tron esac;;
466 1.1 tron esac
467 1.1 tron done
468 1.1 tron done
469 1.1 tron
470 1.1 tron # In case some systems special-case pathnames beginning with //.
471 1.1 tron
472 1.1 tron case $install_root in
473 1.1 tron /) install_root=
474 1.1 tron esac
475 1.1 tron
476 1.1 tron test -z "$need_install_root" || test -n "$install_root" || {
477 1.1 tron echo $0: Error: invalid package root directory: \"install_root=/\" 1>&2
478 1.1 tron exit 1
479 1.1 tron }
480 1.1 tron
481 1.1 tron CONFIG_DIRECTORY=$install_root$config_directory
482 1.1 tron
483 1.1 tron # If a parameter is not set via the command line or environment,
484 1.1 tron # try to use settings from installed configuration files.
485 1.1 tron
486 1.1 tron # Extract parameter settings from the obsolete install.cf file, as
487 1.1 tron # a transitional aid.
488 1.1 tron
489 1.1 tron grep setgid_group $CONFIG_DIRECTORY/main.cf >/dev/null 2>&1 || {
490 1.1 tron test -f $CONFIG_DIRECTORY/install.cf && {
491 1.1 tron for name in sendmail_path newaliases_path mailq_path setgid manpages
492 1.1 tron do
493 1.1 tron eval junk=\$$name
494 1.1 tron case "$junk" in
495 1.1 tron "") eval unset $name;;
496 1.1 tron esac
497 1.1 tron eval : \${$name="\`. $CONFIG_DIRECTORY/install.cf; echo \$$name\`"} \
498 1.1 tron || exit 1
499 1.1 tron done
500 1.1 tron : ${setgid_group=$setgid}
501 1.1 tron : ${manpage_directory=$manpages}
502 1.1 tron }
503 1.1 tron }
504 1.1 tron
505 1.1 tron # Extract parameter settings from the installed main.cf file.
506 1.1 tron
507 1.1 tron test -f $CONFIG_DIRECTORY/main.cf && {
508 1.1 tron for name in $CONFIG_PARAMS sample_directory
509 1.1 tron do
510 1.1 tron eval junk=\$$name
511 1.1 tron case "$junk" in
512 1.1 tron "") eval unset $name;;
513 1.1 tron esac
514 1.6 christos eval : \${$name=\`bin/postconf -c $CONFIG_DIRECTORY -hx $name\`} ||
515 1.1 tron exit 1
516 1.1 tron done
517 1.1 tron }
518 1.1 tron
519 1.1 tron # Use built-in defaults as the final source of parameter settings.
520 1.1 tron
521 1.1 tron for name in $CONFIG_PARAMS sample_directory
522 1.1 tron do
523 1.1 tron eval junk=\$$name
524 1.1 tron case "$junk" in
525 1.1 tron "") eval unset $name;;
526 1.1 tron esac
527 1.6 christos eval : \${$name=\`bin/postconf -c conf -d -hx $name\`} || exit 1
528 1.1 tron done
529 1.1 tron
530 1.1 tron # Override settings manually.
531 1.1 tron
532 1.1 tron test -z "$non_interactive" && for name in $CONFIG_PARAMS
533 1.1 tron do
534 1.1 tron while :
535 1.1 tron do
536 1.1 tron echo
537 1.1 tron eval echo Please specify \$${name}_prompt | ${FMT}
538 1.1 tron eval echo \$n "$name: [\$$name]\ \$c"
539 1.1 tron read ans
540 1.1 tron case $ans in
541 1.1 tron "") break;;
542 1.1 tron *) eval $name=$ans; break;;
543 1.1 tron esac
544 1.1 tron done
545 1.1 tron done
546 1.1 tron
547 1.1 tron # Sanity checks
548 1.1 tron
549 1.1 tron case "$setgid_group" in
550 1.1 tron no) (echo $0: Error: the setgid_group parameter no longer accepts
551 1.1 tron echo \"no\" values. Try again with \"setgid_group=groupname\" on the
552 1.1 tron echo command line or execute \"make install\" and specify setgid_group
553 1.1 tron echo interactively.) | ${FMT} 1>&2
554 1.1 tron exit 1;;
555 1.1 tron esac
556 1.1 tron
557 1.1 tron case "$manpage_directory" in
558 1.1 tron no) (echo $0: Error: the manpage_directory parameter no longer accepts
559 1.1 tron echo \"no\" values. Try again with \"manpage_directory=/path/name\"
560 1.1 tron echo on the command line or execute \"make install\" and specify
561 1.1 tron echo manpage_directory interactively.) | ${FMT} 1>&2
562 1.1 tron exit 1;;
563 1.1 tron esac
564 1.1 tron
565 1.6 christos for path in "$html_directory" "$readme_directory" "$shlib_directory"
566 1.1 tron do
567 1.1 tron case "$path" in
568 1.1 tron /*) ;;
569 1.1 tron no) ;;
570 1.1 tron *) echo $0: Error: \"$path\" should be \"no\" or an absolute path name. 1>&2
571 1.1 tron exit 1;;
572 1.1 tron esac
573 1.1 tron done
574 1.1 tron
575 1.1 tron for path in "$daemon_directory" "$data_directory" "$command_directory" "$queue_directory" \
576 1.6 christos "$sendmail_path" "$newaliases_path" "$mailq_path" "$manpage_directory" \
577 1.6 christos "$meta_directory"
578 1.1 tron do
579 1.1 tron case "$path" in
580 1.1 tron /*) ;;
581 1.1 tron *) echo $0: Error: \"$path\" should be an absolute path name. 1>&2; exit 1;;
582 1.1 tron esac
583 1.1 tron done
584 1.1 tron
585 1.1 tron for path in mailq_path newaliases_path sendmail_path
586 1.1 tron do
587 1.1 tron eval test -d $install_root\$$path && {
588 1.1 tron echo $0: Error: \"$path\" specifies a directory. 1>&2
589 1.1 tron exit 1
590 1.1 tron }
591 1.1 tron done
592 1.1 tron
593 1.1 tron for path in command_directory config_directory daemon_directory data_directory \
594 1.6 christos manpage_directory queue_directory shlib_directory html_directory \
595 1.6 christos readme_directory meta_directory
596 1.1 tron do
597 1.6 christos case "$path" in
598 1.6 christos no) ;;
599 1.6 christos *) eval test -f $install_root\$$path && {
600 1.1 tron echo $0: Error: \"$path\" specifies a regular file. 1>&2
601 1.1 tron exit 1
602 1.6 christos };;
603 1.6 christos esac
604 1.6 christos done
605 1.6 christos
606 1.6 christos # Don't allow space or tab in parameter settings.
607 1.6 christos
608 1.6 christos for name in $CONFIG_PARAMS sample_directory
609 1.6 christos do
610 1.6 christos eval junk=\$$name
611 1.6 christos case "$junk" in
612 1.6 christos *"[ ]"*) echo "$0: Error: $name value contains whitespace: '$junk'" 1>&2
613 1.6 christos exit 1;;
614 1.6 christos esac
615 1.1 tron done
616 1.1 tron
617 1.1 tron test -d $tempdir || mkdir -p $tempdir || exit 1
618 1.1 tron
619 1.1 tron trap "rm -f $tempdir/junk" 0 1 2 3 15
620 1.1 tron
621 1.1 tron ( rm -f $tempdir/junk && touch $tempdir/junk ) || {
622 1.1 tron echo $0: Error: you have no write permission to $tempdir. 1>&2
623 1.1 tron echo Specify an alternative directory for scratch files. 1>&2
624 1.1 tron exit 1
625 1.1 tron }
626 1.1 tron
627 1.1 tron test -z "$install_root" && {
628 1.1 tron
629 1.1 tron chown root $tempdir/junk >/dev/null 2>&1 || {
630 1.1 tron echo Error: you have no permission to change file ownership. 1>&2
631 1.1 tron exit 1
632 1.1 tron }
633 1.1 tron
634 1.1 tron chown "$mail_owner" $tempdir/junk >/dev/null 2>&1 || {
635 1.1 tron echo $0: Error: \"$mail_owner\" needs an entry in the passwd file. 1>&2
636 1.1 tron echo Remember, \"$mail_owner\" needs a dedicated user and group id. 1>&2
637 1.1 tron exit 1
638 1.1 tron }
639 1.1 tron
640 1.1 tron chgrp "$setgid_group" $tempdir/junk >/dev/null 2>&1 || {
641 1.1 tron echo $0: Error: \"$setgid_group\" needs an entry in the group file. 1>&2
642 1.1 tron echo Remember, \"$setgid_group\" needs a dedicated group id. 1>&2
643 1.1 tron exit 1
644 1.1 tron }
645 1.1 tron
646 1.1 tron }
647 1.1 tron
648 1.1 tron rm -f $tempdir/junk || exit 1
649 1.1 tron
650 1.1 tron trap 0 1 2 3 15
651 1.1 tron
652 1.1 tron # Avoid clumsiness.
653 1.1 tron
654 1.1 tron DAEMON_DIRECTORY=$install_root$daemon_directory
655 1.1 tron COMMAND_DIRECTORY=$install_root$command_directory
656 1.1 tron QUEUE_DIRECTORY=$install_root$queue_directory
657 1.1 tron SENDMAIL_PATH=$install_root$sendmail_path
658 1.1 tron HTML_DIRECTORY=$install_root$html_directory
659 1.1 tron MANPAGE_DIRECTORY=$install_root$manpage_directory
660 1.1 tron README_DIRECTORY=$install_root$readme_directory
661 1.6 christos SHLIB_DIRECTORY=$install_root$shlib_directory
662 1.6 christos META_DIRECTORY=$install_root$meta_directory
663 1.1 tron
664 1.1 tron # Avoid repeated tests for existence of these; default permissions suffice.
665 1.1 tron
666 1.1 tron test -d $DAEMON_DIRECTORY || mkdir -p $DAEMON_DIRECTORY || exit 1
667 1.1 tron test -d $COMMAND_DIRECTORY || mkdir -p $COMMAND_DIRECTORY || exit 1
668 1.6 christos test -d $QUEUE_DIRECTORY || mkdir -p $QUEUE_DIRECTORY || exit 1
669 1.6 christos test "$shlib_directory" = "no" -o -d $SHLIB_DIRECTORY ||
670 1.6 christos mkdir -p $SHLIB_DIRECTORY || exit 1
671 1.1 tron test "$html_directory" = "no" -o -d $HTML_DIRECTORY ||
672 1.1 tron mkdir -p $HTML_DIRECTORY || exit 1
673 1.1 tron test "$readme_directory" = "no" -o -d $README_DIRECTORY ||
674 1.1 tron mkdir -p $README_DIRECTORY || exit 1
675 1.6 christos test -d $META_DIRECTORY || mkdir -p $META_DIRECTORY || exit 1
676 1.1 tron
677 1.1 tron # Upgrade or first-time installation?
678 1.1 tron
679 1.1 tron if [ -f $CONFIG_DIRECTORY/main.cf ]
680 1.1 tron then
681 1.1 tron post_install_options="upgrade-source"
682 1.1 tron else
683 1.1 tron post_install_options="first-install"
684 1.1 tron fi
685 1.1 tron
686 1.1 tron # Install files, using information from the postfix-files file.
687 1.1 tron
688 1.6 christos exec < meta/postfix-files || exit 1
689 1.1 tron while IFS=: read path type owner group mode flags junk
690 1.1 tron do
691 1.1 tron IFS="$BACKUP_IFS"
692 1.1 tron
693 1.1 tron # Skip comments.
694 1.1 tron
695 1.1 tron case $path in
696 1.1 tron [$]*) ;;
697 1.1 tron *) continue;;
698 1.1 tron esac
699 1.1 tron
700 1.1 tron # Skip over files that ought to be removed.
701 1.1 tron # Leave it up to post-install to report them to the user.
702 1.1 tron
703 1.1 tron case $flags in
704 1.1 tron *o*) continue
705 1.1 tron esac
706 1.1 tron
707 1.1 tron # Skip over files that must be preserved.
708 1.1 tron
709 1.1 tron case $flags in
710 1.1 tron *p*) eval test -f $install_root$path && {
711 1.1 tron eval echo "Skipping $install_root$path..."
712 1.1 tron continue
713 1.1 tron };;
714 1.1 tron esac
715 1.1 tron
716 1.1 tron # Save source path before it is clobbered.
717 1.1 tron
718 1.1 tron case $type in
719 1.1 tron [hl]) eval source=$owner;;
720 1.1 tron esac
721 1.1 tron
722 1.1 tron # If installing from source code, apply special permissions or ownership.
723 1.1 tron # If building a package, don't apply special permissions or ownership.
724 1.1 tron
725 1.1 tron case $install_root in
726 1.1 tron "") case $owner in
727 1.1 tron [$]*) eval owner=$owner;;
728 1.1 tron root) owner=;;
729 1.1 tron esac
730 1.1 tron case $group in
731 1.1 tron [$]*) eval group=$group;;
732 1.1 tron -) group=;;
733 1.1 tron esac;;
734 1.1 tron *) case $mode in
735 1.1 tron [1-7]755) mode=755;;
736 1.1 tron esac
737 1.1 tron owner=
738 1.1 tron group=;;
739 1.1 tron esac
740 1.1 tron
741 1.1 tron
742 1.1 tron case $type in
743 1.1 tron
744 1.1 tron # Create/update directory.
745 1.1 tron
746 1.1 tron d) eval path=$install_root$path
747 1.1 tron test "$path" = "${install_root}no" -o -d $path || {
748 1.1 tron mkdir -p $path || exit 1
749 1.1 tron test -z "$owner" || chown $owner $path || exit 1
750 1.1 tron test -z "$group" || chgrp $group $path || exit 1
751 1.1 tron chmod $mode $path || exit 1
752 1.1 tron }
753 1.1 tron continue;;
754 1.1 tron
755 1.1 tron # Create/update regular file.
756 1.1 tron
757 1.1 tron f) echo $path | (IFS=/ read prefix file; IFS="$BACKUP_IFS"
758 1.1 tron case $prefix in
759 1.6 christos '$shlib_directory')
760 1.6 christos compare_or_replace $mode "$owner" "$group" lib/$file \
761 1.6 christos $SHLIB_DIRECTORY/$file || exit 1;;
762 1.6 christos '$meta_directory')
763 1.6 christos compare_or_replace $mode "$owner" "$group" meta/$file \
764 1.6 christos $META_DIRECTORY/$file || exit 1;;
765 1.1 tron '$daemon_directory')
766 1.1 tron compare_or_replace $mode "$owner" "$group" libexec/$file \
767 1.1 tron $DAEMON_DIRECTORY/$file || exit 1;;
768 1.1 tron '$command_directory')
769 1.1 tron compare_or_replace $mode "$owner" "$group" bin/$file \
770 1.1 tron $COMMAND_DIRECTORY/$file || exit 1;;
771 1.1 tron '$config_directory')
772 1.1 tron compare_or_replace $mode "$owner" "$group" conf/$file \
773 1.1 tron $CONFIG_DIRECTORY/$file || exit 1;;
774 1.1 tron '$sendmail_path')
775 1.1 tron check_parent $SENDMAIL_PATH || exit 1
776 1.1 tron compare_or_replace $mode "$owner" "$group" bin/sendmail \
777 1.1 tron $SENDMAIL_PATH || exit 1;;
778 1.1 tron '$html_directory')
779 1.1 tron test "$html_directory" = "no" ||
780 1.1 tron compare_or_replace $mode "$owner" "$group" html/$file \
781 1.1 tron $HTML_DIRECTORY/$file || exit 1;;
782 1.1 tron '$manpage_directory')
783 1.1 tron check_parent $MANPAGE_DIRECTORY/$file || exit 1
784 1.1 tron compare_or_replace $mode "$owner" "$group" man/$file \
785 1.1 tron $MANPAGE_DIRECTORY/$file || exit 1;;
786 1.1 tron '$readme_directory')
787 1.1 tron test "$readme_directory" = "no" ||
788 1.1 tron compare_or_replace $mode "$owner" "$group" README_FILES/$file \
789 1.1 tron $README_DIRECTORY/$file || exit 1;;
790 1.6 christos *) echo $0: Error: unknown entry $path in meta/postfix-files 1>&2
791 1.1 tron exit 1;;
792 1.1 tron esac) || exit 1
793 1.1 tron continue;;
794 1.1 tron
795 1.1 tron # Hard link. Skip files that are not installed.
796 1.1 tron
797 1.1 tron h) eval echo $path | (
798 1.1 tron IFS=/ read prefix file; IFS="$BACKUP_IFS"
799 1.1 tron test "$prefix" = "no" || (
800 1.1 tron eval dest_path=$install_root$path
801 1.1 tron check_parent $dest_path || exit 1
802 1.1 tron eval source_path=$install_root$source
803 1.1 tron compare_or_hardlink $source_path $dest_path || exit 1
804 1.1 tron )
805 1.1 tron ) || exit 1
806 1.1 tron continue;;
807 1.1 tron
808 1.1 tron # Symbolic link. Skip files that are not installed.
809 1.1 tron
810 1.1 tron l) eval echo $path | (
811 1.1 tron IFS=/ read prefix file; IFS="$BACKUP_IFS"
812 1.1 tron test "$prefix" = "no" || (
813 1.1 tron eval dest_path=$install_root$path
814 1.1 tron check_parent $dest_path || exit 1
815 1.1 tron eval source_path=$install_root$source
816 1.1 tron compare_or_symlink $source_path $dest_path || exit 1
817 1.1 tron )
818 1.1 tron ) || exit 1
819 1.1 tron continue;;
820 1.1 tron
821 1.6 christos *) echo $0: Error: unknown type $type for $path in meta/postfix-files 1>&2
822 1.1 tron exit 1;;
823 1.1 tron esac
824 1.1 tron
825 1.6 christos done
826 1.6 christos # More (solaris9) shell brain damage!
827 1.6 christos IFS="$BACKUP_IFS"
828 1.1 tron
829 1.1 tron # Save the installation parameters to main.cf even when they haven't
830 1.1 tron # changed from their current default. Defaults can change between
831 1.1 tron # Postfix releases, and software should not suddenly be installed in
832 1.1 tron # the wrong place when Postfix is being upgraded.
833 1.1 tron
834 1.6 christos case "$mail_version" in
835 1.6 christos "") mail_version="`bin/postconf -dhx mail_version`" || exit 1
836 1.6 christos esac
837 1.6 christos
838 1.6 christos # Undo MAIL_VERSION expansion at the end of a parameter value. If
839 1.6 christos # someone really wants the expanded mail version in main.cf, then
840 1.6 christos # we're sorry.
841 1.6 christos
842 1.6 christos for name in $CONFIG_PARAMS sample_directory
843 1.6 christos do
844 1.6 christos eval junk=\$$name
845 1.6 christos case "$junk" in
846 1.6 christos *"$mail_version"*)
847 1.6 christos case "$pattern" in
848 1.6 christos "") pattern=`echo "$mail_version" | sed 's/\./\\\\./g'` || exit 1
849 1.6 christos esac
850 1.6 christos val=`echo "$junk" | sed "s/$pattern"'$/${mail_version}/g'` || exit 1
851 1.6 christos eval ${name}='"$val"'
852 1.6 christos esac
853 1.6 christos done
854 1.6 christos
855 1.1 tron bin/postconf -c $CONFIG_DIRECTORY -e \
856 1.1 tron "daemon_directory = $daemon_directory" \
857 1.1 tron "data_directory = $data_directory" \
858 1.1 tron "command_directory = $command_directory" \
859 1.1 tron "queue_directory = $queue_directory" \
860 1.1 tron "mail_owner = $mail_owner" \
861 1.1 tron "setgid_group = $setgid_group" \
862 1.1 tron "sendmail_path = $sendmail_path" \
863 1.1 tron "mailq_path = $mailq_path" \
864 1.1 tron "newaliases_path = $newaliases_path" \
865 1.1 tron "html_directory = $html_directory" \
866 1.1 tron "manpage_directory = $manpage_directory" \
867 1.1 tron "sample_directory = $sample_directory" \
868 1.1 tron "readme_directory = $readme_directory" \
869 1.6 christos "shlib_directory = $shlib_directory" \
870 1.6 christos "meta_directory = $meta_directory" \
871 1.1 tron || exit 1
872 1.1 tron
873 1.1 tron # If Postfix is being installed locally from source code, do the
874 1.1 tron # post-install processing now.
875 1.1 tron
876 1.6 christos # The unexpansion above may have side effects on exported variables.
877 1.6 christos # It does not matter because bin/postfix below will override them.
878 1.6 christos
879 1.1 tron test -n "$install_root" || {
880 1.1 tron bin/postfix post-install $post_install_options || exit 1
881 1.1 tron }
882