#!/sbin/runscript
# Copyright 1999-2003 Gentoo Technologies, Inc.
# Distributed under the terms of the GNU General Public License v2
# $Header: /home/cvsroot/gentoo-src/rc-scripts/init.d/localmount,v 1.16 2003/03/24 14:09:41 azarah Exp $


depend() {
	need checkfs
}

start() {
	# Mount local filesystems in /etc/fstab.
	ebegin "Mounting local filesystems"
	mount -at nocoda,nonfs,noproc,noncpfs,nosmbfs,noshm >/dev/null
	eend $? "Some local filesystem failed to mount"

	# Make sure we insert usbcore if its a module
	if [ -f /proc/modules ]
	then
		# >/dev/null to hide errors from non-USB users
		modprobe usbcore &>/dev/null
	fi
	
	# Check what USB fs the kernel support.  Currently
	# 2.5+ kernels, and later 2.4 kernels have 'usbfs',
	# while older kernels have 'usbdevfs'.
	local usbfs="$(awk '
	  {
	    # Since 'usbfs' is the newer one, always try to use it
	    if ($2 == "usbfs")
	      USBFS = "usbfs"
	    # With my 2.4.20 kernel, 'usbdevfs' gets listed before 'usbfs',
	    # but this might change, so only change USBFS if it was not already
	    # set (and thus to 'usbfs').
	    if (($2 == "usbdevfs") && (USBFS == ""))
	      USBFS = "usbdevfs"
	  }
	
	  END {
	    if (USBFS != "")
	      print USBFS
	  }' /proc/filesystems)"

	if [ -n "${usbfs}" ] && \
	   [ -e /proc/bus/usb -a ! -e /proc/bus/usb/devices ]
	then
		ebegin "Mounting USB device filesystem (${usbfs})"
		mount -t ${usbfs} none /proc/bus/usb &>/dev/null
		eend $? "Failed to mount USB device filesystem"
	fi

	#swap on loopback devices, and other weirdnesses
	ebegin "Activating (possibly) more swap"
	/sbin/swapon -a &>/dev/null
	eend 0
}


# vim:ts=4
