#!/bin/sh
echo "configuring USB cable for networking..."

/etc/usbcontrol net 2>/dev/null >/dev/null
/etc/usbcontrol checkAndLoadNet 2>/dev/null >/dev/null

GATEWAY=192.168.0.1
IP=192.168.0.2

echo "...DNS is `grep nameserver /etc/resolv.conf|cut -d" " -f2`"
echo "...Gateway is $GATEWAY"
echo "...Local IP for usb0 is $IP"

echo "...reconfiguring network"
ifconfig usbd0 down 2>/dev/null
ifconfig usbd0 $IP up 2>/dev/null
route add -host $GATEWAY usbd0 2>/dev/null
route delete -net `echo $GATEWAY|cut -d. -f1,2,3`.0/24 usbd0 2>/dev/null
route delete default 2>/dev/null
route add default gw $GATEWAY 2>/dev/null

if [ "`ifconfig -a|grep usbd0`" = "" ]; then
  echo "usb cable not plugged in"
else
  echo "done. you might need to update /etc/resolv.conf with your DNS"
fi
