#!/bin/sh
#
# Mounting usbfs if usbcore is loaded.
#
#
case $ACTION in

    add)
	if [ -f /proc/mounts ]; then
	    MOUNTED="`/bin/sed -n '/usb/p' /proc/mounts`"
	fi
	if [ -d /proc/bus/usb ] && [ -z "$MOUNTED" ]; then
	    # if it's not mounted, try to mount it
	    FSTAB="`/bin/sed -n '/usb/p' /etc/fstab`"
	    if [ -n "$FSTAB" ]; then
		mount /proc/bus/usb
	    else
		# NOTE: name was changed to "usbfs" from "usbdevfs"
		# NOTE: some versions don't create empty 'devices' files
		mount -t usbfs usbfs /proc/bus/usb
	    fi
	fi
	;;
    remove)
	if [ -f /proc/mounts ]; then
	    MOUNTED="`/bin/sed -n '/usb/p' /proc/mounts`"
	fi
	if [ -z "$MOUNTED" ]; then
	    set -- $MOUNTED
	    umount $2
	fi
	;;

esac


