init script cleanup, use /etc/rc.d/ for enabled scripts, /etc/init.d/<pkgname> (enabl...
[openwrt/svn-archive/archive.git] / package / base-files / brcm-2.6 / etc / init.d / netconfig
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006 OpenWrt.org
3
4 START=05
5 start() {
6 [ -e /etc/config/network ] && exit 0
7
8 mkdir -p /etc/config
9
10 (
11 if grep -E 'mtd0: 000(6|a)0000' /proc/mtd 2>&- >&-; then
12 # WGT634u
13 echo boardtype=wgt634u
14 else
15 strings /dev/mtdblock/3
16 fi
17 ) | awk '
18 function p(cfgname, name) {
19 if (c[name] != "") print " option " cfgname " \"" c[name] "\""
20 }
21
22 BEGIN {
23 FS="="
24 c["lan_ifname"]="eth0.0"
25 c["wan_ifname"]="eth0.1"
26 c["vlan0ports"]="1 2 3 4 5*"
27 c["vlan1ports"]="0 5"
28 }
29
30 ($1 == "boardnum") || ($1 == "boardtype") || ($1 == "boardflags") {
31 nvram[$1] = $2
32 }
33
34 END {
35 # v1 hardware
36 if (nvram["boardtype"] == "bcm94710dev") {
37 # Asus WL-500g
38 if (nvram["boardnum"] == "asusX") {
39 c["lan_ifname"]="eth0 eth1" # FIXME
40 c["wan_ifname"]=""
41 }
42 }
43 if (nvram["boardtype"] == "wgt634u") {
44 c["vlan0ports"] = "0 1 2 3 5*"
45 c["vlan1ports"] = "4 5"
46 }
47 if ((nvram["boardtype"] == "0x0467") || (nvram["boardtype"] == "0x042f")) {
48 c["vlan0ports"] = "0 1 2 3 5*"
49 c["vlan1ports"] = "4 5"
50 }
51
52 # WAP54G
53 if ((nvram["boardnum"] == "2") || \
54 (nvram["boardnum"] == "1024")) {
55 c["lan_ifname"]="eth0"
56 c["wan_ifname"]=""
57 }
58
59 print "#### VLAN configuration "
60 print "config switch eth0"
61 p("vlan0", "vlan0ports")
62 p("vlan1", "vlan1ports")
63 print ""
64 print ""
65 print "#### Loopback configuration"
66 print "config interface loopback"
67 print " option ifname \"lo\""
68 print " option proto static"
69 print " option ipaddr 127.0.0.1"
70 print " option netmask 255.0.0.0"
71 print ""
72 print ""
73 print "#### LAN configuration"
74 print "config interface lan"
75 print " option type bridge"
76 p("ifname", "lan_ifname")
77 print " option proto static"
78 print " option ipaddr 192.168.1.1"
79 print " option netmask 255.255.255.0"
80 print ""
81 print ""
82 print "#### WAN configuration"
83 print "config interface wan"
84 p("ifname", "wan_ifname")
85 print " option proto dhcp"
86 }' > /etc/config/network
87 }