#!/bin/sh
# chkconfig: 345 91 35
# description: This package enables Linux to talk to Macintosh computers via the \
#              AppleTalk networking protocol. It includes a daemon to allow Linux \
#              to act as a file server over EtherTalk or IP for Mac's.
# processname: atalkd
# pidfile: /var/run/atalkd.pid
# config: /etc/atalk/*

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

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

# Source Appletalk configuration
. /etc/atalk/config

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

# See how we were called.
case "$1" in
  start)
	echo -n "Starting AppleTalk services: "
	if [ ${ATALK_BGROUND} = yes ] ; then
	    echo -n "(backgrounded)"
	    {
		daemon atalkd
		nbprgstr -p 4 "${ATALK_NAME}:Workstation"
		nbprgstr -p 4 "${ATALK_NAME}:netatalk"
		if [ ${PAPD_RUN} = yes ] ; then
		    daemon papd
		fi
		if [ ${AFPD_RUN} = yes ] ; then
		    daemon afpd -c ${AFPD_MAX_CLIENTS} -n ${ATALK_NAME}
		fi
	    } >/dev/null &
	else
	    daemon atalkd
	    nbprgstr -p 4 "${ATALK_NAME}:Workstation"
	    nbprgstr -p 4 "${ATALK_NAME}:netatalk"
	    if [ ${PAPD_RUN} = yes ] ; then
		daemon papd
	    fi
	    if [ ${AFPD_RUN} = yes ] ; then
		daemon afpd -c ${AFPD_MAX_CLIENTS} -n ${ATALK_NAME}
	    fi
	fi
	echo
	touch /var/lock/subsys/atalk
	;;
  stop)
	echo -n "Shutting down AppleTalk services: "
	killall afpd
	killall papd
	nbpunrgstr "${ATALK_NAME}:Workstation@*"
	nbpunrgstr "${ATALK_NAME}:netatalk@*"
	killall atalkd
	# Attempt to zap the module, so that we can restart the
	# Appletalk daemons cleanly
	if [ -e /proc/modules ] && [ -x /sbin/modprobe ] ; then
	    modprobe -r appletalk
	fi
	rm -f /var/lock/subsys/atalk
	echo ""
	;;
  restart|reload)
	$0 stop
	$0 start
	;;
  status)
	status atalkd
	;;
  *)
	echo "Usage: atalk {start|stop|restart|status}"
	exit 1
esac

