#!/bin/sh

##
# AppleTalk
##

. /etc/rc.common

StartService ()
{
    if [ "${APPLETALK:=-NO-}" != "-NO-" ] &&
       [ "$(uname -p)" = "powerpc" ]; then

	ConsoleMessage "Starting AppleTalk"

	helper=/System/Library/SystemConfiguration/Kicker.bundle/Resources/restart-AppleTalk
	if [ -x "${helper}" ]; then
	    ##
	    # if "configd" is managing the network configuration then we
	    # should use the restart script to start AppleTalk and update
	    # the configuration cache.
	    ##
	    ${helper}
	    exit
	fi

	ATO=""
	if [ "${APPLETALK_HOSTNAME:=-AUTOMATIC-}" != "-AUTOMATIC-" ]; then
	    ATO="-C ${APPLETALK_HOSTNAME}"
	fi

	case "${APPLETALK}" in
	  -ROUTER-)
	    # Router mode
	    appletalk ${ATO} -r -q
	    ;;
	  -MULTIHOME-)
	    # Multihome non-routing mode
	    appletalk ${ATO} -x -q
	    ;;
	  *)
	    # Single port on specified interface, non-routing
	    appletalk ${ATO} -u ${APPLETALK} -q
	    ;;
	esac
    fi
}

StopService ()
{
    ConsoleMessage "Stopping AppleTalk"
    appletalk -d
}

RestartService () { StopService; StartService; }

RunService "$1"
