#!/bin/bash
# Begin $rc_base/init.d/netfs

# Based on sysklogd script from LFS-3.1 and earlier.
# Rewritten by Gerard Beekmans  - gerard@linuxfromscratch.org

source /etc/sysconfig/rc
source $rc_functions

case "$1" in
	start)
		echo "Mounting NFS volumes..."
		mount -at nfs
		evaluate_retval

# This section left commented out, as smb mounts require a user's ID and 
# password.  It is bad practice to include login info in a world readable file.
# This section should only be uncomented if you are in a workgroup with a 
# common login ID and password.  Even then, it is not a good idea!

#		echo "Mounting Samba shares..."
#		mount -at smbfs
#		evaluate_retval

# This section is commented out as well for similar reasons. It also is not 
# yet a part of BLFS.  I am unsure ATM if the Netware clients currently 
# availible include a way to directly mount a volume without first loging in,
# or provide a way to pass login info to mount.

#		echo "Mounting Netware volumes..."
#		mount -at ncpfs
#		evaluate_retval
		;;


	stop)
		echo -n "Unmounting NFS volumes..."
		NFSMOUNTS=$(awk 'BEGIN { ORS=" "} $3 ~ /nfs/ { print $2 }' \
			/etc/mtab) 
		if [ "$NFSMOUNTS" != "" ]
		then
			echo " "
			fuser -km $NFSMOUNTS >> /dev/null
			umount $NFSMOUNTS >> /dev/null
			evaluate_retval
		else
			echo "           No NFS volumes mounted!"
			evaluate_retval
		fi

		echo -n "Unmounting Samba shares..."
		SMBMOUNTS=$(awk 'BEGIN { ORS=" "} $3 ~ /smbfs/ { print $2 }' \
			/etc/mtab) 
		if [ "$SMBMOUNTS" != "" ]
		then
			echo ""
			fusrer -km $SMBMOUNTS >> /dev/null
			umount $SMBMOUNTS >> /dev/null
			evaluate_retval
		else
			echo "          No Samba shares mounted!"
			evaluate_retval
		fi

		echo -n "Unmounting Netware volumes..."
		NCPMOUNTS=$(awk 'BEGIN { ORS=" "} $3 ~ /ncpfs/ { print $2 }' \
			/etc/mtab) 
		if [ "$NCPMOUNTS" != "" ]
		then
			echo ""
			fuser -km $NCPMOUNTS >> /dev/null
			umount $NCPMOUNTS /dev/null
			evaluate_retval
		else
			echo "       No Netware volumes mounted!"
			evaluate_retval
		fi
		;;

	*)
		echo "Usage: $0 {start|stop}"
		exit 1
		;;
esac

# End $rc_base/init.d/netfs

