#!/bin/sh
#
# pdaXrom usbd
#

if grep 'PXA27' /proc/cpuinfo >/dev/null 2>/dev/null ; then
    MODULE=pxa27x_udc
elif grep 'PXA25' /proc/cpuinfo >/dev/null 2>/dev/null ; then
    MODULE=pxa2xx_udc
else
    MODULE=pxa2xx_udc
fi

STORAGE_CONF=/etc/sysconfig/usb/g_storage.conf

case "$1" in
start)
	if ! lsmod | grep $MODULE >/dev/null 2>/dev/null ; then
	    if modprobe $MODULE ; then
		if [ -e $STORAGE_CONF ]; then
		    modprobe g_file_storage removable file=`cat $STORAGE_CONF`
		else
		    modprobe g_ether
		fi
	    fi
	fi
	;;
stop)
	if ! lsmod | grep $MODULE >/dev/null 2>/dev/null ; then
		exit 0
	fi
	for i in `lsmod | grep $MODULE | sed 's/\ */\ /g' | cut -f5 -d' ' | tr ',' ' '`;
	do
		modprobe -r $i
	done
	modprobe -r $MODULE
	;;
*)
	echo "Usage: $0 (start|stop)"
	exit 1
	;;
esac

exit 0
