#!/bin/sh
#
# gnunetd	Starts gnunetd.
#
# chkconfig: 345 82 18
# description: The  GNUnet daemon, required for any GNUnet operations (searches, down‐loads, etc).
### BEGIN INIT INFO
# Provides: gnunet
# Required-Start: $network
# Required-Stop: $network
# Default-Start:
# Default-Stop: 0 1 6
# Short-Description: GNUnet daemon
# Description: GNUnet is an anonymous distributed secure network
#               this server is required to connect to the network,
#               it will open a TCP port to communicate with the
#               GUI and an UDP port to communicate with the world.
#               The configuration file /etc/gnunetd.conf will be used.
### END INIT INFO

WITHOUT_RC_COMPAT=1

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

SourceIfNotEmpty /etc/sysconfig/gnunetd

GNUNETD=/usr/bin/gnunet-arm
[ -x "$GNUNETD" ] || exit

GNUNETD_CONF=/etc/gnunetd.conf

PIDFILE=/var/run/gnunetd/pid
LOCKFILE=/var/lock/subsys/gnunetd
RETVAL=0

start()
{
	msg_starting $"GNUNet daemon"
	if [ -f "$GNUNETD_CONF" ]; then
		start_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --no-announce -- $GNUNETD $GNUNETD_OPTIONS
		RETVAL=$?
	else
		passed
		RETVAL=$?
		echo
		echo "GNUNet daemon is not configured"
	fi
	return $RETVAL
}

stop()
{
	msg_stopping $"GNUNet daemon"
	stop_daemon --pidfile "$PIDFILE" --lockfile "$LOCKFILE" --no-announce $GNUNETD
	RETVAL=$?
	return $RETVAL
}

restart()
{
	stop
	start
}

reload()
{
	msg_reloading $"GNUNet daemon"
	stop_daemon --pidfile "$PIDFILE" -HUP $GNUNETD
	RETVAL=$?
	return $RETVAL
}

# See how we were called.
case "$1" in
	start)
		start
		;;
	stop)
		stop
		;;
	status)
		status --pidfile "$PIDFILE" $GNUNETD
		RETVAL=$?
		;;
	restart)
		restart
		;;
	reload)
		reload
		;;
	condstart)
		if [ ! -e "$LOCKFILE" ]; then
			start
		fi
		;;
	condstop)
		if [ -e "$LOCKFILE" ]; then
			stop
		fi
		;;
	condrestart)
		if [ -e "$LOCKFILE" ]; then
			restart
		fi
		;;
	condreload)
		if [ -e "$LOCKFILE" ]; then
			reload
		fi
		;;
	*)
		msg_usage "${0##*/} {start|stop|status|restart|reload|condstart|condstop|condrestart|condreload}"
		RETVAL=1
esac

exit $RETVAL
