#!/bin/ksh
#
# ident "@(#)utctl-shlib.ksh	1.1	05/06/01 SMI"
#
# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

########################################################################
#
# Shared code for the feature scripts.
#
# The feature scripts may override the following variables:
# PARAM - configurable parameters description
# PROG - the program name
#
# The feature scripts must define the following variables:
# DESCR - description for the feature script
#
# NOTE: the parameters must be defined in the feature script before
# sourcing this file.
#
########################################################################

#
# prints the usage message.
# $1 -	exit code. if this is not 0 (success), it will send the output to
#	stderr.
#
Usage() {
	typeset OUT=""

	if [[ $1 -ne 0 ]]; then
		OUT="-u2"
	fi

	print ${OUT} "
	${PROG} [-v] <keyword>

	OPTION:
	-v      # turns on the verbose mode

	KEYWORD:
                # if no keyword is specified, ${PROG} will print description
                # of the feature it manages.
	disable # disables the feature
	enable	# enables the feature
	help	# displays the usage message
	param	# lists the list of configurable parameters
	"
}


#
# help()
#
help() {
	Usage 0
	return 0
}


#
# param()
#
param() {
	print "$PARAM"
	return 0
}


#########################################
#
# Default values for variables that may be overridden by the feature
# script.
#
#########################################

# These variables may be overridden by the feature script.
PARAM=${PARAM:-NONE}
PROG=${PROG:-${0##*/}}


########################################################################
#
# Execution starts here
#

export PATH=/bin:/usr/bin
FEATURE=${PROG#ut}
FEATURE=${FEATURE%ctl}

BASEDIR=`/etc/opt/SUNWut/basedir/lib/utprodinfo -r SUNWuto 2> /dev/null`
BASEDIR=${BASEDIR:-/opt}
SUNWUT=$BASEDIR/SUNWut
SUNWUTLIB=$SUNWUT/lib
SUNWUTETC=/etc/opt/SUNWut
SUNWUTVAR=/var/opt/SUNWut
UTCTLD_CONF=$SUNWUTETC/utctl.conf
OS=`uname -s`
VERB=false

local_variables

if [ -f $UTCTLD_CONF ]; then
	. $UTCTLD_CONF
fi

while getopts :v OPTCH; do
	case "$OPTCH" in
		v)	VERB=true;;
		*)	print -u2 "${PROG}: invalid option $OPTARG"
			Usage 1
			;;
	esac
done
shift `expr $OPTIND - 1`

if [ $# -eq 0 ] ; then
	# print the description
	print "${FEATURE}: $DESCR"
	exit 0
elif [ $# -gt 1 ]; then
	# too many argument
	print -u2 "${PROG}: too many arguments specified"
	Usage 1
fi

case "$1" in
	enable | disable | help | param)
		OPERATION="$1"
		;;
	*)	print -u2 "${PROG}: invalid <keyword> \"$1\""
		Usage 1
		;;
esac
shift 1

eval "$OPERATION"
