summaryrefslogtreecommitdiffstats
path: root/target/linux/ixp4xx-2.6/base-files/etc/init.d/netconfig
blob: ded5f4b8d62dc6db40f91ea53b46283cbcab505f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/sh /etc/rc.common
# Copyright (C) 2006 OpenWrt.org

START=15

# hardware
#  the 'Hardware' string from cpuinfo
hardware(){
	sed -n 's!^Hardware	*: !!p' /proc/cpuinfo
}
#
# machine
#  outputs an identifier of the current machine - i.e. the board
#  slugos is running on.
machine(){
	case "$(hardware)" in
	*Avila*)	echo avila;;
	*Loft*)		echo loft;;
	*NAS?100d*)	echo nas100d;;
	*DSM?G600*)	echo dsmg600;;
	*NSLU2*)	echo nslu2;;
	*FSG?3*)	echo fsg3;;
	*Gateway?7001*)	echo gateway7001;;
	*)		echo unknown;;
	esac
}

start() {
	[ -e /etc/config/network ] && exit 0

	mkdir -p /etc/config

	(
		case "$(machine)" in
			nslu2)
				sysconf=$(find_mtd_part "SysConf")
				echo model=nslu2
				strings $sysconf ;;
			nas100d)
				sysconf=$(find_mtd_part "sysconfig")
				echo model=nas100d
				strings $sysconf ;;
			*)
				echo model=$(machine) ;;
		esac
	) | awk '
	function p(cfgname, name) {
		if (c[name] != "") print "	option " cfgname "	\"" c[name] "\""
	}

	BEGIN {
		FS="="
	}
	
	{	c[$1] = $2	}
	
	END {
		print "#### Loopback configuration"
		print "config interface loopback"
		print "	option ifname	\"lo\""
		print "	option proto	static"
		print "	option ipaddr	127.0.0.1"
		print "	option netmask	255.0.0.0"
		print ""
		print ""
		print "#### LAN configuration"
		print "config interface lan"
		print "	option ifname	\"eth0\""
		if ((c["model"] == "nslu2") || (c["model"] == "nas100d")) {
			p("proto", "bootproto")
			p("ipaddr", "ip_addr")
			p("netmask", "netmask")
			p("gateway", "gateway")
			p("dns", "dns_server1")
			p("hostname", "disk_server_name")
		}
		else {
			print "	option proto	dhcp"
		}
	}' > /etc/config/network

	ifup loopback
	ifup lan
}