#! /bin/sh
# Mount network file systems now that at least one interface is
# configured.

[ "$IFACE" != "lo" ] || exit 0

test -f /etc/fstab || exit 0

[ -f /etc/default/rcS ] && . /etc/default/rcS
. /lib/init/functions.sh


# Lock around this otherwise insanity may occur
mkdir /var/run/network/mountnfs 2>/dev/null || exit 0

#
#	Read through fstab line by line. If it is NFS, set the flag
#	for mounting NFS file systems. If any NFS partition is found and it
#	not mounted with the nolock option, we start the portmapper.
#
portmap=no
while read device mountpt fstype options
do
	case "$device" in
		""|\#*)
			continue
			;;
	esac

	case "$options" in
		*noauto*)
			continue
			;;
	esac

	case "$fstype" in
		nfs|nfs4)
			case "$options" in
				*nolock*)
					;;
				*)
					portmap=yes
					;;
			esac
			;;
		smbfs|cifs|coda|ncp|ncpfs)
			;;
		*)
			fstype=
			;;
	esac
	if [ -n "$fstype" ]
	then
		case "$NETFS" in
			$fstype|*,$fstype|$fstype,*|*,$fstype,*)
				;;
			*)
				NETFS="$NETFS${NETFS:+,}$fstype"
				;;
		esac
	fi
done < /etc/fstab

if [ "$portmap" = yes ]
then
	if [ -x /sbin/portmap ] && [ -z "`pidof portmap`" ] 
	then
		start-stop-daemon --start --quiet --exec /sbin/portmap
	fi
fi

if [ -n "$NETFS" ]
then
	pre_mountall
	mount -a -t$NETFS 2>&1 | egrep -v '(already|nothing was) mounted'
	post_mountall
fi

rmdir /var/run/network/mountnfs 2>/dev/null || exit 0
