#! /bin/sh
#
# @(#)setMAILOPTS	1.2	LPS_UNX_COM	02/15/93
#
# Copyright 1993   Digital Equipment Corporation, Maynard, MA
#
# setMAILOPTS
#
# A script that produces a value for attribute MAILOPTS.
#
# Parameters:
#    $1 - LPS class identifier, one of {PC, MC, PS, ENV}
#    $2 - Operating system type identifier (eg: SV2, BSD, etc)
#    $3 - Print client type identifier (eg: AIX, BSD, SV3, etc)
#    $4 - PrintServer printer model (eg: LPS17, LPS20)
#    $5 - Default value for the attribute
#    $6 - Path of the output file to receive the final attribute value
#
# Global variables:
#    ECHON
#    ENV_MAILADMADDRS
#    ENV_MAILPROG
#    LPSODB
#    LPSODBLIST
#    PAGER
#    PRODUCT
#
# Exit values:
#    0 - Success, output file contains newly set attribute value.
#    1 - Error or interruption occurred, error messages go to stderr,
#	 contents of the output file are undefined.
###

CLASS=$1
OSTYPE=$2
PCTYPE=$3
PSMODEL=$4
DEFVAL=$5
OUTFILE=$6

. $FUNCS   # Import the standard LPS shell functions

if [ "$CLASS" != "ENV" ]
then
    if [ -z "$ENV_MAILPROG" ]   # If not set, then fetch from LPSODB
    then
	ENV_MAILPROG="`$LPSODBLIST -f $LPSODB -e -v mailprog`"
    fi
    if [ -z "$ENV_MAILPROG" ]   # Still null?  Then we have an error...
    then
	echo
	echo "FAILURE to determine the proper mail program path"
	exit 1
    fi

    if [ -z "$ENV_MAILADMADDRS" ]   # If not set, then fetch from LPSODB
    then
	ENV_MAILADMADDRS="`$LPSODBLIST -f $LPSODB -e -v mailadmaddrs`"
    fi
    if [ -z "$ENV_MAILADMADDRS" ]   # Still null?  Then we have an error...
    then
	echo
	echo "FAILURE to determine the administrative mail address"
	exit 1
    fi
fi

showhelp true "
What command line options are required for the mail program?

Special command line options are required when executing the mail
program ($ENV_MAILPROG) within certain LPS programs and scripts.  If
you specified a non-default mail program in the last question, then
you will want to specify the proper command line options for your
chosen mail program.

Even if you previously chose the default mail program, if you specify
non-default command line options here, then it is possible that
sending mail within the LPS programs and/or scripts will fail.

If you do not accept the default response and choose to specify a
command line options string, please note that you must NOT quote the
string in any way; instead, enter the string exactly as you would if
you were running the mail program yourself during an interactive login
session.

The response to this question is validated by sending \"$ENV_MAILADMADDRS\"
a test mail message.  You do not have to review the test message to
continue the installation; instead, its only purpose is to test the
success of using the command line options with the mail program.

It is STRONGLY RECOMMENDED that you take the default response for this
question."

while true
do
    echo
    $ECHON "Mail program command line options [\"$DEFVAL\"]? "
    read RESPONSE
    if [ -z "$RESPONSE" ] ; then RESPONSE="$DEFVAL" ; fi

    $ECHON "Testing mail program command line options \"$RESPONSE\" ... "

    if $ENV_MAILPROG $RESPONSE -s "Test message" "$ENV_MAILADMADDRS" << EOF

This is a test of sending a mail message using the $ENV_MAILPROG mail
program with command line options of "$RESPONSE" directly from the
$PRODUCT.

You may delete this message at any time.
EOF
    then
	echo "done."
	break
    else
	echo
	echo
	echo "    For some reason the test of the specified command line"
	echo "    options did not succeed.  Please enter different options,"
	echo "    or press CTRL/C to abort the procedure."
    fi
done

echo "$RESPONSE" > $OUTFILE

exit 0
