uci-defaults: add ucidef_set_led_mmc
[openwrt/svn-archive/archive.git] / package / base-files / files / lib / functions / uci-defaults.sh
1 #!/bin/sh
2 # Copyright (C) 2011 OpenWrt.org
3
4 UCIDEF_LEDS_CHANGED=0
5
6 ucidef_set_led_netdev() {
7 local cfg="led_$1"
8 local name=$2
9 local sysfs=$3
10 local dev=$4
11
12 uci -q get system.$cfg && return 0
13
14 uci batch <<EOF
15 set system.$cfg='led'
16 set system.$cfg.name='$name'
17 set system.$cfg.sysfs='$sysfs'
18 set system.$cfg.trigger='netdev'
19 set system.$cfg.dev='$dev'
20 set system.$cfg.mode='link tx rx'
21 EOF
22 UCIDEF_LEDS_CHANGED=1
23 }
24
25 ucidef_set_led_usbdev() {
26 local cfg="led_$1"
27 local name=$2
28 local sysfs=$3
29 local dev=$4
30
31 uci -q get system.$cfg && return 0
32
33 uci batch <<EOF
34 set system.$cfg='led'
35 set system.$cfg.name='$name'
36 set system.$cfg.sysfs='$sysfs'
37 set system.$cfg.trigger='usbdev'
38 set system.$cfg.dev='$dev'
39 set system.$cfg.interval='50'
40 EOF
41 UCIDEF_LEDS_CHANGED=1
42 }
43
44 ucidef_set_led_wlan() {
45 local cfg="led_$1"
46 local name=$2
47 local sysfs=$3
48 local trigger=$4
49
50 uci -q get system.$cfg && return 0
51
52 uci batch <<EOF
53 set system.$cfg='led'
54 set system.$cfg.name='$name'
55 set system.$cfg.sysfs='$sysfs'
56 set system.$cfg.trigger='$trigger'
57 EOF
58 UCIDEF_LEDS_CHANGED=1
59 }
60
61 ucidef_set_led_switch() {
62 local cfg="led_$1"
63 local name=$2
64 local sysfs=$3
65 local trigger=$4
66 local port_mask=$5
67
68 uci -q get system.$cfg && return 0
69
70 uci batch <<EOF
71 set system.$cfg='led'
72 set system.$cfg.name='$name'
73 set system.$cfg.sysfs='$sysfs'
74 set system.$cfg.trigger='$trigger'
75 set system.$cfg.port_mask='$port_mask'
76 EOF
77 UCIDEF_LEDS_CHANGED=1
78 }
79
80 ucidef_set_led_default() {
81 local cfg="led_$1"
82 local name=$2
83 local sysfs=$3
84 local default=$4
85
86 uci -q get system.$cfg && return 0
87
88 uci batch <<EOF
89 set system.$cfg='led'
90 set system.$cfg.name='$name'
91 set system.$cfg.sysfs='$sysfs'
92 set system.$cfg.default='$default'
93 EOF
94 UCIDEF_LEDS_CHANGED=1
95 }
96
97 ucidef_set_led_rssi() {
98 local cfg="led_$1"
99 local name=$2
100 local sysfs=$3
101 local iface=$4
102 local minq=$5
103 local maxq=$6
104 local offset=$7
105 local factor=$8
106
107 uci -q get system.$cfg && return 0
108
109 uci batch <<EOF
110 set system.$cfg='led'
111 set system.$cfg.name='$name'
112 set system.$cfg.sysfs='$sysfs'
113 set system.$cfg.trigger='rssi'
114 set system.$cfg.iface='rssid_$iface'
115 set system.$cfg.minq='$minq'
116 set system.$cfg.maxq='$maxq'
117 set system.$cfg.offset='$offset'
118 set system.$cfg.factor='$factor'
119 EOF
120 UCIDEF_LEDS_CHANGED=1
121 }
122
123 ucidef_set_led_timer() {
124 local cfg="led_$1"
125 local name=$2
126 local sysfs=$3
127 local delayon=$4
128 local delayoff=$5
129
130 uci -q get system.$cfg && return 0
131
132 uci batch <<EOF
133 set system.$cfg='led'
134 set system.$cfg.name='$name'
135 set system.$cfg.sysfs='$sysfs'
136 set system.$cfg.trigger='timer'
137 set system.$cfg.delayon='$delayon'
138 set system.$cfg.delayoff='$delayoff'
139 EOF
140 UCIDEF_LEDS_CHANGED=1
141 }
142
143 ucidef_set_led_mmc() {
144 local cfg="led_$1"
145 local name=$2
146 local sysfs=$3
147 local trigger=$4
148
149 uci -q get system.$cfg && return 0
150
151 uci batch <<EOF
152 set system.$cfg='led'
153 set system.$cfg.name='$name'
154 set system.$cfg.sysfs='$sysfs'
155 set system.$cfg.trigger='$trigger'
156 EOF
157 UCIDEF_LEDS_CHANGED=1
158 }
159
160 ucidef_set_rssimon() {
161 local dev="$1"
162 local refresh="$2"
163 local threshold="$3"
164
165 local cfg="rssid_$dev"
166
167 uci -q get system.$cfg && return 0
168
169 uci batch <<EOF
170 set system.$cfg='rssid'
171 set system.$cfg.dev='$dev'
172 set system.$cfg.refresh='$refresh'
173 set system.$cfg.threshold='$threshold'
174 EOF
175 UCIDEF_LEDS_CHANGED=1
176 }
177
178 ucidef_commit_leds()
179 {
180 [ "$UCIDEF_LEDS_CHANGED" = "1" ] && uci commit system
181 }
182
183 ucidef_set_interface_loopback() {
184 uci batch <<EOF
185 set network.loopback='interface'
186 set network.loopback.ifname='lo'
187 set network.loopback.proto='static'
188 set network.loopback.ipaddr='127.0.0.1'
189 set network.loopback.netmask='255.0.0.0'
190 set network.globals='globals'
191 set network.globals.ula_prefix='auto'
192 EOF
193 }
194
195 ucidef_set_interface_raw() {
196 local cfg=$1
197 local ifname=$2
198 local proto=${3:-"none"}
199
200 uci batch <<EOF
201 set network.$cfg='interface'
202 set network.$cfg.ifname='$ifname'
203 set network.$cfg.proto='$proto'
204 EOF
205 }
206
207 ucidef_set_interface_lan() {
208 local ifname=$1
209
210 uci batch <<EOF
211 set network.lan='interface'
212 set network.lan.ifname='$ifname'
213 set network.lan.force_link=1
214 set network.lan.type='bridge'
215 set network.lan.proto='static'
216 set network.lan.ipaddr='192.168.1.1'
217 set network.lan.netmask='255.255.255.0'
218 set network.lan.ip6assign='60'
219 EOF
220 }
221
222 ucidef_set_interface_wan() {
223 local ifname=$1
224
225 uci batch <<EOF
226 set network.wan='interface'
227 set network.wan.ifname='$ifname'
228 set network.wan.proto='dhcp'
229 set network.wan6='interface'
230 set network.wan6.ifname='$ifname'
231 set network.wan6.proto='dhcpv6'
232 EOF
233 }
234
235 ucidef_set_interfaces_lan_wan() {
236 local lan_ifname=$1
237 local wan_ifname=$2
238
239 ucidef_set_interface_lan "$lan_ifname"
240 ucidef_set_interface_wan "$wan_ifname"
241 }
242
243 ucidef_set_interface_macaddr() {
244 local ifname=$1
245 local mac=$2
246
247 uci batch <<EOF
248 set network.$ifname.macaddr='$mac'
249 EOF
250 }
251
252 ucidef_add_switch() {
253 local name=$1
254 local reset=$2
255 local enable=$3
256 uci batch <<EOF
257 add network switch
258 set network.@switch[-1].name='$name'
259 set network.@switch[-1].reset='$reset'
260 set network.@switch[-1].enable_vlan='$enable'
261 EOF
262 }
263
264 ucidef_add_switch_vlan() {
265 local device=$1
266 local vlan=$2
267 local ports=$3
268 uci batch <<EOF
269 add network switch_vlan
270 set network.@switch_vlan[-1].device='$device'
271 set network.@switch_vlan[-1].vlan='$vlan'
272 set network.@switch_vlan[-1].ports='$ports'
273 EOF
274 }
275
276 ucidef_add_switch_port() {
277 local device=$1
278 local port=$2
279 uci batch <<EOF
280 add network switch_port
281 set network.@switch_port[-1].device='$device'
282 set network.@switch_port[-1].port='$port'
283 EOF
284 }
285