#!/bin/sh

myfile=iAgent_hpux_itanium


currentUser=`whoami`
if [ "$currentUser" != "root" ]
then
        echo "******************************************************************************"
        echo "This script can only be run by the root user. Exiting ..."
        echo "******************************************************************************"
        exit
fi

eGuser=egurkha
#eG user - please make sure that the user account exists

eGgroup=egurkha
#eG user's group

eGInstallDir=/opt
#eG install directory

autoRestart=y
#whether the agent should auto-restart

licenseAcceptance=y
#licenseAcceptance the license

eGManager=192.168.10.54
#eG manager host

eGManagerPort=7077
#eG manager port

useProxy=n
#use Proxy?

proxyHost=xxx
#proxy server

proxtPort=8080
#proxy port

setAuthentication=n
#use auhentication for proxy?

proxyUsername=none
#user name for proxy access - none

proxyPassword=none
#password for proxy access

useSSL=n
#use SSL for communication with the manager? y/n

trustedCertificates=n
#use trusted certificates for SSL communication with the manager? y/n

setNickName=n
#set the nickname for the agent - y/n

nickNameToUse=`hostname`
#the nick name to set for this agent

count=`grep "^$eGuser:" /etc/passwd | wc -l`
if [ $count -eq 0 ]
then
	echo "********************************************************************************"
	echo "Sorry. User '$eGuser' does not exist."
	echo "Please create this user account and start the silent install of the eG Agent"
	echo "********************************************************************************"
	exit
fi

count=`grep "^$eGgroup:" /etc/group | wc -l`
if [ $count -eq 0 ]
then
	echo "********************************************************************************"
	echo "Sorry. Group '$eGgroup' does not exist."
	echo "Please create this group and start the silent install of the eG Agent"
	echo "********************************************************************************"
	exit
fi


#run iAgent first
chmod +x $myfile
`pwd`/$myfile $eGuser $eGgroup $eGInstallDir $autoRestart >/dev/null 

monitorColdfusion=n
#monitor coldfusion servers?
monitorSybase=n
#monitor sybase servers?
# silent install for coldfusion and sybase is not handled here - pls manually configure these servers

#run setup_agent next
chmod +x /opt/egurkha/bin/setup_agent
su - $eGuser -c "/opt/egurkha/bin/setup_agent $licenseAcceptance $eGManager $eGManagerPort $useProxy $proxyHost $proxtPort $setAuthentication $proxyUsername $proxyPassword $useSSL $trustedCertificates $setNickName $monitorColdfusion $monitorSybase $eGuser $eGgroup $nickNameToUse" > /dev/null

#now start the agent
su - $eGuser -c /opt/egurkha/bin/start_agent

echo "eG Agent installation and start-up completed."

