:
#      @(#)nfs	4.8.1.3 System V NFS  source
#      SCCS IDENTIFICATION
#
#	System V NFS
#
#	Copyright 1986-1989 Lachman Associates, Incorporated (LAI)
#
#	All Rights Reserved.
#
#	The copyright above and this notice must be preserved in all
#	copies of this source code.  The copyright above does not
#	evidence any actual or intended publication of this source
#	code.
#
#	This is unpublished proprietary trade secret source code of
#	Lachman Associates.  This source code may not be copied,
#	disclosed, distributed, demonstrated or licensed except as
#	expressly authorized by Lachman Associates.
#
# Nfs start/stop script
#

PATH=/etc:/bin:/usr/bin
USAGE="Usage: $0 {start | stop }"
#
# PROCS contains a list of processes to kill when NFS is stopped.
# Edit as appropriate.
#
PROC1="portmap nfsclnt lckclnt"
PROC2="mountd nfsd biod rexd lockd statd pcnfsd \
       rwalld rusersd automount ypserv yppasswdd ypbind ypxfrd"
PROCS="$PROC1 $PROC2"
# PROC additions begin here
# Add additional PROCS here

# figure out which kernel we're running
if [ -x /bin/ps ] ; then
    /bin/ps -ef > /tmp/ps.err$$ 2>&1
    if grep "not the booted" /tmp/ps.err$$ > /dev/null ; then
	PS="/bin/ps -n /unix.old"
    else
        PS="/bin/ps"
    fi
    rm -f /tmp/ps.err$$
else
    echo "$0: Can't find ps"
    exit 1
fi

case "$1" in
'start')

	/bin/su root -c "$PS -e"  2>/dev/null | \
		/usr/bin/fgrep portmap > /dev/null 2>&1

	if [ $? -eq 0 ]
	then
		echo "NFS already running.  NFS start aborted."
		exit 0
	fi

        #
        # Clean up temporary data files so the will be rebuilt freshly
        #
        rm -f /etc/nfsstat_data

	#domainname "$YPDOMAIN"
	nfsstat > /dev/null 2>&1 &
	oldmask=`umask`

	echo "NFS Startup..."

	echo "ONC daemons:\c"

	echo " portmap\c"
	portmap
	if [ $? -ne 0 ]
	then
		echo ""
		echo "Troubling starting portmap.  NFS start aborted."
		exit 1
	fi

       [ -x /etc/pcnfsd ] && {
               echo " pcnfsd\c"
               pcnfsd &
       }


       [ -x /etc/rwalld ] && {
               echo " rwalld\c"
               rwalld
       }


       [ -x /etc/rusersd ] && {
               echo " rusersd\c"
               rusersd
       }


	echo ""

	echo "NFS daemons:\c"

	if [ -r /etc/exports ]
	then
               [ -x /etc/exportfs ] && {
                       echo " exportfs\c"
                       exportfs -a
               }

               [ -x /etc/mountd ] && {
                       echo " mountd\c"
                       mountd
               }


               [ -x /etc/nfsd ] && {
                       umask 000
                       echo " nfsd(x4)\c"
                       nfsd 4
                       umask $oldmask
               }


	fi

       [ -x /etc/nfsclnt ] && {
               echo " nfsclnt(x8)\c"
               nfsclnt 8
       }


       [ -x /etc/biod ] && {
               echo " biod(x4)\c"
               biod 4
       }


       [ -x /etc/automount ] && {
               echo " automount\c"
               if [ -r /etc/auto.master ] ; then
                       umask 000
                       automount -m -f /etc/auto.master
                       umask $oldmask
               fi
       }

	echo ""


# SERVICES additions begin here
# SCO_NLM
	echo "Lock manager:\c"

	echo " statd\c"
	statd

	echo " lckclnt(x4)\c"
	lckclnt 4

	echo " lockd\c"
	lockd

	echo ""
# SCO_NLM
# starting rexd may allow unauthorized access
#
# SCO_REX
#
#	echo "ONC daemons: rexd\c"
#	rexd
#
#	echo ""
# SCO_REX
# Add additional SERVICES here
	grep NFS /etc/default/filesys > /dev/null 2>&1
	if [ $? -eq 0 ]
	then
		echo "Mounting NFS file systems..."
		/usr/bin/mnt -n
	fi

	grep NFS /etc/fstab > /dev/null 2>&1
	if [ $? -eq 0 ]
	then
		echo "There are NFS filesystems listed in /etc/fstab."
		echo "These must be integrated into /etc/default/filesys"
		echo "for them to be automatically mounted."
	fi


	echo "NFS Startup complete."

	;;

'stop')

       #
       # Don't bother stopping NFS if it's not running.
       #

	/bin/su root -c "$PS -e"  2>/dev/null | \
		/usr/bin/fgrep portmap > /dev/null 2>&1

       if [ $? -ne 0 ]
       then
           echo "NFS not running.  NFS stop aborted."
           exit 0
       fi


	echo "NFS shutdown: \c"

	#
	# Unmount mounted NFS file systems
	#

	/etc/numountall

	#
	# Get our ps out of the way
	#
	/bin/su root -c "$PS -ef"  2>/dev/null > /tmp/ps$$

	#
	# Now, kill them procs
	#
	# There is a hole here because some procs
	# may die without us knowing about them
	# because we are working from an old image.
	#

	PIDS=`(
	for proc in $PROC2
	do
	 	cat /tmp/ps$$ | /bin/grep $proc | \
		/bin/grep -v grep | /usr/bin/awk '{ print $2 }'
	done )`

 	if [ "$PIDS" != "" ]
 	then
 		/bin/kill $PIDS 2> /dev/null
		sleep 10
 	fi

	PIDS=`(
	for proc in $PROC1
	do
	 	cat /tmp/ps$$ | /bin/grep $proc | \
		/bin/grep -v grep | /usr/bin/awk '{ print $2 }'
	done )`

	rm -f /tmp/ps$$

 	if [ "$PIDS" != "" ]
 	then
 		/bin/kill -9 $PIDS 2> /dev/null
 	fi

	#
	# Unexport any exported file systems
	#

        [ -x /etc/exportfs -a -r /etc/exports ] && {
                exportfs -ua
        } 

	echo "[NFS Shutdown Complete]"

	;;
*)
	echo $USAGE
	exit 1
	;;
esac
