#!/bin/sh
#
# (C) Copyright 1993, 1994 Mike Jagdis (jaggy@purplet.demon.co.uk)
#
#
# Mount/unmount non-root, non-nfs filesystems

# Load the library and find various programs.
. /etc/init.d/LIB
mount=`pathof mount`
umount=`pathof umount`

case "$1" in
	start)
		# If this isn't a fast boot check the filesystems before
		# mounting them. (*NOT* the NFS filesystems!)
		if [ "$checkfs" != "YES" -a "$checkfs" != "yes" ] && [ -f /fastboot -o -f /etc/fastboot -o -n "$FASTBOOT" ]; then
			echo "FAST BOOT: no filesystem checks made"
		fi
		# N.B. / and /usr (if it exists as a separate filesystem
		# where checked and mounted during power up checks.
		awk '/^[ \t]*\/dev/ && $2 != "/" && $2 != "/usr" && $3 != "swap" && $3 != "proc" && $3 != "nfs" && $4 !~ "noauto"' /etc/fstab | while read fsys
		do
			set -- $fsys
			if grep "^$1" /etc/mtab > /dev/null 2>&1; then
				: already mounted
			else
				if [ "$checkfs" = "YES" -o "$checkfs" = "yes" ] || [ ! -f /fastboot -a ! -f /etc/fastboot -a -z "$FASTBOOT" ]; then
					echo "Checking filesystem on $1"
					(dofscheck $1 $3 > $CTTY 2>&1 < $CTTY)
				fi
				if [ -z "$4" ]; then
					$mount -t $3 $1 $2
				else
					$mount -t $3 $1 $2 -o $4
				fi
			fi
		done

		# Now we've done all that get rid of /fastboot and
		# /etc/fastboot if they exist.
		rm -f /etc/fastboot /fastboot
		;;

	stop)
		$umount -av
		;;

	*)	echo "usage: filesys start|stop"
		exit 1
		;;
esac
