352a2a9a2ba5ad5b21f6f3fca3fee7470a20a04e
[openwrt/svn-archive/archive.git] / target / linux / ixp4xx-2.6 / base-files / etc / init.d / netconfig
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2006 OpenWrt.org
3
4 START=05
5
6 # hardware
7 # the 'Hardware' string from cpuinfo
8 hardware(){
9 sed -n 's!^Hardware *: !!p' /proc/cpuinfo
10 }
11 #
12 # machine
13 # outputs an identifier of the current machine - i.e. the board
14 # slugos is running on.
15 machine(){
16 case "$(hardware)" in
17 *Avila*) echo avila;;
18 *Loft*) echo loft;;
19 *NAS?100d*) echo nas100d;;
20 *DSM?G600*) echo dsmg600;;
21 *NSLU2*) echo nslu2;;
22 *FSG?3*) echo fsg3;;
23 *Gateway?7001*) echo gateway7001;;
24 *) echo unknown;;
25 esac
26 }
27
28 # Returns the mtd device with the specified name (without leading /dev)
29 # $1 = name of mtd device
30 get_mtd() {
31 grep "\"$1\"*$" /proc/mtd | cut -d : -f 1
32 }
33
34 # Returns the mtd block device with the specified name (without leading /dev)
35 # $1 = name of mtd device
36 get_mtdblock() {
37 echo $(get_mtd "$1") | sed 's/mtd/mtdblock/'
38 }
39
40 start() {
41 [ -e /etc/config/network ] && exit 0
42
43 mkdir -p /etc/config
44
45 (
46 case "$(machine)" in
47 nslu2)
48 sysconf=$(find_mtd_part "SysConf")
49 echo model=nslu2
50 strings $sysconf ;;
51 nas100d)
52 sysconf=$(find_mtd_part "sysconfig")
53 echo model=nas100d
54 strings $sysconf ;;
55 *)
56 echo model=$(machine) ;;
57 esac
58 ) | awk '
59 function p(cfgname, name) {
60 if (c[name] != "") print " option " cfgname " \"" c[name] "\""
61 }
62
63 BEGIN {
64 FS="="
65 getline model
66 }
67
68 { c[$1] = $2 }
69
70 END {
71 print "#### Loopback configuration"
72 print "config interface loopback"
73 print " option ifname \"lo\""
74 print " option proto static"
75 print " option ipaddr 127.0.0.1"
76 print " option netmask 255.0.0.0"
77 print ""
78 print ""
79 print "#### LAN configuration"
80 print "config interface lan"
81 print " option ifname eth0"
82 if ((model == "nslu2") || (model == "nas100d")) {
83 p("proto", "bootproto")
84 p("ipaddr", "ip_addr")
85 p("netmask", "netmask")
86 p("gateway", "gateway")
87 p("dns", "dns_server1")
88 p("hostname", "disk_server_name")
89 }
90 else {
91 print " option proto dhcp"
92 }
93 }' > /etc/config/network
94 }