#! /bin/sh
#
# @(#)showobject	1.8	LPS_UNX_COM	02/19/95
#
# Copyright 1994   Digital Equipment Corporation, Maynard, MA
#
# showobject
#
# This script is used by all top-level management scripts to display
# the specified configuration variables of a defined object of the
# specified class.
#
# The user is queried for the name of the object, which must already exist
# in the LPS Object Database.
#
# Parameters:
#    $1 - Class identifier, one of {ENV, PS, PC, MC}.
#    $2 - Path of the variable list file
#
# Note that this script is not really implemented to handle the ENV class.
#
# Global variables:
#    FUNCS
#    LPSODB
#    LPSODBLIST
#    PAGER
#    TMPDIR
#
# Exit value:
#    0 - Success, the user-specified object was displayed, or the user
#	 entered a null response, implying that the user decided not to
#	 display an object after all.
#    1 - Failure, some sort of error occurred, either with the local
#	 environment (shell variable assignments) or the LPSODB file.
###

CLASS=$1
VARLIST=$2

OUTFILE="$TMPDIR/showobj.$$"

# Import the standard shell function library and export all
# common kit variables for use by our subprocesses.

if . $FUNCS
then
    expkitvars
else
    exit 1
fi

# Resolve the object "description" string for use in the display header

OBJDESC="`getobjdesc $CLASS`"

# Clear the screen and display the standard menu function header

clear

echo
echo "Display the configuration of an existing ${OBJDESC}..."

# Ask the user to select the object to display.  If a null
# response is entered, it implies a return to the top-level
# menu, so simply return success.

if selectobject $CLASS "Which $OBJDESC is to be displayed" $OUTFILE ""
then
    OBJNAME="`cat $OUTFILE`"

    # Clear all existing variables of the target class

    clearobjvars $CLASS

    # Extract the configuration variables of the named object, using the
    # value of the OBJNAME variable as set by the selectobject function.

    if getobject true $CLASS $OBJNAME
    then
	# If this is a PS object, then we must extract the $CONFIG file
	# variables.

	if [ $CLASS = PS ]
	then
	    echo
	    echo "One moment please..."

	    if getPScfgvars "$PS_CONFIGFILE" $OUTFILE
	    then
		. $OUTFILE
	    else
		exit 1
	    fi
	fi

	# Export all object variables of the target class, then
	# display them in the standard manner.

	expobjvars  $CLASS

	if showobjvars $CLASS $OBJNAME $VARLIST > $OUTFILE
	then
	    :
	else
	    $PAGER $OUTFILE
	fi
    fi

    # If we get here, then we lose...

    exit 1
fi

exit 0
