ar71xx: create generic network config from an uci-defaults script
[openwrt/svn-archive/archive.git] / target / linux / ar71xx / base-files / etc / uci-defaults / network
1 #!/bin/sh
2 #
3 # Copyright (C) 2011 OpenWrt.org
4 #
5
6 set_interface_loopback() {
7 uci batch <<EOF
8 set network.loopback='interface'
9 set network.loopback.ifname='lo'
10 set network.loopback.proto='static'
11 set network.loopback.ipaddr='127.0.0.1'
12 set network.loopback.netmask='255.0.0.0'
13 EOF
14 }
15
16 set_interface_lan() {
17 local ifname=$1
18
19 uci batch <<EOF
20 set network.lan='interface'
21 set network.lan.ifname='$ifname'
22 set network.lan.type='bridge'
23 set network.lan.proto='static'
24 set network.lan.ipaddr='192.168.1.1'
25 set network.lan.netmask='255.255.255.0'
26 EOF
27 }
28
29 set_interface_wan() {
30 local ifname=$1
31
32 uci batch <<EOF
33 set network.wan='interface'
34 set network.wan.ifname='$ifname'
35 set network.wan.proto='dhcp'
36 EOF
37 }
38
39 set_interfaces_lan_wan() {
40 local lan_ifname=$1
41 local wan_ifname=$2
42
43 set_interface_lan "$lan_ifname"
44 set_interface_wan "$wan_ifname"
45 }
46
47 [ -e /etc/config/network ] && exit 0
48
49 touch /etc/config/network
50
51 set_interface_loopback
52
53 . /lib/ar71xx.sh
54
55 board=$(ar71xx_board_name)
56
57 case "$board" in
58 *)
59 set_interfaces_lan_wan "eth0" "eth1"
60 ;;
61 esac
62
63 uci commit network
64
65 exit 0