#!/bin/sh -f
#
# Copyright 1994 Sun Microsystems, Inc. All Rights Reserved.
# Copyright 1993 Sun Microsystems, Inc. All Rights Reserved.
#	This command locates a cmdtool or shelltool and executes
#	its arguments within an invocation of that tool.
#
# @(#)snm_cmdtool	2.22 08/29/94 (c) 1990,1992 Sun Microsystems Inc

#
# figure out which OS we're on
#
os_version=`/bin/uname -r 2>&- | egrep "^5\..|SVR4" 1>&- && echo svr4||echo sunos`
if [ $os_version = "svr4" ]; then
	SNMDIR=/opt/SUNWconn/snm
else
	SNMDIR=/usr/snm
fi

#
# Let SNMCMDTOOL environment variable provide absolute TOOLPATH
#
TOOLPATH="$SNMCMDTOOL"

#
# find snm_exec .. should be in $SNMHOME/bin
#
if [ -f $SNMHOME/bin/snm_exec ]; then
   EXEC="$SNMHOME/bin/snm_exec"
else
   if [ -f $SNMDIR/bin/snm_exec ]; then
      EXEC="$SNMDIR/bin/snm_exec"
   fi
fi


#
# If no TOOLPATH and no OPENWINHOME, try to find an OPENWINHOME
#
if [ "$TOOLPATH" = "" -a "$OPENWINHOME" = "" ]; then
	if [ -d /usr/openwin ]; then
            OPENWINHOME="/usr/openwin"
        elif [ -d /usr/local/openwin ]; then
            OPENWINHOME="/usr/local/openwin"
	fi
fi


#
# If no TOOLPATH, but have OPENWINHOME, try to find a TOOLPATH 
#
if [ "$TOOLPATH" = ""  -a "$OPENWINHOME" != "" ]; then
        if [ -x $OPENWINHOME/bin/cmdtool ]; then
	    TOOLPATH="$OPENWINHOME/bin/cmdtool"
	elif [ -x $OPENWINHOME/bin/xview/cmdtool ]; then
            TOOLPATH="$OPENWINHOME/bin/xview/cmdtool"
        elif [ -x $OPENWINHOME/bin/shelltool ]; then
            TOOLPATH="$OPENWINHOME/bin/shelltool" ]
        elif [ -x $OPENWINHOME/bin/xview/shelltool ]; then
            TOOLPATH="$OPENWINHOME/bin/xview/shelltool" ]
	fi
fi


#
# If still no TOOLPATH, look in misc. places
#
if [ "$TOOLPATH" = "" ]; then
        if [ -x /usr/bin/cmdtool ]; then
            TOOLPATH="/usr/bin/cmdtool"
        elif [ -x /usr/bin/shelltool ]; then
            TOOLPATH="/usr/bin/shelltool"
        fi
fi

if [ "$TOOLPATH" != "" ]; then
	exec $TOOLPATH $EXEC "$@"
else
	echo
	echo "Unable to locate a command tool or shell tool program"
	echo "in which to execute the requested tool."
	echo
	echo "To correct, find a suitable command tool and:"
        echo "  (1) Exit the SunNet Manager Console"
        echo "  (2) Execute:  setenv \$SNMCMDTOOL <toolpath>"
        echo "  (3) Restart the SunNet Manager Console (Execute: snm)"
        echo
fi
