#!/bin/bash
#
# startup script for the Argos
# Author: Maros Barabas <ibarabas@fit.vutbr.cz>
#
# description: Argos is Qemu based high-interaction honeypot for
#	       automatically detecting zero-day attacks
# processname: /opt/argos/bin/argos
# config: (no config)
# pidfile: (no pidfile)

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

start() {
	echo $IMAGE
        echo -n $"Starting $prog: "
	[ -x $argos ] || exit 1
	[ -f $IMAGE ] || exit 2
	if [ -f $lockfile ]; then
		failure $"Argos startup"
		echo
		status $argos
		exit 3
	fi
	cd ${LOGPATH}
        $argos $OPTIONS 2>&1 >>${LOG} &
        RETVAL=$?
	${PATH_SCRIPTS}/run_tcpdump.sh $IFNAME &>/dev/null
	RETVALI=$?
        [ $RETVAL = 0 ] && [ $RETVALI = 0 ] && touch ${lockfile}
	success $"Argos startup"
        echo
        return $RETVAL
}

stop() {
	echo -n $"Stopping $prog: "
	killproc $argos
	RETVAL=$?
        PID=`ps aux | grep tcpdump | grep $IFNAME | awk '{print $2}'`
        [ "x$PID" != "x" ] && kill -9 $PID
	echo
	[ $RETVAL = 0 ] && rm -f ${lockfile}
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
    	stop
	;;
  status)
	status $argos
        RETVAL=$?
	;;
  restart|reload|condrestart)
    	stop
    	start
	;;
  *)
	echo $"Usage: $prog {start|stop|restart|reload|status}"
	exit 1
esac

exit $RETVAL
