Add network support to initscripts
[qi-bootmenu-system/guyou.git] / rootfs-overlay / etc / init.d / networking
blobda9bde061c8b83e97e3f4638de3735a93b755676
1 #!/bin/sh
3 case "$1" in
4 start)
5 # gathers or create necessary host and device mac addresses for
6 # the g_ether module. If the g_ether module options file exists,
7 # we have nothing to do.
9 if [ ! -e /etc/modprobe.d/g_ether.conf ] ; then
11 # Gather up all g_ether parameters passed in on the kernel
12 # command line, and make sure to pass them to the module.
14 # Begin by searching the command line for the host and dev addrs
15 da=`sed -n -e 's|.*g_ether\.dev_addr\=\(..:..:..:..:..:..\).*|\1|p' /proc/cmdline`
16 ha=`sed -n -e 's|.*g_ether\.host_addr\=\(..:..:..:..:..:..\).*|\1|p' /proc/cmdline`
18 # If have a device address, now we need to sort out the host address.
19 # If it is unspecified, or if it is the same as the device address
20 # (Qi does this), compute a new address by just incrementing the device
21 # address.
23 if [ -n "$da" -a -z "$ha" -o "$da" = "$ha" ]; then
25 # We need to compute a new address - split the device
26 # address into two part, and increment the second part.
27 pfx=`echo "$da" | sed -n -e 's|\(..:..:..:\)..:..:..|\1|p'`
28 i=`echo "$da" | sed -n -e 's|..:..:..:\(..\):\(..\):\(..\)|0x\1\2\3|p'`
30 # Now increment the mac addr
31 i=$(printf %06x $(($i+1)))
33 # And glue the parts back together again.
34 i=`echo "$i" | sed -n -e 's|\(..\)\(..\)\(..\)|\1:\2:\3|p'`
36 # Assign the computed host address, if this all worked out.
37 [ -n "$i" -a -n "$pfx" ] && ha=$pfx$i
40 [ -n "$da" ] && daddr="dev_addr=$da"
41 [ -n "$ha" ] && haddr="host_addr=$ha"
43 [ -d /etc/modprobe.d ] || mkdir /etc/modprobe.d
44 echo "options g_ether $daddr $haddr" >/etc/modprobe.d/g_ether.conf
47 # load g_ether module if it isn't yet
48 lsmod | grep g_ether 2>/dev/null || modprobe g_ether 2>/dev/null
50 ifconfig usb0 192.168.0.202 netmask 255.255.255.0 up
51 route add default gw 192.168.0.200 metric 8
52 echo nameserver 208.67.222.222 > /etc/resolv.conf
53 echo nameserver 208.67.220.220 >> /etc/resolv.conf
56 stop)
57 ifconfig usb0 down
58 modprobe -r g_ether
60 restart)
61 $0 stop
62 $0 start
65 echo "Usage: $0 {start|stop|restart}"
66 exit 1
68 esac
70 exit 0