#!/bin/sh
umask 022
PATH=/bin:/usr/bin:/usr/sbin:/usr/etc:/sbin:/etc:/usr/contrib/bin:/usr/gnu/bin:/usr/ucb:/usr/bsd
SHELL=/bin/sh
IFS="
"
BACKUP_IFS="$IFS"
LC_ALL=C; export LC_ALL
if [ -n "$SHLIB_ENV_VAR" ]; then
junk="${SHLIB_ENV_VAL}"
eval export "$SHLIB_ENV_VAR=\$junk"
fi
USAGE="Usage: $0 [name=value] [option]
-keep-build-mtime Preserve build-time file mtime timestamps.
-non-interactive Do not ask for installation parameters.
-package Build a ready-to-install package.
name=value Specify an installation parameter".
for arg
do
case $arg in
*[" "]*) echo "$0: Error: argument contains whitespace: '$arg'"; exit 1;;
*=*) IFS= eval $arg; IFS="$BACKUP_IFS";;
-non-int*) non_interactive=1;;
-package) need_install_root=install_root;;
-keep-build-mtime)
keep_build_mtime=1;;
*) echo "$0: Error: $USAGE" 1>&2; exit 1;;
esac
shift
done
test -z "$non_interactive" -a ! -t 0 && {
echo $0: Error: for non-interactive use, run: \"$0 -non-interactive\" 1>&2
exit 1
}
test -x bin/postconf || {
echo $0: Error: no bin/postconf file. Did you forget to run \"make\"? 1>&2
exit 1
}
CONFIG_PARAMS="command_directory daemon_directory data_directory \
html_directory mail_owner mailq_path manpage_directory newaliases_path \
queue_directory readme_directory sendmail_path setgid_group shlib_directory \
meta_directory"
for name in $CONFIG_PARAMS sample_directory install_root tempdir
do
eval junk=\$$name
case "$junk" in
*MAIL_VERSION*)
case "$mail_version" in
"") mail_version="`/usr/sbin/postconf -dhx mail_version`" || exit 1
esac
val=`echo "$junk" | sed 's/MAIL_VERSION$/'"$mail_version/g"` || exit 1
case "$val" in
*MAIL_VERSION*)
echo "MAIL_VERSION not at end of parameter value: $junk" 1>&2; exit 1
esac
eval ${name}='"$val"'
esac
done
case `uname -s` in
HP-UX*) FMT=cat;;
*) FMT=fmt;;
esac
test -z "$non_interactive" && cat <<EOF | ${FMT}
Warning: if you use this script to install Postfix locally,
this script will replace existing sendmail or Postfix programs.
Make backups if you want to be able to recover.
Before installing files, this script prompts you for some
definitions. Most definitions will be remembered, so you have
to specify them only once. All definitions should have a
reasonable default value.
EOF
compare_or_replace() {
mode=$1
owner=$2
group=$3
src=$4
dst=$5
(cmp $src $dst >/dev/null 2>&1 && echo Skipping $dst...) || {
echo Updating $dst...
rm -f $tempdir/junk || exit 1
cp $src $tempdir/junk || exit 1
test -z "$keep_build_mtime" || touch -r $src $tempdir/junk || exit 1
mv -f $tempdir/junk $dst || exit 1
test -z "$owner" || chown $owner $dst || exit 1
test -z "$group" || chgrp $group $dst || exit 1
chmod $mode $dst || exit 1
}
}
myreadlink() {
ls -ld -- "$@" 2>/dev/null | awk '
/->/ { print $NF; next }
{ exit(1) }
'
}
compare_or_symlink() {
case $1 in
/*) dest=`echo $1 | sed '
s;^'$install_root';;
s;/\./;/;g
s;//*;/;g
s;^/;;
'`
link=`echo $2 | sed '
s;^'$install_root';;
s;/\./;/;g
s;//*;/;g
s;^/;;
s;/[^/]*$;/;
s;[^/]*/;../;g
s;$;'$dest';
'`
;;
*) link=$1
;;
esac
(test $link = "`myreadlink $2`" >/dev/null 2>&1 && echo Skipping $2...) || {
echo Updating $2...
rm -f $2 && ln -sf $link $2 || exit 1
}
}
compare_or_hardlink() {
(cmp $1 $2 >/dev/null 2>&1 && echo Skipping $2...) || {
echo Updating $2...
rm -f $2 || exit 1
ln $1 $2 || exit 1
}
}
check_parent() {
for path
do
dir=`echo $path|sed -e 's/[/][/]*[^/]*$//' -e 's/^$/\//'`
test -d $dir || mkdir -p $dir || exit 1
done
}
case `echo -n` in
"") n=-n; c=;;
*) n=; c='\c';;
esac
install_root_prompt="the prefix for installed file names. Specify
this ONLY if you are building ready-to-install packages for
distribution to OTHER machines. See PACKAGE_README for instructions."
tempdir_prompt="a directory for scratch files while installing
Postfix. You must have write permission in this directory."
config_directory_prompt="the final destination directory for
installed Postfix configuration files."
data_directory_prompt="the final destination directory for
Postfix-writable data files such as caches or random numbers. This
directory should not be shared with non-Postfix software."
daemon_directory_prompt="the final destination directory for
installed Postfix daemon programs. This directory should not be
in the command search path of any users."
command_directory_prompt="the final destination directory for
installed Postfix administrative commands. This directory should
be in the command search path of adminstrative users."
queue_directory_prompt="the final destination directory for Postfix
queues."
sendmail_path_prompt="the final destination pathname for the
installed Postfix sendmail command. This is the Sendmail-compatible
mail posting interface."
newaliases_path_prompt="the final destination pathname for the
installed Postfix newaliases command. This is the Sendmail-compatible
command to build alias databases for the Postfix local delivery
agent."
mailq_path_prompt="the final destination pathname for the installed
Postfix mailq command. This is the Sendmail-compatible mail queue
listing command."
mail_owner_prompt="the owner of the Postfix queue. Specify an
account with numerical user ID and group ID values that are not
used by any other accounts on the system."
setgid_group_prompt="the group for mail submission and for queue
management commands. Specify a group name with a numerical group
ID that is not shared with other accounts, not even with the Postfix
mail_owner account. You can no longer specify \"no\" here."
manpage_directory_prompt="the final destination directory for the
Postfix on-line manual pages. You can no longer specify \"no\"
here."
readme_directory_prompt="the final destination directory for the Postfix
README files. Specify \"no\" if you do not want to install these files."
html_directory_prompt="the final destination directory for the Postfix
HTML files. Specify \"no\" if you do not want to install these files."
shlib_directory_prompt="the final destination directory for Postfix
shared-library files."
meta_directory_prompt="the final destination directory for
non-executable files that are shared among multiple Postfix instances,
such as postfix-files, dynamicmaps.cf, as well as the multi-instance
template files main.cf.proto and master.cf.proto."
: ${install_root=/}
: ${tempdir=`pwd`}
: ${config_directory=`/usr/sbin/postconf -c conf -h -d config_directory`}
test -z "$non_interactive" && for name in install_root tempdir config_directory
do
while :
do
echo
eval echo Please specify \$${name}_prompt | ${FMT}
eval echo \$n "$name: [\$$name]\ \$c"
read ans
case $ans in
"") break;;
*) case $ans in
/*) eval $name=$ans; break;;
*) echo; echo $0: Error: $name should be an absolute path name. 1>&2;;
esac;;
esac
done
done
case $install_root in
/) install_root=
esac
test -z "$need_install_root" || test -n "$install_root" || {
echo $0: Error: invalid package root directory: \"install_root=/\" 1>&2
exit 1
}
CONFIG_DIRECTORY=$install_root$config_directory
grep setgid_group $CONFIG_DIRECTORY/main.cf >/dev/null 2>&1 || {
test -f $CONFIG_DIRECTORY/install.cf && {
for name in sendmail_path newaliases_path mailq_path setgid manpages
do
eval junk=\$$name
case "$junk" in
"") eval unset $name;;
esac
eval : \${$name="\`. $CONFIG_DIRECTORY/install.cf; echo \$$name\`"} \
|| exit 1
done
: ${setgid_group=$setgid}
: ${manpage_directory=$manpages}
}
}
test -f $CONFIG_DIRECTORY/main.cf && {
for name in $CONFIG_PARAMS sample_directory
do
eval junk=\$$name
case "$junk" in
"") eval unset $name;;
esac
eval : \${$name=\`/usr/sbin/postconf -c $CONFIG_DIRECTORY -hx $name\`} ||
exit 1
done
}
for name in $CONFIG_PARAMS sample_directory
do
eval junk=\$$name
case "$junk" in
"") eval unset $name;;
esac
eval : \${$name=\`/usr/sbin/postconf -c conf -d -hx $name\`} || exit 1
done
test -z "$non_interactive" && for name in $CONFIG_PARAMS
do
while :
do
echo
eval echo Please specify \$${name}_prompt | ${FMT}
eval echo \$n "$name: [\$$name]\ \$c"
read ans
case $ans in
"") break;;
*) eval $name=$ans; break;;
esac
done
done
case "$setgid_group" in
no) (echo $0: Error: the setgid_group parameter no longer accepts
echo \"no\" values. Try again with \"setgid_group=groupname\" on the
echo command line or execute \"make install\" and specify setgid_group
echo interactively.) | ${FMT} 1>&2
exit 1;;
esac
case "$manpage_directory" in
no) (echo $0: Error: the manpage_directory parameter no longer accepts
echo \"no\" values. Try again with \"manpage_directory=/path/name\"
echo on the command line or execute \"make install\" and specify
echo manpage_directory interactively.) | ${FMT} 1>&2
exit 1;;
esac
for path in "$html_directory" "$readme_directory" "$shlib_directory"
do
case "$path" in
/*) ;;
no) ;;
*) echo $0: Error: \"$path\" should be \"no\" or an absolute path name. 1>&2
exit 1;;
esac
done
for path in "$daemon_directory" "$data_directory" "$command_directory" "$queue_directory" \
"$sendmail_path" "$newaliases_path" "$mailq_path" "$manpage_directory" \
"$meta_directory"
do
case "$path" in
/*) ;;
*) echo $0: Error: \"$path\" should be an absolute path name. 1>&2; exit 1;;
esac
done
for path in mailq_path newaliases_path sendmail_path
do
eval test -d $install_root\$$path && {
echo $0: Error: \"$path\" specifies a directory. 1>&2
exit 1
}
done
for path in command_directory config_directory daemon_directory data_directory \
manpage_directory queue_directory shlib_directory html_directory \
readme_directory meta_directory
do
case "$path" in
no) ;;
*) eval test -f $install_root\$$path && {
echo $0: Error: \"$path\" specifies a regular file. 1>&2
exit 1
};;
esac
done
for name in $CONFIG_PARAMS sample_directory
do
eval junk=\$$name
case "$junk" in
*"[ ]"*) echo "$0: Error: $name value contains whitespace: '$junk'" 1>&2
exit 1;;
esac
done
test -d $tempdir || mkdir -p $tempdir || exit 1
trap "rm -f $tempdir/junk" 0 1 2 3 15
( rm -f $tempdir/junk && touch $tempdir/junk ) || {
echo $0: Error: you have no write permission to $tempdir. 1>&2
echo Specify an alternative directory for scratch files. 1>&2
exit 1
}
test -z "$install_root" && {
chown root $tempdir/junk >/dev/null 2>&1 || {
echo Error: you have no permission to change file ownership. 1>&2
exit 1
}
chown "$mail_owner" $tempdir/junk >/dev/null 2>&1 || {
echo $0: Error: \"$mail_owner\" needs an entry in the passwd file. 1>&2
echo Remember, \"$mail_owner\" needs a dedicated user and group id. 1>&2
exit 1
}
chgrp "$setgid_group" $tempdir/junk >/dev/null 2>&1 || {
echo $0: Error: \"$setgid_group\" needs an entry in the group file. 1>&2
echo Remember, \"$setgid_group\" needs a dedicated group id. 1>&2
exit 1
}
}
rm -f $tempdir/junk || exit 1
trap 0 1 2 3 15
DAEMON_DIRECTORY=$install_root$daemon_directory
COMMAND_DIRECTORY=$install_root$command_directory
QUEUE_DIRECTORY=$install_root$queue_directory
SENDMAIL_PATH=$install_root$sendmail_path
HTML_DIRECTORY=$install_root$html_directory
MANPAGE_DIRECTORY=$install_root$manpage_directory
README_DIRECTORY=$install_root$readme_directory
SHLIB_DIRECTORY=$install_root$shlib_directory
META_DIRECTORY=$install_root$meta_directory
test -d $DAEMON_DIRECTORY || mkdir -p $DAEMON_DIRECTORY || exit 1
test -d $COMMAND_DIRECTORY || mkdir -p $COMMAND_DIRECTORY || exit 1
test -d $QUEUE_DIRECTORY || mkdir -p $QUEUE_DIRECTORY || exit 1
test "$shlib_directory" = "no" -o -d $SHLIB_DIRECTORY ||
mkdir -p $SHLIB_DIRECTORY || exit 1
test "$html_directory" = "no" -o -d $HTML_DIRECTORY ||
mkdir -p $HTML_DIRECTORY || exit 1
test "$readme_directory" = "no" -o -d $README_DIRECTORY ||
mkdir -p $README_DIRECTORY || exit 1
test -d $META_DIRECTORY || mkdir -p $META_DIRECTORY || exit 1
if [ -f $CONFIG_DIRECTORY/main.cf ]
then
post_install_options="upgrade-source"
else
post_install_options="first-install"
fi
exec < meta/postfix-files || exit 1
while IFS=: read path type owner group mode flags junk
do
IFS="$BACKUP_IFS"
case $path in
[$]*) ;;
*) continue;;
esac
case $flags in
*o*) continue
esac
case $flags in
*p*) eval test -f $install_root$path && {
eval echo "Skipping $install_root$path..."
continue
};;
esac
case $type in
[hl]) eval source=$owner;;
esac
case $install_root in
"") case $owner in
[$]*) eval owner=$owner;;
root) owner=;;
esac
case $group in
[$]*) eval group=$group;;
-) group=;;
esac;;
*) case $mode in
[1-7]755) mode=755;;
esac
owner=
group=;;
esac
case $type in
d) eval path=$install_root$path
test "$path" = "${install_root}no" -o -d $path || {
mkdir -p $path || exit 1
test -z "$owner" || chown $owner $path || exit 1
test -z "$group" || chgrp $group $path || exit 1
chmod $mode $path || exit 1
}
continue;;
f) echo $path | (IFS=/ read prefix file; IFS="$BACKUP_IFS"
case $prefix in
'$shlib_directory')
compare_or_replace $mode "$owner" "$group" lib/$file \
$SHLIB_DIRECTORY/$file || exit 1;;
'$meta_directory')
compare_or_replace $mode "$owner" "$group" meta/$file \
$META_DIRECTORY/$file || exit 1;;
'$daemon_directory')
compare_or_replace $mode "$owner" "$group" libexec/$file \
$DAEMON_DIRECTORY/$file || exit 1;;
'$command_directory')
compare_or_replace $mode "$owner" "$group" bin/$file \
$COMMAND_DIRECTORY/$file || exit 1;;
'$config_directory')
compare_or_replace $mode "$owner" "$group" conf/$file \
$CONFIG_DIRECTORY/$file || exit 1;;
'$sendmail_path')
check_parent $SENDMAIL_PATH || exit 1
compare_or_replace $mode "$owner" "$group" bin/sendmail \
$SENDMAIL_PATH || exit 1;;
'$html_directory')
test "$html_directory" = "no" ||
compare_or_replace $mode "$owner" "$group" html/$file \
$HTML_DIRECTORY/$file || exit 1;;
'$manpage_directory')
check_parent $MANPAGE_DIRECTORY/$file || exit 1
compare_or_replace $mode "$owner" "$group" man/$file \
$MANPAGE_DIRECTORY/$file || exit 1;;
'$readme_directory')
test "$readme_directory" = "no" ||
compare_or_replace $mode "$owner" "$group" README_FILES/$file \
$README_DIRECTORY/$file || exit 1;;
*) echo $0: Error: unknown entry $path in meta/postfix-files 1>&2
exit 1;;
esac) || exit 1
continue;;
h) eval echo $path | (
IFS=/ read prefix file; IFS="$BACKUP_IFS"
test "$prefix" = "no" || (
eval dest_path=$install_root$path
check_parent $dest_path || exit 1
eval source_path=$install_root$source
compare_or_hardlink $source_path $dest_path || exit 1
)
) || exit 1
continue;;
l) eval echo $path | (
IFS=/ read prefix file; IFS="$BACKUP_IFS"
test "$prefix" = "no" || (
eval dest_path=$install_root$path
check_parent $dest_path || exit 1
eval source_path=$install_root$source
compare_or_symlink $source_path $dest_path || exit 1
)
) || exit 1
continue;;
*) echo $0: Error: unknown type $type for $path in meta/postfix-files 1>&2
exit 1;;
esac
done
IFS="$BACKUP_IFS"
case "$mail_version" in
"") mail_version="`/usr/sbin/postconf -dhx mail_version`" || exit 1
esac
for name in $CONFIG_PARAMS sample_directory
do
eval junk=\$$name
case "$junk" in
*"$mail_version"*)
case "$pattern" in
"") pattern=`echo "$mail_version" | sed 's/\./\\\\./g'` || exit 1
esac
val=`echo "$junk" | sed "s/$pattern"'$/${mail_version}/g'` || exit 1
eval ${name}='"$val"'
esac
done
/usr/sbin/postconf -c $CONFIG_DIRECTORY -e \
"daemon_directory = $daemon_directory" \
"data_directory = $data_directory" \
"command_directory = $command_directory" \
"queue_directory = $queue_directory" \
"mail_owner = $mail_owner" \
"setgid_group = $setgid_group" \
"sendmail_path = $sendmail_path" \
"mailq_path = $mailq_path" \
"newaliases_path = $newaliases_path" \
"html_directory = $html_directory" \
"manpage_directory = $manpage_directory" \
"sample_directory = $sample_directory" \
"readme_directory = $readme_directory" \
"shlib_directory = $shlib_directory" \
"meta_directory = $meta_directory" \
|| exit 1
test -n "$install_root" || {
/usr/sbin/postfix post-install $post_install_options || exit 1
}