#!/bin/sh

_FUNCTIONS=/etc/rc.d/functions
[ -f ${_FUNCTIONS} ] && . ${_FUNCTIONS}

KINDLE_IP=192.168.15.244 

status_usbnetd()
{
	return 0
}

start_usbnetd()
{
	if lsmod | grep g_file_storage > /dev/null ; then 
		msg "unloading g_file_storage module" I
		rmmod g_file_storage || exit 1
		msg "loading g_ether module" I
		modprobe g_ether host_addr='EE4900000000' dev_addr='EE1900000000' || exit 1
	
		msg "bringing usb0 interface up" I
		ifconfig usb0 ${KINDLE_IP} netmask 255.255.255.0 || exit 1
	fi
}

stop_usbnetd()
{
	if lsmod | grep g_ether > /dev/null ; then 
		msg "bringing usb0 interface down" I
        	ifconfig usb0 down || exit 1

        	msg "unloading g_ether module" I
        	rmmod g_ether || exit 1
        	msg "loading g_file_storage module" I
        	modprobe g_file_storage || exit 1 
	fi
}

usage()
{
    echo "Usage: $(basename $0) {start|stop|connect|disconnect|tethered|status}"
    exit 1
}

case $1 in

	start)
		start_usbnetd
		;;
	
	stop)
		stop_usbnetd
		;;

	connect)
		;;

	disconnect)
		;;
                
	tethered)
		;;
        
	launch)
		start_usbnetd
		;;

	status)
		status_usbnetd
                exit $?
		;;

	*)
		if [ $# -ne 0 ] ; then
			usage
		fi
		start_usbnetd
		;;
esac
