#!/bin/sh
#
# depagt    This shell script takes care of starting and stopping
#            depagtd (Target On Linux cilent service).
#
# chkconfig: 35 99 99
# description: depagt - Target On Linux client service
# processname: depagtd
### BEGIN INIT INFO
# Provides: depagtd
# Required-Start: $network $syslog
# Required-Stop:
# Default-Start:  3 5
# Default-Stop:   0 1 2 6
# Description:    depagt - Target On Linux client service
### END INIT INFO

BASEDIR=/opt/dpmclient/agent

CHK_SUSELINUX()
{
	local READ_LINE

	if [ -z "$1" ] ; then
		return 0
	fi

	if [ ! -f "$1" ] ; then
		return 0
	fi

	while read READ_LINE ; do

		if [ -f "$READ_LINE" ] ; then
			return 1
		fi

	done < "$1"

	return 0
}

#Module Check
[ -f ${BASEDIR}/bin/depagtd ] || exit 1
[ -f ${BASEDIR}/etc/server.inf ] || exit 1

#
# Check OS Type (Red Hat Linux / SuSE Linux)
#
CHK_SUSELINUX "${BASEDIR}/etc/suse-linux.txt"
if [ $? -eq 0 ] ; then
	#
	# for Red Hat Linux
	#

	# Source function library.
	. /etc/rc.d/init.d/functions

	# See how we were called.
	case "$1" in
	  start)
	        echo -n "Starting depagtd services: "
	        daemon ${BASEDIR}/bin/depagtd

	        echo
	        touch /var/lock/subsys/depagt
	        ;;
	  stop)
	        echo -n "Stopping depagtd services: "
	        killproc ${BASEDIR}/bin/depagtd

	        echo
	        rm -f /var/lock/subsys/depagt
	        ;;
	  status)
	        status ${BASEDIR}/bin/depagtd
	        ;;
	  restart|reload)
	        $0 stop
	        $0 start
	        ;;
	  *)
	        echo "Usage: skelton {start|stop|status|restart}"
	        exit 1
	esac
else
	#
	# for SuSE Linux
	#

	# Shell functions sourced from /etc/rc.status:
	. /etc/rc.status

	# First reset status of this service
	rc_reset

	#Module Check
	[ -f ${BASEDIR}/bin/depagtd ] || exit 1
	[ -f ${BASEDIR}/etc/server.inf ] || exit 1

	# See how we were called.
	case "$1" in
	  start)
	        echo -n "Starting depagtd services: "
	        startproc ${BASEDIR}/bin/depagtd

	        # Remember status and be verbose
	        rc_status -v
	        ;;
	  stop)
	        echo -n "Stopping depagtd services: "
	        killproc ${BASEDIR}/bin/depagtd

	        # Remember status and be verbose
	        rc_status -v
	        ;;
	  status)
	        echo -n "depagtd services: "
	        checkproc ${BASEDIR}/bin/depagtd
	        rc_status -v
	        ;;
	  restart|reload)
	        $0 stop
	        $0 start

	        # Remember status and be quiet
	        rc_status
	        ;;
	  *)
	        echo "Usage: skelton {start|stop|status|restart}"
	        exit 1
	esac
	rc_exit
fi

exit 0
