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
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
>/dev
/null
2>&1 || modprobe g_ether
2>/dev
/null
&& sleep 1
51 ip addr add
192.168.0.202/24 dev usb0
52 ip route add default via
192.168.0.200
54 echo nameserver
208.67.222.222 > /etc
/resolv.conf
55 echo nameserver
208.67.220.220 >> /etc
/resolv.conf
66 echo "Usage: $0 {start|stop|restart}"