#! /bin/sh
### BEGIN INIT INFO
# Provides:          revepupdateD
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: revepupdate
# Description:       Start Stop revepupdate
### END INIT INFO
# Check root user.

BASE=/usr/local/reveantivirus/bin
NAME=revepupdateD
BNAME=revepupdate
DAEMON=${BASE}/revepupdate
SCRIPTNAME=/etc/init.d/$NAME
pidFPath=/usr/local/reveantivirus/conf/.pupdate.pid
start()
{
	isProc=`pidof $BNAME`
	isProcVal=`expr $isProc + 1`
	if [ $isProcVal -gt 1 ];
	then
		echo "$NAME is already running"
	else
		sleep 1
		startproc $DAEMON
	        sleep 1
		echo "$BNAME started"
	fi
}
stop()
{
	if [ -f "$pidFPath" ];
	then
	rm $pidFPath
	killproc $DAEMON > /dev/null
	sleep 2
	fi

	isProc=`pidof $BNAME`
	isProcVal=`expr $isProc + 1`
	if [ $isProcVal -gt 1 ];
	then
		kill -9 $isProc > /dev/null
		sleep 3
	fi
}

status()
{
	checkproc $DAEMON
}
restart()
{
	stop
	sleep 5
	start
	echo "$NAME Service restarted"
}
if [ $(id -u) -ne 0 ]
then
        if [ "$1" != "start" -a "$1" != "stop" -a "$1" != "status" ];
        then
                echo "Usage: {start|stop|restart|status}" >&2
                exit 0
        fi

        if [ "$1" != "status" ]
        then
                echo "You are not root user. Please login as root user.";
                exit 0
        fi
fi
if [ ! -f $DAEMON ]; then
	exit 0
fi
# Setting HOME
[ -f /etc/default/revedefault ] && . /etc/default/revedefault

if [ -z "$GUICONFIG" ] ;  then
  echo "Gui Config is not set, please set it in /etc/default/revedefault" >&2
  exit 1
fi


check_process()
{
    # Check if the process is already running. Ignore grep line.
    result=`ps aux | grep "$BNAME" | grep -v grep | wc -l`
}
# Load the VERBOSE setting and other rcS variables
[ -f /etc/default/rcS ] && . /etc/default/rcS

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
. /lib/lsb/init-functions

PATH="/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/usr/local/sbin:/usr/local/reveantivirus/bin"
 export DISPLAY=:0
 export XAUTHORITY=$GUICONFIG

case "$1" in
start)
     start
     ;;
stop) 
    stop
    ;;

status)
    status
    ;;
restart)
    restart
    ;;
*)
   echo "Usage: $SCRIPTNAME {start|stop|restart|status}"
   exit 1
esac
:
