#!/bin/sh
args="$#"
if [ $args -ne  1  ]
then
	echo "Usage /opt/egurkha/bin/auto_restart [ install | uninstall ] "
	return
fi

install_mode=$1
if [  $install_mode = "install"  -o    $install_mode = "uninstall" ]
then
	echo ""
else
	echo "Usage /opt/egurkha/bin/auto_restart [ install | uninstall ] "
	return
fi
userName=`/usr/bin/whoami`
if [ ! $userName = "root"  ]
then
        echo "Current user '$userName' does not have permission to execute this script"
	echo "Only super user can execute this script !"
	return
fi
if [ $install_mode = "install"  ]
then
	cp /opt/egurkha/bin/rc.egurkha /sbin/init.d/egurkha
	chmod 755 /sbin/init.d/egurkha
	## creating links for startup script
	if [ -L "/sbin/rc2.d/K77egurkha" ]
	then
		rm /sbin/rc2.d/K77egurkha 
	fi
	if [ -L "/sbin/rc2.d/S77egurkha" ]
	then
		rm /sbin/rc2.d/S77egurkha 
	fi

	ln -s /sbin/init.d/egurkha /sbin/rc2.d/K77egurkha
	ln -s /sbin/init.d/egurkha /sbin/rc2.d/S77egurkha
	echo "Successfully installed the auto-restart feature for the eG agent "
	return
else
	rm /sbin/rc2.d/K77egurkha
	rm /sbin/rc2.d/S77egurkha
	rm /sbin/init.d/egurkha
	echo "Successfully uninstalled the auto-restart feature for the eG agent "
fi
