netifd: ifup-shellscript - fix wrong usage of 'local'
[openwrt/svn-archive/archive.git] / package / network / config / netifd / files / sbin / ifup
1 #!/bin/sh
2
3 ifup_all=
4 setup_wifi=
5
6 if_call() {
7 local interface="$1"
8 for mode in $modes; do
9 ubus call network.interface $mode "{ \"interface\" : \"$interface\" }"
10 done
11 }
12
13 case "$0" in
14 *ifdown) modes=down;;
15 *ifup)
16 modes="down up"
17 setup_wifi=1
18 ;;
19 *) echo "Invalid command: $0";;
20 esac
21
22 while :; do
23 case "$1" in
24 -a)
25 ifup_all=1
26 shift
27 ;;
28 -w)
29 setup_wifi=
30 shift
31 ;;
32 *)
33 break
34 ;;
35 esac
36 done
37
38 [ "$modes" = "down up" ] && ubus call network reload
39 if [ -n "$ifup_all" ]; then
40 for interface in `ubus -S list 'network.interface.*'`; do
41 if_call "${interface##network.interface.}"
42 done
43 [ -n "$setup_wifi" ] && /sbin/wifi up
44 exit
45 else
46 ubus -S list "network.interface.$1" > /dev/null || {
47 echo "Interface $1 not found"
48 exit
49 }
50 if_call "$1"
51 fi
52
53 if [ -n "$setup_wifi" ] && grep -sq config /etc/config/wireless; then
54 . /lib/functions.sh
55
56 find_related_radios() {
57 local wdev wnet
58 config_get wdev "$1" device
59 config_get wnet "$1" network
60
61 if [ -n "$wdev" ]; then
62 for wnet in $wnet; do
63 if [ "$wnet" = "$network" ]; then
64 append radio_devs "$wdev" "$N"
65 fi
66 done
67 fi
68 }
69
70 network="$1"
71 config_load wireless
72 config_foreach find_related_radios wifi-iface
73
74 for dev in $(echo "$radio_devs" | sort -u); do
75 /sbin/wifi up "$dev"
76 done
77 fi