#!/bin/sh
#
# $Id: filesys,v 4.5 1993/04/01 12:58:40 mike Exp $
#
# Mount/unmount non-root, non-nfs filesystems

# Load the library and find various programs.
. /etc/init.d/LIB

case "$1" in
	start)
		# If this isn't a fast boot check the filesystems before
		# mounting them. (*NOT* the NFS filesystems!)
		if [ -f /fastboot -o -f /etc/fastboot -o -n "$FASTBOOT" ]; then
			echo "FAST BOOT: no filesystem checks made"
		fi
		awk '/^[ \t]*\/dev/ && $2 != "/" && $3 != "swap" && $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 [ ! -f /fastboot -a ! -f /etc/fastboot -a -z "$FASTBOOT" ]; then
					echo "Checking filesystem on $1"
					checkfs $1 $3 > /dev/tty 2>&1 < /dev/tty
				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
