1
  5   #ˆl–äY>”ŠhŠi@·p ¸”Å£�þDÓEYÀŠY[Œ  ^óÎƒ|OµÍÀÐ $N    ##! /bin/sh

umask 022

# postmulti(1) contract:
#
# Arguments:
#  postmulti-script -e <edit_command>
#
# Environment:
#
# All actions:
#
#  MAIL_CONFIG			- config_directory of primary instance
#  command_directory		- From primary instance
#  daemon_directory		- From primary instance
#  meta_directory		- From primary instance
#  shlib_directory		- From primary instance
#  config_directory		- config_directory of target instance
#  queue_directory		- queue_directory of target instance
#  data_directory		- data_directory of target instance
#
# Create, destroy, import and deport:
#
#  multi_instance_directories	- New value for primary instance
#
# Create, import and assign (unset == nochange, "-" == clear):
#
#  multi_instance_group		- New value for target instance
#  multi_instance_name		- New value for target instance

: ${MAIL_CONFIG:?"do not invoke this command directly"}
: ${command_directory:?"do not invoke this command directly"}
: ${daemon_directory:?"do not invoke this command directly"}
: ${meta_directory:?"do not invoke this command directly"}
: ${shlib_directory:?"do not invoke this command directly"}

USAGE="$0 -e create|destroy|import|deport|enable|disable|assign|init"
usage() { echo "$0: Error: Usage: $USAGE" >&2; exit 1; }

TAG="$MAIL_LOGTAG/postmulti-script"
fatal() { postlog -p fatal -t "$TAG" "$1"; exit 1; }

# args: add|del $dir
#
update_cfdirs() {
    op=$1
    dir=$2

    alt=`postconf -h alternate_config_directories` || return 1

    shift $#	# Needed on SunOS where bare "set --" is NOP!
    IFS="$IFS,"; set -- $alt; IFS="$BACKUP_IFS"
    keep=
    found=
    # Portability: SunOS "sh" needs 'in "$@"' for one-line for-loop.
    for d in "$@"; do [ "$d" = "$dir" ] && found=1 || keep="$keep $d"; done

    set -- "multi_instance_directories = $multi_instance_directories"

    case $op in
    add) test -n "$found" ||
	 set -- "$@" "alternate_config_directories =$keep $dir";;
    del) test -n "$found" &&
	 set -- "$@" "alternate_config_directories =$keep";;
      *) return 1;;		# XXX: Internal error
    esac
    postconf -e "$@" || return 1
}

assign_names() {
    # Set the instance name and group
    #
    test -n "$multi_instance_name" && {
	test "$multi_instance_name" = "-" && multi_instance_name=
	set -- "$@" "multi_instance_name = $multi_instance_name"
    }
    test -n "$multi_instance_group" && {
	test "$multi_instance_group" = "-" && multi_instance_group=
	set -- "$@" "multi_instance_group = $multi_instance_group"
    }
    test $# -eq 0 || postconf -c "$config_directory" -e "$@" || return 1
}

# Process command-line options and parameter settings. Work around
# brain damaged shells. "IFS=value command" should not make the
# IFS=value setting permanent. But some broken standard allows it.

BACKUP_IFS="$IFS"
action=

while getopts ":e:" opt
do
    case $opt in
    e) action="$OPTARG";;
    *) usage;;
    esac
done
shift `expr $OPTIND - 1`

# Check for valid action and required instance name
case "$action" in
 create|import|destroy|deport|enable|disable|assign|init) ;;
						       *) usage;;
esac
test $# -eq 0 || usage

case $action in
init)
    postconf -e \
    	'multi_instance_wrapper = ${command_directory}/postmulti -p --' \
    	'multi_instance_enable = yes'
    exit $? ;;
esac

# Backport note: "-x" requires 2.10 or later, and is not essential here.
#
wrapper=`postconf -hx multi_instance_wrapper` || exit 1
enable=`postconf -hx multi_instance_enable` || exit 1

test -n "$wrapper" ||
    fatal "multi_instance_wrapper is empty, run 'postmulti -e init' first."

test "$enable" = "yes" ||
    fatal "multi_instance_enable!=yes, run 'postmulti -e init' first."

: ${config_directory:?"Invalid empty target instance config_directory"}

case $action in
create|import)

    # Atomically install stock main.cf/master.cf files. We install the
    # master.cf file last. Once it is present the instance is complete.
    #
    test -f $config_directory/main.cf -a \
	 -f $config_directory/master.cf || {

	test "$action" = "create" || {
	    test 