Home | History | Annotate | Line # | Download | only in dist
postfix-install revision 1.5
      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.5  tron #	The final 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.5  tron #	The final 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.5  tron #	The final destination directory for the Postfix sample configuration
    145  1.5  tron #	files. 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.5  tron #	The final 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.5  tron # This script uses outputs from Postfix and non-Postfix commands.
    178  1.5  tron # Override all LC_* settings and LANG for robustness.
    179  1.5  tron LC_ALL=C; export LC_ALL
    180  1.5  tron 
    181  1.1  tron USAGE="Usage: $0 [name=value] [option]
    182  1.1  tron     -non-interactive        Do not ask for installation parameters.
    183  1.1  tron     -package                Build a ready-to-install package.
    184  1.1  tron     name=value              Specify an installation parameter".
    185  1.1  tron 
    186  1.1  tron # Process command-line options and parameter settings. Work around
    187  1.1  tron # brain damaged shells. "IFS=value command" should not make the
    188  1.1  tron # IFS=value setting permanent. But some broken standard allows it.
    189  1.1  tron 
    190  1.1  tron for arg
    191  1.1  tron do
    192  1.1  tron     case $arg in
    193  1.1  tron       *=*) IFS= eval $arg; IFS="$BACKUP_IFS";;
    194  1.1  tron -non-int*) non_interactive=1;;
    195  1.1  tron  -package) need_install_root=install_root;;
    196  1.1  tron         *) echo "$0: Error: $USAGE" 1>&2; exit 1;;
    197  1.1  tron     esac
    198  1.1  tron     shift
    199  1.1  tron done
    200  1.1  tron 
    201  1.1  tron # Sanity checks.
    202  1.1  tron 
    203  1.1  tron test -z "$non_interactive" -a ! -t 0 && {
    204  1.1  tron     echo $0: Error: for non-interactive use, run: \"$0 -non-interactive\" 1>&2
    205  1.1  tron     exit 1
    206  1.1  tron }
    207  1.1  tron 
    208  1.1  tron test -x bin/postconf || {
    209  1.1  tron     echo $0: Error: no bin/postconf file. Did you forget to run \"make\"? 1>&2
    210  1.1  tron     exit 1
    211  1.1  tron }
    212  1.1  tron 
    213  1.1  tron case `uname -s` in
    214  1.1  tron HP-UX*) FMT=cat;;
    215  1.1  tron      *) FMT=fmt;;
    216  1.1  tron esac
    217  1.1  tron 
    218  1.1  tron # Disclaimer.
    219  1.1  tron 
    220  1.1  tron test -z "$non_interactive" && cat <<EOF | ${FMT}
    221  1.1  tron 
    222  1.1  tron     Warning: if you use this script to install Postfix locally,
    223  1.1  tron     this script will replace existing sendmail or Postfix programs.
    224  1.1  tron     Make backups if you want to be able to recover.
    225  1.1  tron 
    226  1.1  tron     Before installing files, this script prompts you for some
    227  1.1  tron     definitions.  Most definitions will be remembered, so you have
    228  1.1  tron     to specify them only once. All definitions should have a
    229  1.1  tron     reasonable default value.
    230  1.1  tron EOF
    231  1.1  tron 
    232  1.1  tron # The following shell functions replace files/symlinks while minimizing
    233  1.1  tron # the time that a file does not exist, and avoid copying over files
    234  1.1  tron # in order to not disturb running programs. That is certainly desirable
    235  1.1  tron # when upgrading Postfix on a live machine. It also avoids surprises
    236  1.1  tron # when building a Postfix package for distribution to other systems.
    237  1.1  tron 
    238  1.1  tron compare_or_replace() {
    239  1.1  tron     mode=$1
    240  1.1  tron     owner=$2
    241  1.1  tron     group=$3
    242  1.1  tron     src=$4
    243  1.1  tron     dst=$5
    244  1.1  tron     (cmp $src $dst >/dev/null 2>&1 && echo Skipping $dst...) || {
    245  1.1  tron 	echo Updating $dst...
    246  1.1  tron 	rm -f $tempdir/junk || exit 1
    247  1.1  tron 	cp $src $tempdir/junk || exit 1
    248  1.1  tron 	mv -f $tempdir/junk $dst || exit 1
    249  1.1  tron 	test -z "$owner" || chown $owner $dst || exit 1
    250  1.1  tron 	test -z "$group" || chgrp $group $dst || exit 1
    251  1.1  tron 	chmod $mode $dst || exit 1
    252  1.1  tron     }
    253  1.1  tron }
    254  1.1  tron 
    255  1.1  tron compare_or_symlink() {
    256  1.1  tron     (cmp $1 $2 >/dev/null 2>&1 && echo Skipping $2...) || {
    257  1.1  tron 	echo Updating $2...
    258  1.1  tron 	rm -f $tempdir/junk || exit 1
    259  1.1  tron 	dest=`echo $1 | sed '
    260  1.1  tron 	    s;^'$install_root';;
    261  1.1  tron 	    s;/\./;/;g
    262  1.1  tron 	    s;//*;/;g
    263  1.1  tron 	    s;^/;;
    264  1.1  tron 	'`
    265  1.1  tron 	link=`echo $2 | sed '
    266  1.1  tron 	    s;^'$install_root';;
    267  1.1  tron 	    s;/\./;/;g
    268  1.1  tron 	    s;//*;/;g
    269  1.1  tron 	    s;^/;;
    270  1.1  tron 	    s;/[^/]*$;/;
    271  1.1  tron 	    s;[^/]*/;../;g
    272  1.1  tron 	    s;$;'$dest';
    273  1.1  tron 	'`
    274  1.1  tron 	ln -s $link $tempdir/junk || exit 1
    275  1.1  tron 	mv -f $tempdir/junk $2 || {
    276  1.1  tron 	    echo $0: Error: your mv command has trouble renaming symlinks. 1>&2
    277  1.1  tron 	    echo If you run Linux, upgrade to GNU fileutils-4.0 or better, 1>&2
    278  1.1  tron 	    echo or choose a tempdir that is in the same file system as $2. 1>&2
    279  1.1  tron 	    echo If you run FreeBSD, upgrade to version 5 or better. 1>&2
    280  1.1  tron 	    exit 1
    281  1.1  tron 	}
    282  1.1  tron     }
    283  1.1  tron }
    284  1.1  tron 
    285  1.1  tron compare_or_hardlink() {
    286  1.1  tron     (cmp $1 $2 >/dev/null 2>&1 && echo Skipping $2...) || {
    287  1.1  tron 	echo Updating $2...
    288  1.1  tron 	rm -f $2 || exit 1
    289  1.1  tron 	ln $1 $2 || exit 1
    290  1.1  tron     }
    291  1.1  tron }
    292  1.1  tron 
    293  1.1  tron check_parent() {
    294  1.1  tron     for path
    295  1.1  tron     do
    296  1.1  tron 	dir=`echo $path|sed -e 's/[/][/]*[^/]*$//' -e 's/^$/\//'`
    297  1.1  tron 	test -d $dir || mkdir -p $dir || exit 1
    298  1.1  tron     done
    299  1.1  tron }
    300  1.1  tron 
    301  1.1  tron # How to supress newlines in echo.
    302  1.1  tron 
    303  1.1  tron case `echo -n` in
    304  1.1  tron "") n=-n; c=;;
    305  1.1  tron  *) n=; c='\c';;
    306  1.1  tron esac
    307  1.1  tron 
    308  1.1  tron # Prompts.
    309  1.1  tron 
    310  1.1  tron install_root_prompt="the prefix for installed file names. Specify
    311  1.1  tron this ONLY if you are building ready-to-install packages for
    312  1.3  tron distribution to OTHER machines. See PACKAGE_README for instructions."
    313  1.1  tron 
    314  1.1  tron tempdir_prompt="a directory for scratch files while installing
    315  1.1  tron Postfix.  You must have write permission in this directory."
    316  1.1  tron 
    317  1.1  tron config_directory_prompt="the final destination directory for
    318  1.1  tron installed Postfix configuration files."
    319  1.1  tron 
    320  1.1  tron data_directory_prompt="the final destination directory for
    321  1.1  tron Postfix-writable data files such as caches or random numbers.  This
    322  1.1  tron directory should not be shared with non-Postfix software."
    323  1.1  tron 
    324  1.1  tron daemon_directory_prompt="the final destination directory for
    325  1.1  tron installed Postfix daemon programs.  This directory should not be
    326  1.1  tron in the command search path of any users."
    327  1.1  tron 
    328  1.1  tron command_directory_prompt="the final destination directory for
    329  1.1  tron installed Postfix administrative commands.  This directory should
    330  1.1  tron be in the command search path of adminstrative users."
    331  1.1  tron 
    332  1.1  tron queue_directory_prompt="the final destination directory for Postfix
    333  1.1  tron queues."
    334  1.1  tron 
    335  1.1  tron sendmail_path_prompt="the final destination pathname for the
    336  1.1  tron installed Postfix sendmail command. This is the Sendmail-compatible
    337  1.1  tron mail posting interface."
    338  1.1  tron 
    339  1.1  tron newaliases_path_prompt="the final destination pathname for the
    340  1.1  tron installed Postfix newaliases command.  This is the Sendmail-compatible
    341  1.1  tron command to build alias databases for the Postfix local delivery
    342  1.1  tron agent."
    343  1.1  tron 
    344  1.1  tron mailq_path_prompt="the final destination pathname for the installed
    345  1.1  tron Postfix mailq command.  This is the Sendmail-compatible mail queue
    346  1.1  tron listing command."
    347  1.1  tron 
    348  1.1  tron mail_owner_prompt="the owner of the Postfix queue. Specify an
    349  1.1  tron account with numerical user ID and group ID values that are not
    350  1.1  tron used by any other accounts on the system."
    351  1.1  tron 
    352  1.1  tron setgid_group_prompt="the group for mail submission and for queue
    353  1.1  tron management commands.  Specify a group name with a numerical group
    354  1.1  tron ID that is not shared with other accounts, not even with the Postfix
    355  1.1  tron mail_owner account. You can no longer specify \"no\" here."
    356  1.1  tron 
    357  1.5  tron manpage_directory_prompt="the final destination directory for the
    358  1.5  tron Postfix on-line manual pages. You can no longer specify \"no\"
    359  1.5  tron here."
    360  1.1  tron 
    361  1.5  tron readme_directory_prompt="the final destination directory for the Postfix
    362  1.1  tron README files. Specify \"no\" if you do not want to install these files."
    363  1.1  tron 
    364  1.5  tron html_directory_prompt="the final destination directory for the Postfix
    365  1.1  tron HTML files. Specify \"no\" if you do not want to install these files."
    366  1.1  tron 
    367  1.1  tron # Default settings, just to get started.
    368  1.1  tron 
    369  1.1  tron : ${install_root=/}
    370  1.1  tron : ${tempdir=`pwd`}
    371  1.4  tron : ${config_directory=`bin/postconf -c conf -h -d config_directory`}
    372  1.1  tron 
    373  1.1  tron # Find out the location of installed configuration files.
    374  1.1  tron 
    375  1.1  tron test -z "$non_interactive" && for name in install_root tempdir config_directory
    376  1.1  tron do
    377  1.1  tron     while :
    378  1.1  tron     do
    379  1.1  tron 	echo
    380  1.1  tron 	eval echo Please specify \$${name}_prompt | ${FMT}
    381  1.1  tron 	eval echo \$n "$name: [\$$name]\  \$c"
    382  1.1  tron 	read ans
    383  1.1  tron 	case $ans in
    384  1.1  tron 	"") break;;
    385  1.1  tron 	 *) case $ans in
    386  1.1  tron 	    /*) eval $name=$ans; break;;
    387  1.1  tron 	     *) echo; echo $0: Error: $name should be an absolute path name. 1>&2;;
    388  1.1  tron 	    esac;;
    389  1.1  tron 	esac
    390  1.1  tron     done
    391  1.1  tron done
    392  1.1  tron 
    393  1.1  tron # In case some systems special-case pathnames beginning with //.
    394  1.1  tron 
    395  1.1  tron case $install_root in
    396  1.1  tron /) install_root=
    397  1.1  tron esac
    398  1.1  tron 
    399  1.1  tron test -z "$need_install_root" || test -n "$install_root" || {
    400  1.1  tron     echo $0: Error: invalid package root directory: \"install_root=/\" 1>&2
    401  1.1  tron     exit 1
    402  1.1  tron }
    403  1.1  tron 
    404  1.1  tron CONFIG_DIRECTORY=$install_root$config_directory
    405  1.1  tron 
    406  1.1  tron # If a parameter is not set via the command line or environment,
    407  1.1  tron # try to use settings from installed configuration files.
    408  1.1  tron 
    409  1.1  tron # Extract parameter settings from the obsolete install.cf file, as
    410  1.1  tron # a transitional aid.
    411  1.1  tron 
    412  1.1  tron grep setgid_group $CONFIG_DIRECTORY/main.cf >/dev/null 2>&1 || {
    413  1.1  tron     test -f $CONFIG_DIRECTORY/install.cf && {
    414  1.1  tron 	for name in sendmail_path newaliases_path mailq_path setgid manpages
    415  1.1  tron 	do
    416  1.1  tron 	    eval junk=\$$name
    417  1.1  tron 	    case "$junk" in
    418  1.1  tron 	    "") eval unset $name;;
    419  1.1  tron 	    esac
    420  1.1  tron 	    eval : \${$name="\`. $CONFIG_DIRECTORY/install.cf; echo \$$name\`"} \
    421  1.1  tron 		|| exit 1
    422  1.1  tron 	done
    423  1.1  tron 	: ${setgid_group=$setgid}
    424  1.1  tron 	: ${manpage_directory=$manpages}
    425  1.1  tron     }
    426  1.1  tron }
    427  1.1  tron 
    428  1.1  tron CONFIG_PARAMS="command_directory daemon_directory data_directory \
    429  1.1  tron html_directory mail_owner mailq_path  manpage_directory newaliases_path \
    430  1.1  tron queue_directory readme_directory sendmail_path setgid_group"
    431  1.1  tron 
    432  1.1  tron # Extract parameter settings from the installed main.cf file.
    433  1.1  tron 
    434  1.1  tron test -f $CONFIG_DIRECTORY/main.cf && {
    435  1.1  tron     for name in $CONFIG_PARAMS sample_directory
    436  1.1  tron     do
    437  1.1  tron 	eval junk=\$$name
    438  1.1  tron 	case "$junk" in
    439  1.1  tron 	"") eval unset $name;;
    440  1.1  tron 	esac
    441  1.1  tron 	eval : \${$name=\`bin/postconf -c $CONFIG_DIRECTORY -h $name\`} ||
    442  1.1  tron 	    exit 1
    443  1.1  tron     done
    444  1.1  tron }
    445  1.1  tron 
    446  1.1  tron # Use built-in defaults as the final source of parameter settings.
    447  1.1  tron 
    448  1.1  tron for name in $CONFIG_PARAMS sample_directory
    449  1.1  tron do
    450  1.1  tron     eval junk=\$$name
    451  1.1  tron     case "$junk" in
    452  1.1  tron     "") eval unset $name;;
    453  1.1  tron     esac
    454  1.4  tron     eval : \${$name=\`bin/postconf -c conf -d -h $name\`} || exit 1
    455  1.1  tron done
    456  1.1  tron 
    457  1.1  tron # Override settings manually.
    458  1.1  tron 
    459  1.1  tron test -z "$non_interactive" && for name in $CONFIG_PARAMS
    460  1.1  tron do
    461  1.1  tron     while :
    462  1.1  tron     do
    463  1.1  tron 	echo
    464  1.1  tron 	eval echo Please specify \$${name}_prompt | ${FMT}
    465  1.1  tron 	eval echo \$n "$name: [\$$name]\  \$c"
    466  1.1  tron 	read ans
    467  1.1  tron 	case $ans in
    468  1.1  tron 	"") break;;
    469  1.1  tron 	 *) eval $name=$ans; break;;
    470  1.1  tron 	esac
    471  1.1  tron     done
    472  1.1  tron done
    473  1.1  tron 
    474  1.1  tron # Sanity checks
    475  1.1  tron 
    476  1.1  tron case "$setgid_group" in
    477  1.1  tron  no) (echo $0: Error: the setgid_group parameter no longer accepts 
    478  1.1  tron      echo \"no\" values. Try again with \"setgid_group=groupname\" on the 
    479  1.1  tron      echo command line or execute \"make install\" and specify setgid_group
    480  1.1  tron      echo interactively.) | ${FMT} 1>&2
    481  1.1  tron      exit 1;;
    482  1.1  tron esac
    483  1.1  tron 
    484  1.1  tron case "$manpage_directory" in
    485  1.1  tron  no) (echo $0: Error: the manpage_directory parameter no longer accepts 
    486  1.1  tron      echo \"no\" values.  Try again with \"manpage_directory=/path/name\" 
    487  1.1  tron      echo on the command line or execute \"make install\" and specify
    488  1.1  tron      echo manpage_directory interactively.) | ${FMT} 1>&2
    489  1.1  tron      exit 1;;
    490  1.1  tron esac
    491  1.1  tron 
    492  1.1  tron for path in "$html_directory" "$readme_directory"
    493  1.1  tron do
    494  1.1  tron    case "$path" in
    495  1.1  tron    /*) ;;
    496  1.1  tron    no) ;;
    497  1.1  tron     *) echo $0: Error: \"$path\" should be \"no\" or an absolute path name. 1>&2
    498  1.1  tron        exit 1;;
    499  1.1  tron    esac
    500  1.1  tron done
    501  1.1  tron 
    502  1.1  tron for path in "$daemon_directory" "$data_directory" "$command_directory" "$queue_directory" \
    503  1.1  tron     "$sendmail_path" "$newaliases_path" "$mailq_path" "$manpage_directory"
    504  1.1  tron do
    505  1.1  tron    case "$path" in
    506  1.1  tron    /*) ;;
    507  1.1  tron     *) echo $0: Error: \"$path\" should be an absolute path name. 1>&2; exit 1;;
    508  1.1  tron    esac
    509  1.1  tron done
    510  1.1  tron 
    511  1.1  tron for path in mailq_path newaliases_path sendmail_path
    512  1.1  tron do
    513  1.1  tron     eval test -d $install_root\$$path && {
    514  1.1  tron 	echo $0: Error: \"$path\" specifies a directory. 1>&2
    515  1.1  tron 	exit 1
    516  1.1  tron     }
    517  1.1  tron done
    518  1.1  tron 
    519  1.1  tron for path in command_directory config_directory daemon_directory data_directory \
    520  1.1  tron     manpage_directory queue_directory html_directory readme_directory
    521  1.1  tron do
    522  1.1  tron     eval test -f $install_root\$$path && {
    523  1.1  tron 	echo $0: Error: \"$path\" specifies a regular file. 1>&2
    524  1.1  tron 	exit 1
    525  1.1  tron     }
    526  1.1  tron done
    527  1.1  tron 
    528  1.1  tron test -d $tempdir || mkdir -p $tempdir || exit 1
    529  1.1  tron 
    530  1.1  tron trap "rm -f $tempdir/junk" 0 1 2 3 15
    531  1.1  tron 
    532  1.1  tron ( rm -f $tempdir/junk && touch $tempdir/junk ) || {
    533  1.1  tron     echo $0: Error: you have no write permission to $tempdir. 1>&2
    534  1.1  tron     echo Specify an alternative directory for scratch files. 1>&2
    535  1.1  tron     exit 1
    536  1.1  tron }
    537  1.1  tron 
    538  1.1  tron test -z "$install_root" && {
    539  1.1  tron 
    540  1.1  tron     chown root $tempdir/junk >/dev/null 2>&1 || {
    541  1.1  tron 	echo Error: you have no permission to change file ownership. 1>&2
    542  1.1  tron 	exit 1
    543  1.1  tron     }
    544  1.1  tron 
    545  1.1  tron     chown "$mail_owner" $tempdir/junk >/dev/null 2>&1 || {
    546  1.1  tron 	echo $0: Error: \"$mail_owner\" needs an entry in the passwd file. 1>&2
    547  1.1  tron 	echo Remember, \"$mail_owner\" needs a dedicated user and group id. 1>&2
    548  1.1  tron 	exit 1
    549  1.1  tron     }
    550  1.1  tron 
    551  1.1  tron     chgrp "$setgid_group" $tempdir/junk >/dev/null 2>&1 || {
    552  1.1  tron 	echo $0: Error: \"$setgid_group\" needs an entry in the group file. 1>&2
    553  1.1  tron 	echo Remember, \"$setgid_group\" needs a dedicated group id. 1>&2
    554  1.1  tron 	exit 1
    555  1.1  tron     }
    556  1.1  tron 
    557  1.1  tron }
    558  1.1  tron 
    559  1.1  tron rm -f $tempdir/junk || exit 1
    560  1.1  tron 
    561  1.1  tron trap 0 1 2 3 15
    562  1.1  tron 
    563  1.1  tron # Avoid clumsiness.
    564  1.1  tron 
    565  1.1  tron DAEMON_DIRECTORY=$install_root$daemon_directory
    566  1.1  tron COMMAND_DIRECTORY=$install_root$command_directory
    567  1.1  tron QUEUE_DIRECTORY=$install_root$queue_directory
    568  1.1  tron SENDMAIL_PATH=$install_root$sendmail_path
    569  1.1  tron HTML_DIRECTORY=$install_root$html_directory
    570  1.1  tron MANPAGE_DIRECTORY=$install_root$manpage_directory
    571  1.1  tron README_DIRECTORY=$install_root$readme_directory
    572  1.1  tron 
    573  1.1  tron # Avoid repeated tests for existence of these; default permissions suffice.
    574  1.1  tron 
    575  1.1  tron test -d $DAEMON_DIRECTORY || mkdir -p $DAEMON_DIRECTORY || exit 1
    576  1.1  tron test -d $COMMAND_DIRECTORY || mkdir -p $COMMAND_DIRECTORY || exit 1
    577  1.1  tron test -d $COMMAND_DIRECTORY || mkdir -p $COMMAND_DIRECTORY || exit 1
    578  1.1  tron test "$html_directory" = "no" -o -d $HTML_DIRECTORY || 
    579  1.1  tron 	mkdir -p $HTML_DIRECTORY || exit 1
    580  1.1  tron test "$readme_directory" = "no" -o -d $README_DIRECTORY || 
    581  1.1  tron 	mkdir -p $README_DIRECTORY || exit 1
    582  1.1  tron 
    583  1.1  tron # Upgrade or first-time installation?
    584  1.1  tron 
    585  1.1  tron if [ -f $CONFIG_DIRECTORY/main.cf ]
    586  1.1  tron then
    587  1.1  tron     post_install_options="upgrade-source"
    588  1.1  tron else
    589  1.1  tron     post_install_options="first-install"
    590  1.1  tron fi
    591  1.1  tron 
    592  1.1  tron # Install files, using information from the postfix-files file.
    593  1.1  tron 
    594  1.1  tron exec < libexec/postfix-files || exit 1
    595  1.1  tron while IFS=: read path type owner group mode flags junk
    596  1.1  tron do
    597  1.1  tron     IFS="$BACKUP_IFS"
    598  1.1  tron 
    599  1.1  tron     # Skip comments.
    600  1.1  tron 
    601  1.1  tron     case $path in
    602  1.1  tron     [$]*) ;;
    603  1.1  tron        *) continue;;
    604  1.1  tron     esac
    605  1.1  tron 
    606  1.1  tron     # Skip over files that ought to be removed.
    607  1.1  tron     # Leave it up to post-install to report them to the user.
    608  1.1  tron 
    609  1.1  tron     case $flags in
    610  1.1  tron     *o*) continue
    611  1.1  tron     esac
    612  1.1  tron 
    613  1.1  tron     # Skip over files that must be preserved.
    614  1.1  tron 
    615  1.1  tron     case $flags in
    616  1.1  tron     *p*) eval test -f $install_root$path && {
    617  1.1  tron 	    eval echo "Skipping $install_root$path..."
    618  1.1  tron 	    continue
    619  1.1  tron 	 };;
    620  1.1  tron     esac
    621  1.1  tron 
    622  1.1  tron     # Save source path before it is clobbered.
    623  1.1  tron 
    624  1.1  tron     case $type in
    625  1.1  tron     [hl]) eval source=$owner;;
    626  1.1  tron     esac
    627  1.1  tron 
    628  1.1  tron     # If installing from source code, apply special permissions or ownership.
    629  1.1  tron     # If building a package, don't apply special permissions or ownership.
    630  1.1  tron 
    631  1.1  tron     case $install_root in
    632  1.1  tron     "") case $owner in
    633  1.1  tron 	[$]*) eval owner=$owner;;
    634  1.1  tron 	root) owner=;;
    635  1.1  tron 	esac
    636  1.1  tron 	case $group in
    637  1.1  tron 	[$]*) eval group=$group;;
    638  1.1  tron 	   -) group=;;
    639  1.1  tron 	esac;;
    640  1.1  tron      *) case $mode in
    641  1.1  tron 	[1-7]755) mode=755;;
    642  1.1  tron 	esac
    643  1.1  tron 	owner=
    644  1.1  tron 	group=;;
    645  1.1  tron     esac
    646  1.1  tron 
    647  1.1  tron 
    648  1.1  tron     case $type in
    649  1.1  tron 
    650  1.1  tron      # Create/update directory.
    651  1.1  tron 
    652  1.1  tron      d) eval path=$install_root$path
    653  1.1  tron 	test "$path" = "${install_root}no" -o -d $path || {
    654  1.1  tron 	    mkdir -p $path || exit 1
    655  1.1  tron 	    test -z "$owner" || chown $owner $path || exit 1
    656  1.1  tron 	    test -z "$group" || chgrp $group $path || exit 1
    657  1.1  tron 	    chmod $mode $path || exit 1
    658  1.1  tron 	}
    659  1.1  tron 	continue;;
    660  1.1  tron 
    661  1.1  tron      # Create/update regular file.
    662  1.1  tron 
    663  1.1  tron      f) echo $path | (IFS=/ read prefix file; IFS="$BACKUP_IFS"
    664  1.1  tron 	case $prefix in
    665  1.1  tron 	'$daemon_directory')
    666  1.1  tron 	    compare_or_replace $mode "$owner" "$group" libexec/$file \
    667  1.1  tron 		$DAEMON_DIRECTORY/$file || exit 1;;
    668  1.1  tron 	'$command_directory')
    669  1.1  tron 	    compare_or_replace $mode "$owner" "$group" bin/$file \
    670  1.1  tron 		$COMMAND_DIRECTORY/$file || exit 1;;
    671  1.1  tron 	'$config_directory')
    672  1.1  tron 	    compare_or_replace $mode "$owner" "$group" conf/$file \
    673  1.1  tron 		$CONFIG_DIRECTORY/$file || exit 1;;
    674  1.1  tron 	'$sendmail_path')
    675  1.1  tron 	    check_parent $SENDMAIL_PATH || exit 1
    676  1.1  tron 	    compare_or_replace $mode "$owner" "$group" bin/sendmail \
    677  1.1  tron 		$SENDMAIL_PATH || exit 1;;
    678  1.1  tron 	'$html_directory')
    679  1.1  tron 	    test "$html_directory" = "no" ||
    680  1.1  tron 		compare_or_replace $mode "$owner" "$group" html/$file \
    681  1.1  tron 		    $HTML_DIRECTORY/$file || exit 1;;
    682  1.1  tron 	'$manpage_directory')
    683  1.1  tron 	    check_parent $MANPAGE_DIRECTORY/$file || exit 1
    684  1.1  tron 	    compare_or_replace $mode "$owner" "$group" man/$file \
    685  1.1  tron 		$MANPAGE_DIRECTORY/$file || exit 1;;
    686  1.1  tron 	'$readme_directory')
    687  1.1  tron 	    test "$readme_directory" = "no" ||
    688  1.1  tron 		compare_or_replace $mode "$owner" "$group" README_FILES/$file \
    689  1.1  tron 		    $README_DIRECTORY/$file || exit 1;;
    690  1.1  tron 	 *) echo $0: Error: unknown entry $path in libexec/postfix-files 1>&2
    691  1.1  tron 	    exit 1;;
    692  1.1  tron 	esac) || exit 1
    693  1.1  tron 	continue;;
    694  1.1  tron 
    695  1.1  tron      # Hard link. Skip files that are not installed.
    696  1.1  tron 
    697  1.1  tron      h) eval echo $path | (
    698  1.1  tron 	    IFS=/ read prefix file; IFS="$BACKUP_IFS"
    699  1.1  tron 	    test "$prefix" = "no" || (
    700  1.1  tron 		eval dest_path=$install_root$path
    701  1.1  tron 		check_parent $dest_path || exit 1
    702  1.1  tron 		eval source_path=$install_root$source
    703  1.1  tron 		compare_or_hardlink $source_path $dest_path || exit 1
    704  1.1  tron 	    )
    705  1.1  tron 	) || exit 1
    706  1.1  tron 	continue;;
    707  1.1  tron 
    708  1.1  tron      # Symbolic link. Skip files that are not installed.
    709  1.1  tron 
    710  1.1  tron      l) eval echo $path | (
    711  1.1  tron 	    IFS=/ read prefix file; IFS="$BACKUP_IFS"
    712  1.1  tron 	    test "$prefix" = "no" || (
    713  1.1  tron 		eval dest_path=$install_root$path
    714  1.1  tron 		check_parent $dest_path || exit 1
    715  1.1  tron 		eval source_path=$install_root$source
    716  1.1  tron 		compare_or_symlink $source_path $dest_path || exit 1
    717  1.1  tron 	    )
    718  1.1  tron 	) || exit 1
    719  1.1  tron 	continue;;
    720  1.1  tron 
    721  1.1  tron      *) echo $0: Error: unknown type $type for $path in libexec/postfix-files 1>&2
    722  1.1  tron 	exit 1;;
    723  1.1  tron     esac
    724  1.1  tron 
    725  1.1  tron     done
    726  1.1  tron 
    727  1.1  tron # Save the installation parameters to main.cf even when they haven't
    728  1.1  tron # changed from their current default. Defaults can change between
    729  1.1  tron # Postfix releases, and software should not suddenly be installed in
    730  1.1  tron # the wrong place when Postfix is being upgraded.
    731  1.1  tron 
    732  1.1  tron bin/postconf -c $CONFIG_DIRECTORY -e \
    733  1.1  tron     "daemon_directory = $daemon_directory" \
    734  1.1  tron     "data_directory = $data_directory" \
    735  1.1  tron     "command_directory = $command_directory" \
    736  1.1  tron     "queue_directory = $queue_directory" \
    737  1.1  tron     "mail_owner = $mail_owner" \
    738  1.1  tron     "setgid_group = $setgid_group" \
    739  1.1  tron     "sendmail_path = $sendmail_path" \
    740  1.1  tron     "mailq_path = $mailq_path" \
    741  1.1  tron     "newaliases_path = $newaliases_path" \
    742  1.1  tron     "html_directory = $html_directory" \
    743  1.1  tron     "manpage_directory = $manpage_directory" \
    744  1.1  tron     "sample_directory = $sample_directory" \
    745  1.1  tron     "readme_directory = $readme_directory" \
    746  1.1  tron || exit 1
    747  1.1  tron 
    748  1.1  tron # If Postfix is being installed locally from source code, do the
    749  1.1  tron # post-install processing now.
    750  1.1  tron 
    751  1.1  tron test -n "$install_root" || {
    752  1.1  tron     bin/postfix post-install $post_install_options || exit 1
    753  1.1  tron }
    754