#!/bin/bsh
# IBM_PROLOG_BEGIN_TAG 
# This is an automatically generated prolog. 
#  
# onc720 src/oncplus/usr/sbin/sysmgt/lsclient.sh 1.6 
#  
# Licensed Materials - Property of IBM 
#  
# COPYRIGHT International Business Machines Corp. 1997,2008 
# All Rights Reserved 
#  
# US Government Users Restricted Rights - Use, duplication or 
# disclosure restricted by GSA ADP Schedule Contract with IBM Corp. 
#  
# IBM_PROLOG_END_TAG 

set -f			# this is so that the case statement will work

# Set the default printing format
FORMAT="colon"

COMMAND_NAME=`/usr/bin/basename $0`

USAGE="
usage:  ${COMMAND_NAME}	[ -c | -l ]\n"


case "$#" in
	"0")
		FORMAT="long"
		;;
	"1")
		if [ "$1" = "-c" ] ; then
			FORMAT="colon"
		elif [ "$1" = "-l" ] ; then
			FORMAT="long"
		else
			/usr/bin/dspmsg cmdnfs.cat -s 37 3 "$USAGE"
			exit
		fi
		;;
	*)
		/usr/bin/dspmsg cmdnfs.cat -s 37 3 "$USAGE"
		exit
		;;
esac

NOW="no"
IPL="no"
WHEN=""
SERVER=""

/usr/bin/ypwhich >/dev/null 2>&1
if [ $? = 0 ]
then
    NOW="yes"
fi

YPLINE=`/usr/bin/grep "start ypbind /usr/lib/netsvc/yp/ypbind" /etc/rc.nfs`
if [ "$YPLINE" != "" ]
then
    echo $YPLINE | /usr/bin/grep -q "#"
    if [ $? != 0 ]
    then
	IPL="yes"
    fi
fi


if [ "$IPL" = "yes" ]
then
    /usr/bin/lssrc -S -s ypbind | /usr/bin/grep -q ypsetme
    if [ $? = 0 ]
    then
	SERVER=`/usr/bin/grep /usr/sbin/ypset /etc/rc.nfs | /usr/bin/awk '{ print $2 }'`
    fi
else
    /usr/bin/ps -ef | /usr/bin/grep ypbind | /usr/bin/grep -q ypsetme
    if [ $? = 0 ]
    then
	/usr/bin/ypwhich > /dev/null 2>&1
	SERVER=`/usr/bin/ypwhich`
	N=`echo $SERVER | /usr/bin/wc -w`
	if [ $N != 1 ]
	then
	    SERVER=""
	fi
    fi
fi

if [ $IPL = "yes" ]
then
    if [ "$NOW" = "yes" ]
    then
	WHEN="both"
	MESSGAE="ypbind is currently running and will be restarted at system reboot.\n"
	MSGID=49
    else
	WHEN="restart"
	MESSAGE="ypbind will be started at system reboot.\n"
	MSGID=50
    fi
else
    if [ "$NOW" = "yes" ]
    then
	WHEN="now"
	MESSAGE="ypbind is currently running but will not be restarted at system reboot.\n"
	MSGID=51
    else
	WHEN="both"
	MESSAGE="This system is not configured to run ypbind.\n"
	MSGID=54
    fi
fi


if [ "$FORMAT" = "colon" ]
then
    TRANSLATED_STR=`/usr/bin/dspmsg smit.cat -s 39 278 "both,restart,now"`
    # WHEN string needs to be translated so that SMIT receives correct lang vers
    case $WHEN in
        both)
                xlate_WHEN=`echo $TRANSLATED_STR | /usr/bin/cut -d "," -f 1`
                ;;
        restart)
                xlate_WHEN=`echo $TRANSLATED_STR | /usr/bin/cut -d "," -f 2`
                ;;
        now)
                xlate_WHEN=`echo $TRANSLATED_STR | /usr/bin/cut -d "," -f 3`
                ;;
        *)      xlate_WHEN=$WHEN
                ;;
    esac

    echo "#when:server"
    echo ${xlate_WHEN}:${SERVER}
else
    /usr/bin/dspmsg cmdnfs.cat -s 37 $MSGID "$MESSAGE"

    if [ $MSGID != 54 ]
    then
	if [ "$SERVER" = "" ]
	then
	    /usr/bin/dspmsg cmdnfs.cat -s 37 52 "A NIS server will be found by broadcasting.\n"
	else
	    /usr/bin/dspmsg  cmdnfs.cat -s 37 53 "%s is the NIS server.\n" $SERVER
	fi
    fi
fi

exit 0