#! /bin/sh
#
# lpsinitodb -- Configure the initial LPS Object Database
#
# @(#)lpsinitodb	1.34	LPS_UNX_COM	4/18/95
#
# Copyright 1995   Digital Equipment Corporation, Maynard, MA
#
# DESCRIPTION:
#
# This script initializes the LPS Object Database from the standard
# GENERIC database file, or reinitializes it if the database file
# already exists.  The user is then allowed to either accept the
# GENERIC/existing values, or interactively specify the value of each
# initial configuration variable.  All initial configuration variables
# comprise most of the attributes of the LPS Environment object.
#
# This script MUST be executed from the "lpsinstall" shell script to
# ensure the operating environment is properly validated and setup.
#
# The current working directory is expected to be the LPSKIT directory,
# and the PATH is expected to be constructed to provide access to all
# kit scripts and utilities.  Also, all common kit variables are
# expected to be set and accessible.
#
# AUTHOR:   JK Martin, Underscore, Inc.
#
# -------------------------------------------------------------------------

# Set all initial variables

ABORT="kill -1 $$"
NOTALLSETS=true
OUTFILE="$TMPDIR/lpsinit.$$"
RESPONSE=""
SCRIPTNAME="lpsinitodb"

#----------------------------------------------------------------------

# Verify that we have been invoked by the "lpsinstall" master shell script.

if [ "$LPSINSTALL" ]
then
    if [ `$PSPID $LPSINSTALL | wc -l` -eq 2 ]
    then
	:
    else
	LPSINSTALL=""
    fi
fi

if [ -z "$LPSINSTALL" ]
then
    echo
    echo '    This script can only be executed by the "lpsinstall" script!'
    exit 1
fi

export LPSINSTALL

#----------------------------------------------------------------------

# Setup activities to be executing upon encountering certain signals

trap 'echo ; \
      echo The LPS Object Database file \($LPSODB\) was NOT written. ; \
      rm -f $TMPDIR/*.$$ ; \
      rm -f /tmp/*.$$ ; \
      rm -f ./*.$$ ; \
      exit 1' \
      1 2 3 15

#----------------------------------------------------------------------

# Load the common LPS shell script functions.  The lpsinstall script
# ensures that this file exists and is executable by this process.

. $FUNCS

# Export all variables that may be required by subscripts and utilities

expkitvars

#----------------------------------------------------------------------

# showvars()
#
# A shell function to display all Environment configuration variables
# (ie, all variables with the "ENV_" prefix) currently set within the
# process.
#
# This function depends on the following variables in order to filter
# exactly what is displayed:
#    KITTYPE
#    NEEDACCT
#    NEEDPCACCT
#    PCTYPE
#    SHKIT
#
# Output is to stdout, so redirect or pipe as necessary.
# Return value is always 0.

showvars ()
{
    cat <<END_OF_INPUT

Current values of the LPS Environment configuration variables
for $PRODUCT on ${LOCALHOST}:

  DIRECTORIES:
    LPS kit (LPSKIT):              $ENV_LPSKIT
    LPS root (LPSROOT):            $ENV_LPSROOT
    LPS system programs (LPSBIN):  $ENV_LPSBIN
    LPS library files (LPSLIB):    $ENV_LPSLIB
    LPS documentation (LPSDOC):    $ENV_LPSDOC
    Image files (LPSIMAGES):       $ENV_LPSIMAGES
    LPS user programs (LPSUSR):    $ENV_LPSUSR
    Temporary files (LPSTMP):      $ENV_LPSTMP
    Error/log files (LPSLOG):      $ENV_LPSLOG
END_OF_INPUT

    if $NEEDACCT
    then
	echo "    Accounting files (LPSACCT):    $ENV_LPSACCT"
    fi

    if $SHKIT
    then
	echo "    Network boot files (LPSBOOT):  $ENV_LPSBOOT"
    fi

    if [ "$PCTYPE" = "BSD" ]
    then
	echo "    Spool directories (TOPQDIR):   $ENV_TOPQDIR"
    fi

    cat <<END_OF_INPUT

  PRINT CLIENT OPTIONS:
    Enable ANSI translation:       $ENV_ENABLEANSI
    Default page width:            $ENV_PAGEWIDTH
    Default page length:           $ENV_PAGELENGTH
    Enable offset stacking:        $ENV_OFFSETSTACK
    Enable banner page printing:   $ENV_ENABLEBANNERS
    Banner input tray:             $ENV_BANNERTRAY
    Enable banner images:          $ENV_ENABLEIMAGES
    Banner image file suffix:      $ENV_IMAGESUFFIX
    Supervisor connection name:    $ENV_PCSUPERNAME
END_OF_INPUT

    if [ "$PCTYPE" != "BSD" ]
    then
	echo "    Problem notification method:   $ENV_NOTIFYSTYLE"
    fi

    if $NEEDPCACCT
    then
	echo "    Accounting units:              $ENV_ACCTUNIT"
    fi

    echo
    echo "  GENERAL CLIENT/SERVER OPTIONS:"

    if $SHKIT
    then
	echo "    Booting options:               $ENV_BOOTOPTIONS"
    fi

    if $NEEDPCACCT
    then
	echo "    Enable accounting:             $ENV_ENABLEACCT"
    fi

    cat <<END_OF_INPUT
    Enable logging:                $ENV_ENABLELOG
    Default logging level:         $ENV_LOGLEVEL
    Default debug level:           $ENV_DEBUGLEVEL
    Default file I/O buffer size:  $ENV_IOBUFSIZE
END_OF_INPUT

    cat <<END_OF_INPUT

  ELECTRONIC MAIL:
    Administrative mail address:   $ENV_MAILADMADDRS
    Mail addressing style:         $ENV_MAILSTYLE
    Mail program:                  $ENV_MAILPROG
    Mail command line options:     $ENV_MAILOPTS

END_OF_INPUT
    return 0
} 

#----------------------------------------------------------------------

# See if a $LPSODB file already exists, and if so, then ask if this file
# should be used to initialize the database values.  This allows for a
# rapid, convenient way for the user to change just a few variables,
# accepting the established values for all others.
#
# Since overwriting an existing $LPSODB file can be catastrophic, the
# user is warned of this fact and given an opportunity to view the
# current file and bail out, if necessary.
#
# If the user wants to use the existing $LPSODB file as a starting point,
# then the $USEGENERIC variable is set to false to indicate that fact.
#
# The SAVEOLDDEFS variable is used to control the preservation of existing
# object definitions and their reincorporation into the new database file.

USEGENERIC=true
SAVEOLDDEFS=false

if [ -f $LPSODB ]
then
    echo ""
    $PAGER <<END_OF_INPUT

			   --- W A R N I N G ---

    The LPS Object Database file ($LPSODB) already exists.

    You must now choose one of the following options:

	1) Use the existing Environment values, and either preserve or
	   remove the existing Print Client, PrintServer printer and
	   Management Client definitions

	2) Reinitialize the existing database, using either the existing
	   LPS Environment values or the generic values

	3) Quit the installation.

    If you choose to use the existing Environment values, then you will be
    given the opportunity to either preserve or remove the other
    definitions.  Note that if you preserve all definitions, then the
    definitions are left intact; no updates are made to any of the values
    for any of the definitions, with the exception of minor, non-critical
    informational values (such as the system version number).

    If you choose to reinitialize the existing database, then all
    information for any currently defined Print Clients, Management Clients
    and/or PrintServer printers will no longer be available to the
    PrintServer system, forcing you to redefine each Client or Server.  If
    one or more Print Clients are currently defined, then those Print
    Clients will repeatedly fail until the LPS Object Database has been
    updated to redefine those Print Clients.  Similar problems will arise
    with any Management Clients currently defined.

    If you choose to update the existing database file, then the current
    version will be renamed to preserve its contents.  Renaming the current
    database file will occur at the last possible moment, just in case you
    decide not to reinitialize this CRITICAL database file.
END_OF_INPUT

    if yesno y "Do you wish to examine the existing database file"
    then
	getobject false ENV
	showvars | $PAGER
    fi

    if yesno y "Do you wish to use the existing database values"
    then
	USEGENERIC=false   # Critical variable setting!!!

	# If the existing database is to be used, then see if any
	# other object types are currently defined.  If so, then
	# inform the user that other object types are currently
	# defined, then ask if those definitions should be preserved
	# and appended to the final database.

	oldpss="`$LPSODBLIST -f $LPSODB -c PS`"
	oldpcs="`$LPSODBLIST -f $LPSODB -c PC`"
	if $SHKIT ; then oldmcs="`$LPSODBLIST -f $LPSODB -c MC`" ; fi

	if [ "$oldpss" -o "$oldpcs" -o "$oldmcs" ]
	then
	    echo
	    echo "The current database contains one or more definitions"
	    echo "other than just the LPS Environment.  Here are the names"
	    echo "of the various objects currently defined:"
	    echo
	    $ECHON "PrintServer printers: "
	    if [ "$oldpss" ] ; then echo $oldpss ; else echo "[none]";fi
	    $ECHON "Print Clients:        "
	    if [ "$oldpcs" ] ; then echo $oldpcs ; else echo "[none]";fi
	    if $SHKIT
	    then
		$ECHON "Management Clients:   "
		if [ "$oldmcs" ] ; then echo $oldmcs ; else echo "[none]";fi
	    fi

	    if yesno y "Do you wish to preserve all definitions"
	    then
		SAVEOLDDEFS=true
		OLDDEFS="$TMPDIR/olddefs.$$"
		if sed -e '/^#/,/[^\\]$/d' $LPSODB | sed -e '/^LPSENV[:|]/,/[^\\]$/d' > $OLDDEFS
		then
		    :
		else
		    cat << END_OF_INPUT

    A problem was encountered while attempting to extract the current
    database definitions.  Please try to solve this problem, then re-run
    this procedure.
END_OF_INPUT
		    $ABORT
		fi
	    fi
	fi
    else
	if yesno n "Do you wish to reinitialize the existing database file"
	then
	    if yesno x "Are you ABSOLUTELY sure"
	    then
		if yesno y "Use the existing Environment database values as defaults"
		then
		    USEGENERIC=false
		fi
	    else
		$ABORT
	    fi
	else
	    $ABORT
	fi
    fi
else
    if [ ! -r $LPSODBGENERIC ]
    then
	cat <<END_OF_INPUT

    For some reason the GENERIC version of the LPS Object Database
    file ("$LPSODBGENERIC") either does not exist
    or is not readable by your process.

    Please try to solve this problem, then re-run this procedure.
END_OF_INPUT
	$ABORT
    fi
fi

#----------------------------------------------------------------------

# Determine which database file will be used to initialize the LPS
# Environment variables, then import those values into our process.
#
# No matter which database file is used for the initial values, the
# LPSKIT variable is *always* reset to the current working directory.
#
# NOTE:	This is a key location where various platform-specific
#	and LPS version-specific information is handled for
#	setting up the initial Environment object definition.

if $USEGENERIC
then
    ODBFILE=$LPSODBGENERIC
else
    ODBFILE=$LPSODB
fi

if [ "$LPSDEBUG" ]
then
    echo "[Will initialize the LPSODB file with: $ODBFILE]"
fi

if $LPSODBLIST -f $ODBFILE -e -B > $TMPDIR/lpsodb.$$
then
    :
else
    cat <<END_OF_INPUT

    There is a problem with the LPS Object Database file to be
    used for the initialization ($ODBFILE).

    Please try to solve this problem, then re-run this procedure.
END_OF_INPUT
    $ABORT
fi


# Import the variable definitions just created by lpsodblist,
# then reset a few that need to be manually "adjusted" due to
# local conditions.

. $TMPDIR/lpsodb.$$

ENV_LPSKIT=`pwd`

expobjvars ENV

#----------------------------------------------------------------------

# Perform any required special changes to the GENERIC database
# values IFF we are reading in the GENERIC file.  These variables
# are initialized based on the kit-specific variables that should
# have already been read and set by lpsinstall.

if $USEGENERIC
then
    ENV_ACCTUNIT="$ACCTUNIT"
    ENV_LPSACCT="$LPSACCT"
    ENV_LPSLOG="$LPSLOG"
    ENV_MAILPROG="$MAILPROG"
    ENV_MAILOPTS="$MAILOPTS"
    ENV_OSNAME="$OSNAME"
    ENV_OSTYPE="$OSTYPE"
    ENV_OSVER="$OSVER"
    ENV_PCSUPERNAME="${OSNAME}-connect"
    ENV_PCTYPE="$PCTYPE"
    ENV_PLATFORM="$PLATFORM"
    ENV_PRODUCT="$PRODUCT"
    ENV_TOPQDIR="$TOPQDIR"

    # !!! Perform any last-minute platform- or kit-specific hack here !!!

    if $SHKIT
    then
	ENV_BOOTOPTIONS=`chkboot -s`
    fi
fi

#----------------------------------------------------------------------

# SUBNETMASK
#
# The SUBNETMASK attribute is now silently acquired from the local
# host, without intervention by the user, through the LPS getnetmask
# utility.

if $SHKIT
then
    echo
    $ECHON "Determining subnet mask for \"$LOCALHOST\" interface..."
fi

if ENV_SUBNETMASK=`getnetmask`
then
    echo "done."
else
    cat << ENDOFINPUT

    [Attempt to get '$LOCALHOST' subnet mask failed]
    [Continuing installation...]

ENDOFINPUT
    pause
fi

echo

#----------------------------------------------------------------------

# createodb()
#
# A shell function to create the initial LPSODB, using the mklpsodb
# script to do most of the work.
#
# This function should be invoked as the very last thing to be done
# in this script before it exits.
#
# If the user previously chose to save the existing object definitions,
# then those are appended to the new version of the file.

createodb ()
{
    echo
    echo "Creating the LPS Object Database file ($LPSODB)..."

    OFILE=$TMPDIR/crodb.$$	# The fully created LPSODB file

    rm -f $OFILE

    oksofar=true

    if [ -f $LPSODB ]
    then
	old=${LPSODB}.OLD
	echo "    The existing $LPSODB file will be renamed"
	echo "    to $old for future reference."
	echo

	if [ -f $old ]
	then
	    echo "    [Preserving previous versions of $old first...]"

	    if savefile $old
	    then
		:
	    else
		echo
		echo "    Unable to preserve $old file!"
		oksofar=false
	    fi
	fi

	if mv $LPSODB $old
	then
	    :
	else
	    echo
	    echo "    Unable to rename $LPSODB to $old"
	    oksofar=false
	fi
    fi

    if $oksofar && mklpsodb $LPSODB $OFILE $OLDDEFS
    then
	:
    else
	oksofar=false
    fi

    if $oksofar
    then
	# The LPSODB file has been created, so create a highly readable
	# description of the initial database values for later use in
	# mailing to the designated driver by the lpsinstall script.

	showvars > $ODBMSG

	# We're all done, so declare success.  Then, if the binaries were
	# requested for only the local system, ensure that a $BINROOT file
	# no longer exists from a (potentially) previous execution of this
	# script.

	echo
	echo "The initialization of the LPS Object Database is complete."
	echo

	if $NOTALLSETS
	then
	    rm -f $BINROOT
	fi

	return 0
    else
	$PAGER <<END_OF_INPUT

    A problem has been encountered while attempting to create the
    final form of the LPS Object Database file ($LPSODB).

    Please try to solve this problem, then re-run this procedure.
    In the meantime, a copy of the database containing all values
    defined during this session will be stored in $OFILE.
    If you copy this file to $LPSODB and set its protection (mode)
    to 755, then you will not have to re-run this procedure.
END_OF_INPUT
	return 1
    fi
}

#----------------------------------------------------------------------

# revector()
#
# A shell function to potentially change all paths that are based (rooted)
# on the LPSROOT definition when the LPSROOT definition is changed to the
# specified path.
#
# The only parameter is the new path.
#
# If it is determined that the new path is equivalent to the current path
# (via resolution of symbolic links), then the return value is 1.  Otherwise,
# a real change in paths results in a return value of 0.

revector ()
{
    newroot="$1"

    if linkcheck $LINKCHECKOPTS $newroot $ENV_LPSROOT
    then
	rc=1
    else
	rc=0
    fi

    ENV_BANNERFILE="`resetpath      $newroot $ENV_LPSROOT $ENV_BANNERFILE`"
    ENV_CONFIGFILE="`resetpath      $newroot $ENV_LPSROOT $ENV_CONFIGFILE`"
    ENV_DEFAULTSFILE="`resetpath    $newroot $ENV_LPSROOT $ENV_DEFAULTSFILE`"
    ENV_ERRORFILE="`resetpath       $newroot $ENV_LPSROOT $ENV_ERRORFILE`"
    ENV_FILEMAPFILE="`resetpath     $newroot $ENV_LPSROOT $ENV_FILEMAPFILE`"
    ENV_LPSBIN="`resetpath          $newroot $ENV_LPSROOT $ENV_LPSBIN`"
    ENV_LPSDOC="`resetpath          $newroot $ENV_LPSROOT $ENV_LPSDOC`"
    ENV_LPSFILES="`resetpath        $newroot $ENV_LPSROOT $ENV_LPSFILES`"
    ENV_LPSFONTS="`resetpath        $newroot $ENV_LPSROOT $ENV_LPSFONTS`"
    ENV_LPSIMAGES="`resetpath       $newroot $ENV_LPSROOT $ENV_LPSIMAGES`"
    ENV_LPSLIB="`resetpath          $newroot $ENV_LPSROOT $ENV_LPSLIB`"
    ENV_LPSSERVERS="`resetpath      $newroot $ENV_LPSROOT $ENV_LPSSERVERS`"
    ENV_LPSSYS="`resetpath          $newroot $ENV_LPSROOT $ENV_LPSSYS`"
    ENV_PCLDEFAULTSFILE="`resetpath $newroot $ENV_LPSROOT $ENV_PCLDEFAULTSFILE`"
    ENV_RESOURCES="`resetpath       $newroot $ENV_LPSROOT $ENV_RESOURCES`"
    ENV_SETUPFILE="`resetpath       $newroot $ENV_LPSROOT $ENV_SETUPFILE`"
    ENV_SYSPARAMSFILE="`resetpath   $newroot $ENV_LPSROOT $ENV_SYSPARAMSFILE`"
    ENV_ASC2PSPRO="`resetpath       $newroot $ENV_LPSROOT $ENV_ASC2PSPRO`"

    ENV_LPSROOT=$newroot

    return $rc
} 

#----------------------------------------------------------------------

# Determine where the kit should be installed (LPSROOT path) IFF the
# the GENERIC database values are to be used.  If the existing
# database is to be used, then we skip over this section.
#
# By default, if the kit is NOT located on a read-only device (eg,
# CD-ROM), then the kit is installed "in situ" (right in place); that
# is, LPSROOT == LPSKIT.  If lpsinstall has told us that the kit tree
# is writable, then LPSROOT is defined to be LPSKIT.  If the kit tree
# is NOT writable, then we retain the value as obtained from the
# GENERIC database file.

if $USEGENERIC
then
    if $WRITABLE_KIT
    then
	revector $ENV_LPSKIT
    else
	if [ "$LPSDEBUG" ]
	then
	    echo
	    echo "[-- The kit resides on a read-only filesystem --]"
	    echo "[-- No revectoring of LPSROOT will be performed --]"
	    echo
	fi
    fi

    question="Where should the PrintServer Software be installed"

    showhelp true "
${question}?

The PrintServer Software can be installed into a directory tree
different from the directory used to load the software distribution
kit.  The root of this installation directory tree is referred to as
the \"LPS root directory\", or simply the \"LPSROOT\" directory.

The LPSROOT directory may be located in a filesystem that is not
expected to significantly increase in size over time.  Note, however,
that subsequent configurations of Print Servers and Management Clients
may require the creation of certain configuration files, so the
filesystem containing the LPSROOT directory should not be defined
within a read-only filesystem.

If the directory specified for LPSROOT does not exist, it will be
created after you have completely initialized the LPS Object Database.

The LPSROOT directory can be the same as the directory used to load
the $PRODUCT kit from the distribution media if you are not loading
from CD-ROM.  This load directory is commonly referred to as the
\"LPSKIT\" directory.  At the moment, the LPSKIT directory is defined
as your current working directory ($ENV_LPSKIT)."

    getpath z $ENV_LPSROOT "LPS root directory"

    # We must now determine if the resulting LPSROOT path is different than
    # the current $ENV_LPSROOT value.  If the path is different, then each
    # variable defining a directory path is potentially "revectored" to use
    # the newly specified LPSROOT path as the path "stem" if that directory
    # path was directly related to the old LPSROOT value.

    if [ "$RESPONSE" != "$ENV_LPSROOT" ]
    then
	if revector $RESPONSE
	then
	    :
	else
	    $ABORT
	fi
    fi
fi

#----------------------------------------------------------------------

# Determine if the current database values (GENERIC or existing) are
# acceptable.  If so, then the database is immediately created based
# on the current values, and we're done.
#
# Otherwise, the user proceeds to configure the Environment, with
# default values coming from the GENERIC database file.
#
# Alternatively, if the existing $LPSODB file is used, remind the user
# of that fact (ie, that the displayed values do not necessarily
# represent a GENERIC configuration).

if $USEGENERIC
then
    showhelp true "
The initial state of the LPS Object Database can be configured in a
GENERIC manner using definitions suitable for your type of system.
The database variables displayed below are grouped by functional area.

These variables represent the initial values for the LPS Environment
and are used to assist in later configurations of Print Client,
Management Client and Print Server printer components.  When these
components are configured, you will be given the opportunity to
override the any default values taken from the LPS Environment.

You can choose to either accept these Environment definitions and
configure a standard, GENERIC installation, or you can individually
define each of the initial configuration variables.  If you are unsure
about your site's specific needs, it is STRONGLY RECOMMENDED that you
choose the GENERIC configuration for your system.  A GENERIC
configuration will facilitate technical support should you encounter
problems in getting your system running.
"
    type="generic"
else
    showhelp true "

The LPS Object Database has already been configured on your system.
You can either accept the current configuration variable values, or
individually define each of the variables.
"
    type="existing"
fi

pause "Press RETURN to view the $type database values... "
clear
showvars | $PAGER  # Display the set of Environment variables and their values

if yesno y "Do you wish to use these configuration variable values"
then
    createodb
    exit	# Use return value from createodb() as the exit value
fi

#----------------------------------------------------------------------

# Configure all Environment variables that are accessible (that is,
# "visible") to the user. To do this, we use a "Vlist" file in a
# manner analogous to managing Clients & Servers; however, unlike
# Clients and Servers, the Vlist for an Environment is constructed on
# the fly from the concatenation of a "common" variable set and a
# PCTYPE-specific set.
#
# Note that most of the "GROUP"-related stuff was lifted right out
# of the setPCvars script, so see that script for details on this
# mechanism.

VARLIST=$TMPDIR/vlist.env

cat Vlist.ENV.COM Vlist.ENV.$PCTYPE | sed -n '/^[^#].*/p' > $VARLIST

G_BANNERS="BANNERFILE ENABLEIMAGES BANNERTRAY"   # Control: ENABLEBANNERS
G_IMAGES="LPSIMAGES IMAGESUFFIX"		 # Control: ENABLEIMAGES
G_LOGGING="LOGFILE LOGLEVEL DEBUGLEVEL"		 # Control: ENABLELOG
G_ACCTING="ACCTFILE ACCTUNIT"			 # Control: ENABLEACCT

GROUPS="G_BANNERS G_IMAGES G_LOGGING G_ACCTING"

CONFIGERROR="FAILURE to properly set a Environment configuration variable!!!"

PSMODEL="LPS32"	        # Use LPS32 so as to make all tray options available
defmode="step-by-step"	# Default for first time is "step-by-step" config mode

rm -f $OUTFILE		# Temporary file used by subscripts to return values

while true	# --- Top of the configuration loop ---
do
    list="step-by-step menu-oriented"
    quest="How do you want to configure the Environment"

    choose "$defmode" "$quest" $list

    defmode="menu-oriented"  # If we do this again, default to "menu-oriented"

    if [ "$RESPONSE" = "step-by-step" ]   # --- Step-by-step starts here
    then
	for var in `cat $VARLIST`
	do
	    # See if this var should be skipped due to the disabling
	    # of a related control var.

	    for group in $GROUPS
	    do
		eval grouplist="\$$group"
		if expr "$grouplist" : ".*$var" > /dev/null 2>&1
		then
		    case $group in
			G_BANNERS ) if boolval $ENV_ENABLEBANNERS
				    then break ; else continue 2; fi ;;
			G_IMAGES  ) if boolval $ENV_ENABLEBANNERS &&
				       boolval $ENV_ENABLEIMAGES
				    then break ; else continue 2; fi ;;
			G_LOGGING ) if boolval $ENV_ENABLELOG
				    then break ; else continue 2; fi ;;
			G_ACCTING ) if boolval $ENV_ENABLEACCT
				    then break ; else continue 2; fi ;;
		    esac
		fi
	    done

	    eval val="\"\$ENV_$var\""   # Resolve the var's current value

	    script=`echo set$var | cut -c1-14`   # Resolve script filename

	    if $script ENV $OSTYPE $PCTYPE "$PSMODEL" "$val" $OUTFILE
	    then
		var="ENV_$var"
		val="`cat $OUTFILE`"
		eval $var="\"$val\""
	    else
		echo
		echo $CONFIGERROR
		$ABORT
	    fi
	done

	echo
	pause "Press RETURN to view the complete Environment configuration... "

	showvars | $PAGER

    else   # --- Menu-oriented configuration starts here ---

	while true
	do
	    if objvarmenu ENV "($LOCALHOST)" $VARLIST $OUTFILE
	    then
		break   # Break out of inner loop
	    else
		var="`cat $OUTFILE`"
		eval val="\"\$ENV_$var\""

		script=`echo set$var | cut -c1-14`   # Resolve script filename

		if $script ENV $OSTYPE $PCTYPE "$PSMODEL" "$val" $OUTFILE
		then
		    val="`cat $OUTFILE`"
		    eval var="ENV_$var"
		    eval $var="\"$val\""
		else
		    echo
		    echo $CONFIGERROR
		    exit 1
		fi
	    fi
	done
    fi

    if yesno x "Are the current set of Environment values acceptable"
    then
	break   # Break out of outer loop
    fi

done	# --- Bottom of configuration loop ---

rm -f $OUTFILE

#----------------------------------------------------------------------

# Make any last minute changes to the Environment configuration here.
#
# Some files depend on the LPSLIB definition; such files were not part
# of the Environment configuration procedure, so we forcibly set their
# full paths according to the final definition of the LPSLIB variable.

ENV_ASC2PSPRO=$ENV_LPSLIB/lpsasc2ps.psh
ENV_BANNERFILE=$ENV_LPSLIB/bannerPage.psh
ENV_ERRORFILE=$ENV_LPSLIB/errorPage.psh

#----------------------------------------------------------------------

# Finally, create the LPS Object Database as configured by the user

if createodb
then
    exit 0
fi

exit 1		# LPSODB creation error if we get here


#----------------------------------------------------------------------
#
# Local Variables:
# fill-column:70
# page-delimiter:"^#---"
# End:
