#!/bin/sh
#
# netromd       This shell script takes care of starting and stopping
#               the ax25-tools netromd daemon.
#
# chkconfig: - 96 04
# description: ax25-tools netromd daemon

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

# Source networking configuration.
. /etc/sysconfig/network

# Check that networking is up.
[ ${NETWORKING} = "no" ] && exit 0

[ -f /proc/net/nr ] || exit 0

DAEMON=netromd

# See how we were called.
case "$1" in
  start)
        # Start daemons.
        echo -n "Starting $DAEMON: "
        daemon $DAEMON
	RETVAL=$?
        echo
	if [ -f /var/ax25/nodesave.data ]; then
		echo -n "(restoring saved netrom nodes)"
		. /var/ax25/nodesave.data
		rm -f /var/ax25/nodesave.data
	fi
        touch /var/lock/subsys/$DAEMON
        ;;
  stop)
        # Stop daemons.
        echo -n "Shutting down $DAEMON: "
	killproc $DAEMON
	RETVAL=$?
	echo -n "(saving netrom nodes)"
	/usr/sbin/nodesave /var/ax25/nodesave.data
        echo
        [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$DAEMON
        ;;
  status)
	status $DAEMON
	RETVAL=$?
	;;
  restart|reload)
	$0 stop
	$0 start
	RETVAL=$?
	;;
  *)
        echo "Usage: $DAEMON {start|stop|restart|status}"
        exit 1
esac

exit $RETVAL
