#!/bin/sh


EG_HOME=/opt/egvmagent
export EG_HOME

if [ -f $EG_HOME/tmp/logging ]
then
	rm -f $EG_HOME/tmp/logging 
fi

echo "WELCOME TO JRE UPGRADE" >$EG_HOME/logs/JREupgradeEvent

sleep 30

echo "VMAgent JRE Upgrade started"  >>$EG_HOME/logs/JREupgradeEvent

echo $PATH  >>$EG_HOME/logs/JREupgradeEvent

if [ -d $EG_HOME/jre_new ] 
then

echo "Going to rename Jre folder into egvm_lin_x64_725_1I" >>$EG_HOME/logs/JREupgradeEvent
mv $EG_HOME/jre $EG_HOME/egvm_lin_x64_725_1I 
	if [ $? -ne 0 ]
	then
		echo "Unable to rename jre to egvm_lin_x64_725_1I..." >>$EG_HOME/logs/JREupgradeEvent
	fi
echo "Going to rename jre_new folder into jre" >>$EG_HOME/logs/JREupgradeEvent
mv $EG_HOME/jre_new $EG_HOME/jre
	if [ $? -ne 0 ]
	then
		echo "Unable to rename jre_new to jre..." >>$EG_HOME/logs/JREupgradeEvent
	fi

echo "Copying cacerts file.." >>$EG_HOME/logs/JREupgradeEvent
cp -f $EG_HOME/egvm_lin_x64_725_1I/lib/security/cacerts $EG_HOME/jre/lib/security

fi

if [ ! -d $EG_HOME/jre ]
then
	if [ -d $EG_HOME/egvm_lin_x64_725_1I ]
	then
		mv $EG_HOME/egvm_lin_x64_725_1I $EG_HOME/jre
	fi
fi
if [ -d $EG_HOME/egvm_lin_x64_725_1I ]
then
	rm -rf $EG_HOME/egvm_lin_x64_725_1I
fi


exit

