#!/bin/sh

##
# Network File System
##

. /etc/rc.common

StartService ()
{
    CheckForNetwork 
    if [ "${NETWORKUP}" = "-NO-" ]; then exit; fi

    ##
    # Set up NFS client.
    ##
    ConsoleMessage "Starting network file system"

    # nsfiod is the NFS asynchronous block I/O daemon, which implements
    # NFS read-ahead and write-behind caching on NFS clients.
    nfsiod -n 4 

    ##
    # Set up NFS server.
    ##

    # If exportfs finds something to export (either using /etc/exports or the
    # exports NetInfo directory), then start the NFS daemons (which service
    # NFS requests) and the mount server (which services NFS mount requests).

    # Clear the table of exported filesystems.
    rm -f /var/db/mountdtab

    exports_ni=$(niutil -list . /exports 2> /dev/null | wc -w)
    # Look for exports in /etc/exports, ignoring comments and blank lines.
    exports_etc=$(grep -v '^[[:space:]]*\(#\|$\)' /etc/exports 2> /dev/null | wc -l)
    exports=$((exports_ni+exports_etc))

    if [ "${exports}" -gt 0 ]; then
	ConsoleMessage "Starting Network File System server"
	mountd

	# If the NetInfo config/nfsd directory contains startup args for nfsd, use those.
	arguments=`niutil -readprop . /config/nfsd arguments`
	if [ "${arguments}" = "" ]; then
		arguments="-t -u -n 6"
	fi
	nfsd ${arguments}
    fi

    ##
    # Start the automounter
    ##

    if [ "${AUTOMOUNT:=-YES-}" = "-YES-" ]; then
	automount -m /Network/Servers -fstab -m /automount -static
    fi
}

StopService ()
{
    return 0
}

RestartService ()
{
    return 0
}

RunService "$1"
