#!/bin/sh

echo "This script is to be used to set up a Java-based Application"
echo "Server (Tomcat, Orion, etc.) for monitoring using eG products."
echo " " 
echo "Note: Only the Application Server's administrator has permissions "
echo "to configure the eG monitoring capability for a server."
echo " " 
echo "Do you want to continue  y/n? [y]: \c" > /dev/tty
read data
if [ "$data" = "n" ]
then
	exit 0
fi
appDir=""
while [ -z "$appDir" ]
do
	echo "Please specify the application directory where "
	echo "the Application Server executes JSP pages from:"
	read appDir
done
echo " "
echo "Are you the administrator of this Application Server? y/n [y]: \c"
read accept
if [ -z "$accept" ]
then 
	accept=y
fi
if test  "$accept" != "y" ; 
then
	echo "Please enter the user name of the Application Server's administator: \c"
	read user
	if test -z "$user" 
	then
		echo "Sorry! Invalid user name..."
		exit;
        fi
	echo "Next, you will need to enter the administrator's password ..."	
	su - $user -c "/opt/egurkha/bin/conf_jserver $appDir"
else
	echo "About to configure the Application Server for monitoring ..."
	/opt/egurkha/bin/conf_jserver $appDir
fi

echo " "
echo "If you did not see any errors reported above, your Application Server"
echo "has been successfully configured for monitoring by eG agents!"
