#!/bin/sh
#
# usbnet-ipaq.sh
#

rm -f /etc/init.d/usbnet

echo "USB Network Interface Configuration:"

read -p "  Local IP Address   [     172.17.7.1]: " address
if [ -n $address ]; then address="172.17.7.1"; fi

read -p "  Netmask            [  255.255.255.0]: " netmask
if [ -n $netmask ]; then netmask="255.255.255.0"; fi

read -p "  Gateway IP Address [     172.17.7.2]: " gateway
if [ -n $gateway ]; then gateway="172.17.7.2"; fi

read -p "  Domain Name Server [    216.68.4.10]: " nameserver
if [ -n $nameserver ]; then nameserver="216.68.4.10"; fi


cat > /etc/init.d/usbnet << EOF
#!/bin/sh

# chkconfig: 345 45 96
# processname: usbnet
# pidfile: /var/run/usbnet.pid
# lockfile: /var/lock/subsys/usbnet

# rc.usbnet
#
# Based On: rc.netbase 1.27 1999/09/27 16:45:01 (David Hinds)
#
# Modified by Oleg Drokin: Adapted to start usbnet
#
# Modified 2002-01-17 by Gregor Purdy: No /proc/scale, better IP addressing.
#

usage()
{
  echo "Usage: \$0 {start|stop|status}"
}

for x in "1" ; do
  if [ \$# -lt 1 ] ; then usage ; break ; fi
  action=\$1
  case \$action in
    start)
      modprobe usb-eth
      ifconfig usbf up $address netmask $netmask
      route add default gw $gateway
      ;;
    stop)
      ifconfig usbf down
      rmmod usb-eth sa1100_usb
      ;;
    status)
      ifconfig usbf
      ;;
    *)
      usage
      ;;
  esac
done

# Only exit if we're in our own subshell

if [ "\${0##*/}" = "usbnet" ] ; then
  exit \$EXITCODE
fi

EOF

chmod u+x /etc/init.d/usbnet

/bin/sh /etc/init.d/usbnet start

ifconfig usbf

cat > /etc/resolv.conf <<EOF
nameserver $nameserver
EOF


