# SUMMARY
# Postfix post-installation script
# SYNOPSIS
-# post-install [options] config_directory
+# post-install [name=value] command ...
# DESCRIPTION
# The post-install script performs the finishing touch of a Postfix
# installation, after the executable programs and configuration
# create missing queue directories.
# .PP
# Arguments
-# .IP -create
+# .IP create-missing
# Create missing queue directories with ownerships and permissions
# according to the contents of $config_directory/postfix-files.
#
# This is required at Postfix start-up time.
-# .IP -set-permissions
+# .IP set-permissions
# Set all file/directory ownerships and permissions according to the
-# contents of $config_directory/postfix-files. Implies -create.
+# contents of $config_directory/postfix-files. Implies create-missing.
#
# This is required when installing Postfix from a pre-built package.
-# .IP -upgrade-permissions
+# .IP upgrade-permissions
# Update ownership and permission of selected files/directories as
-# specified in $config_directory/postfix-files. Implies -create.
+# specified in $config_directory/postfix-files. Implies create-missing.
#
# This is required when installing Postfix from source code, while
# Postfix was already installed on the machine.
-# .IP -upgrade-configuration
+# .IP upgrade-configuration
# Edit the installed main.cf and master.cf files, in order to account
# for missing services and to fix deprecated parameter settings.
#
# This is required when Postfix was already installed on the machine.
-# .IP -upgrade-source
-# Short-hand for -upgrade-permissions -upgrade-configuration.
+# .IP upgrade-source
+# Short-hand for upgrade-permissions upgrade-configuration.
#
# This is recommended when upgrading Postfix from source code.
-# .IP -upgrade-package
-# Short-hand for -set-permissions -upgrade-configuration.
+# .IP upgrade-package
+# Short-hand for set-permissions upgrade-configuration.
#
# This is recommended when upgrading Postfix from a pre-built package.
-# .IP -first-install-reminder
+# .IP first-install-reminder
# Remind the user that they still need to configure main.cf and the
# aliases file, and that newaliases needs to be run.
#
# This is recommended when Postfix is installed for the first time.
-# .IP config_directory
-# Directory with Postfix configuration files. This must be an absolute
-# pathname.
+# .IP config_directory=pathname
+# Absolute pathname of the directory with Postfix configuration files.
+# This information must be specified if it is not given via the
+# process environment.
+# .IP command_directory=pathname
+# Absolute pathname of the directory with the postconf command.
+# This information must be specified if it is not given via the
+# process environment, and if the directory is not a standard
+# system directory.
# SEE ALSO
-# postfix-install(1) Postfix primary installation script for installation
-# from source code, or for building a package for distribution to other
-# systems.
+# postfix-install(1) Postfix primary installation script.
# FILES
# $config_directory/main.cf, Postfix installation configuration.
# $config_directory/postfix-files, permissions and ownerships.
PATH=/bin:/usr/bin:/usr/sbin:/usr/etc:/sbin:/etc:/usr/contrib/bin:/usr/gnu/bin:/usr/ucb:/usr/bsd
SHELL=/bin/sh
+IFS="
+"
-USAGE="usage: $0 [options] config_directory
+USAGE="Usage: $0 [name=value] command
+ create-missing Create missing queue directories.
+ upgrade-source Use when upgrading from source.
+ upgrade-package Use when upgrading from pre-built package.
+ first-install-reminder Remind of mandatory configuration steps.
+ config_directory=path Specify an absolute path name.
+ command_directory=path Specify an absolute path name."
- -upgrade-source Use when upgrading from source.
+# Process command-line options and parameter settings. Work around
+# brain damaged shells. "name=value command" should not make the
+# name=value setting permanent.
- -upgrade-package Use when upgrading from pre-built package.
-
- -first-install-reminder Remind of mandatory configuration steps.
-
- config_directory Must be an absolute path name."
-
-# Process command-line settings
+create=; set_perms=; upgrade_perms=; upgrade_conf=; first_install_reminder=
for arg
do
case $arg in
- -create) create=1;;
- -set-perm*) create=1; set_perms=1;;
- -upgrade-perm*) create=1; upgrade_perms=1;;
- -upgrade-conf*) upgrade_conf=1;;
- -upgrade-source) create=1; upgrade_conf=1; upgrade_perms=1;;
- -upgrade-package) create=1; upgrade_conf=1; set_perms=1;;
- -first-install*) first_install_reminder=1;;
- /*) config_dir=$1;;
- "") break;;
- *) echo "Error: $USAGE" 1>&2; exit 1;;
+ *=*) SAVED_IFS="$IFS"; IFS= eval $arg; IFS="$SAVED_IFS";;
+ create-missing) create=1;;
+ set-perm*) create=1; set_perms=1;;
+ upgrade-perm*) create=1; upgrade_perms=1;;
+ upgrade-conf*) upgrade_conf=1;;
+ upgrade-source) create=1; upgrade_conf=1; upgrade_perms=1;;
+ upgrade-package) create=1; upgrade_conf=1; set_perms=1;;
+ first-install*) first_install_reminder=1;;
+ "") break;;
+ *) echo "Error: $USAGE" 1>&2; exit 1;;
esac
shift
done
exit 1
}
-test -n "$config_dir" || {
- echo "Error: $USAGE" 1>&2
+test -n "$config_directory" || {
+ echo "Error: no config_directory parameter setting." 1>&2
+ echo "$USAGE" 1>&2
exit 1
}
-test -d "$config_dir" || {
- echo Error: $config_dir is not a directory. 1>&2
+test -d "$config_directory" || {
+ echo Error: $config_directory is not a directory. 1>&2
exit 1
}
-test -f $config_dir/postfix-files || {
- Error: $config_dir/postfix-files is not a file. 1>&2
+test -f $config_directory/postfix-files || {
+ Error: $config_directory/postfix-files is not a file. 1>&2
exit 1
}
CHATTR=echo
fi
-# Use file/directory status information in $config_dir/postfix-files.
+# Bootstrapping problem.
+
+if [ -n "$command_directory" ]
+then
+ POSTCONF="$command_directory/postconf"
+else
+ POSTCONF="postconf"
+fi
+
+# Settings from main.cf must override command line or environment settings.
+
+for name in daemon_directory command_directory queue_directory mail_owner \
+ setgid_group sendmail_path newaliases_path mailq_path manpage_path
+do
+ eval $name=\`$POSTCONF -c $config_directory -h $name\` || kill $$
+done
+
+POSTCONF="$command_directory/postconf"
+
+# Use file/directory status information in $config_directory/postfix-files.
test -n "$create" && {
- IFS=:
- while read path type owner group mode upgrade_flag create_flag junk
+ while IFS=: read path type owner group mode upgrade_flag create_flag junk
do
set_permission=
case $path in
- /*) # Create missing directories with proper owner/group/mode settings.
- if [ -n "$create" -a "$type" = "d" -a -n "$create_flag" -a ! -d "$path" ]
- then
- mkdir $path || exit 1
- $CHATTR $path >/dev/null 2>/dev/null
- set_permission=1
- # Update all owner/group/mode settings.
- elif [ -n "$set_perms" ]
- then
- set_permission=1
- # Update obsolete owner/group/mode settings.
- elif [ -n "$upgrade_perms" -a -n "$upgrade_flag" ]
- then
- set_permission=1
- fi
- test -n "$set_permission" && {
- chown $owner $path || exit 1
- test -z "$group" || chgrp $group $path || exit 1
- chmod $mode $path || exit 1
- }
- ;;
+ [$]*) eval path=$path;;
+ /*) ;;
+ *) continue;;
+ esac
+ case $owner in
+ [$]*) eval owner=$owner;;
esac
- done <$config_dir/postfix-files
+ case $group in
+ [$]*) eval group=$group;;
+ esac
+ # Create missing directories with proper owner/group/mode settings.
+ if [ -n "$create" -a "$type" = "d" -a -n "$create_flag" -a ! -d "$path" ]
+ then
+ mkdir $path || exit 1
+ $CHATTR $path >/dev/null 2>/dev/null
+ set_permission=1
+ # Update all owner/group/mode settings.
+ elif [ -n "$set_perms" ]
+ then
+ set_permission=1
+ # Update obsolete owner/group/mode settings.
+ elif [ -n "$upgrade_perms" -a -n "$upgrade_flag" ]
+ then
+ set_permission=1
+ fi
+ test -n "$set_permission" && {
+ chown $owner $path || exit 1
+ test -z "$group" || chgrp $group $path || exit 1
+ chmod $mode $path || exit 1
+ }
+ done <$config_directory/postfix-files
}
# Upgrade existing Postfix configuration files if necessary.
# Add missing flush service to master.cf.
- grep 'flush.*flush' $config_dir/master.cf >/dev/null || {
- echo Editing $config_dir/master.cf, adding missing entry for flush service
- cat >>$config_dir/master.cf <<EOF
+ grep 'flush.*flush' $config_directory/master.cf >/dev/null || {
+ echo Editing $config_directory/master.cf, adding missing entry for flush service
+ cat >>$config_directory/master.cf <<EOF
flush unix - - n 1000? 0 flush
EOF
}
# Change privileged pickup service into unprivileged.
grep "^pickup[ ]*fifo[ ]*n[ ]*n" \
- $config_dir/master.cf >/dev/null && {
- echo Editing $config_dir/master.cf, making the pickup service unprivileged
- ed $config_dir/master.cf <<EOF
+ $config_directory/master.cf >/dev/null && {
+ echo Editing $config_directory/master.cf, making the pickup service unprivileged
+ ed $config_directory/master.cf <<EOF
/^pickup[ ]*fifo[ ]*n[ ]*n/
s/\(n[ ]*\)n/\1-/
p
for name in cleanup flush
do
grep "^$name[ ]*unix[ ]*-" \
- $config_dir/master.cf >/dev/null && {
- echo Editing $config_dir/master.cf, making the $name service public
- ed $config_dir/master.cf <<EOF
+ $config_directory/master.cf >/dev/null && {
+ echo Editing $config_directory/master.cf, making the $name service public
+ ed $config_directory/master.cf <<EOF
/^$name[ ]*unix[ ]*-/
s/-/n/
p
# If you don't want slow mailq, be sure to hash defer and deferred,
# because those two directories can contain lots of files.
- found=`bin/postconf -c $config_dir -h hash_queue_names`
+ found=`$POSTCONF -c $config_directory -h hash_queue_names`
missing=
(echo "$found" | grep active >/dev/null) || missing="$missing active"
(echo "$found" | grep bounce >/dev/null) || missing="$missing bounce"
(echo "$found" | grep deferred>/dev/null)|| missing="$missing deferred"
test -n "$missing" && {
echo fixing main.cf hash_queue_names for missing $missing
- bin/postconf -c $config_dir -e hash_queue_names="$found$missing"
+ $POSTCONF -c $config_directory -e hash_queue_names="$found$missing"
}
}
test -n "$first_install_reminder" && {
- ALIASES=`postconf -h alias_database | sed 's/^[^:]*://'`
- NEWALIASES_PATH=`postconf -h newaliases_path`
+ ALIASES=`$POSTCONF -h alias_database | sed 's/^[^:]*://'`
+ NEWALIASES_PATH=`$POSTCONF -h newaliases_path`
cat <<EOF 1>&2
Warning: you still need to edit myorigin/mydestination/mynetworks
- parameter settings in $config_dir/main.cf.
+ parameter settings in $config_directory/main.cf.
See also http://www.postfix.org/faq.html for information about
dialup sites or about sites inside a firewalled network.
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="
+"
-# Process command-line options and parameter settings.
+# Process command-line options and parameter settings. Work around
+# brain damaged shells. "name=value command" should not make the
+# name=value setting permanent.
for arg
do
case $arg in
- *=*) IFS= eval $arg;;
+ *=*) SAVED_IFS="$IFS"; IFS= eval $arg; IFS="$SAVED_IFS";;
-non-interactive) non_interactive=1;;
*) echo Error: usage: $0 [-non-interactive] name=value ... 1>&2
exit 1;;
# update=update owner/group/mode (upgrade mode).
# create=create missing directory.
#
-$config_directory:d:root::755:u
-$daemon_directory:d:root::755:u
-$queue_directory:d:root::755:u
+\$config_directory:d:root::755:u
+\$daemon_directory:d:root::755:u
+\$queue_directory:d:root::755:u:c
EOF
# Generate instructions only for queue subdirectories.
for dir in active bounce corrupt defer deferred flush incoming private saved
do
- echo $queue_directory/$dir:d:$mail_owner::700:u:c \
+ echo \$queue_directory/$dir:d:\$mail_owner::700:u:c \
>>$CONFIG_DIRECTORY/postfix-files || exit 1
done
-echo $queue_directory/maildrop:d:$mail_owner:$setgid_group:730:u:c \
+echo \$queue_directory/maildrop:d:\$mail_owner:\$setgid_group:730:u:c \
>>$CONFIG_DIRECTORY/postfix-files || exit 1
-echo $queue_directory/public:d:$mail_owner:$setgid_group:710:u:c \
+echo \$queue_directory/public:d:\$mail_owner:\$setgid_group:710:u:c \
>>$CONFIG_DIRECTORY/postfix-files || exit 1
-echo $queue_directory/pid:d:root::755:u:c \
+echo \$queue_directory/pid:d:root::755:u:c \
>>$CONFIG_DIRECTORY/postfix-files || exit 1
# Install daemon programs.
for file in `censored_ls libexec`
do
compare_or_replace $EXE libexec/$file $DAEMON_DIRECTORY/$file || exit 1
- echo $daemon_directory/$file:f:root::755 \
+ echo \$daemon_directory/$file:f:root::755 \
>>$CONFIG_DIRECTORY/postfix-files || exit 1
done
for file in `censored_ls bin | grep '^post' | egrep -v '^post(drop|queue)$'`
do
compare_or_replace $EXE bin/$file $COMMAND_DIRECTORY/$file || exit 1
- echo $command_directory/$file:f:root::755 \
+ echo \$command_directory/$file:f:root::755 \
>>$CONFIG_DIRECTORY/postfix-files || exit 1
done
for file in postdrop postqueue
do
compare_or_replace $EXE bin/$file $COMMAND_DIRECTORY/$file || exit 1
- echo $command_directory/$file:f:root:postdrop:1755 \
+ echo \$command_directory/$file:f:root:\$setgid_group:1755 \
>>$CONFIG_DIRECTORY/postfix-files || exit 1
done
else
do
compare_or_replace 2$EXE bin/$file $COMMAND_DIRECTORY/$file postdrop \
|| exit 1
- echo $command_directory/$file:f:root:postdrop:1755 \
+ echo \$command_directory/$file:f:root:\$setgid_group:1755 \
>>$CONFIG_DIRECTORY/postfix-files || exit 1
done
fi
compare_or_symlink $SENDMAIL_PATH $NEWALIASES_PATH
compare_or_symlink $SENDMAIL_PATH $MAILQ_PATH
cat <<EOF >>$CONFIG_DIRECTORY/postfix-files || exit 1
-$sendmail_path:f:root::755
-$newaliases_path:f:root::755
-$mailq_path:f:root::755
+\$sendmail_path:f:root::755
+\$newaliases_path:f:root::755
+\$mailq_path:f:root::755
EOF
}
do
compare_or_replace 644 conf/$file $CONFIG_DIRECTORY/$file || exit 1
done
- test -z "$install_root" && need_config="-create -first-install"
+ test -z "$install_root" && need_config="create-missing first-install"
fi
for file in `censored_ls conf | egrep -v 'postfix-script|post-install'`
do
- echo $config_directory/$file:f:root::644 \
+ echo \$config_directory/$file:f:root::644 \
>>$CONFIG_DIRECTORY/postfix-files || exit 1
done
for file in postfix-script post-install
do
compare_or_replace $EXE conf/$file $CONFIG_DIRECTORY/$file || exit 1
- echo $config_directory/$file:f:root::755 \
+ echo \$config_directory/$file:f:root::755 \
>>$CONFIG_DIRECTORY/postfix-files || exit 1
done
for file in `censored_ls man?/*`
do
compare_or_replace 644 $file $MANPAGE_PATH/$file || exit 1
- echo "$manpage_path/$file:f:root::644" \
+ echo \$manpage_path/$file:f:root::644 \
>>$CONFIG_DIRECTORY/postfix-files || exit 1
done)
test -n "$install_root" && exit 0
-${SHELL} conf/post-install ${need_config-"-upgrade-source"} $config_directory
+export command_directory config_directory
+
+${SHELL} conf/post-install ${need_config-"upgrade-source"}