0d2a3ca10723bea4d351e9e767ac654916199954
[openwrt.git] / package / 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 $interface $mode
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"
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 "network.interface.$1"
51 fi
52
53 if [ -n "$setup_wifi" ] && grep -q 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" ] && [ "$wnet" = "$network" ]; then
62                         append radio_devs "$wdev" "$N"
63                 fi
64         }
65
66         local radio_devs
67         local network="$1"
68         config_load wireless
69         config_foreach find_related_radios wifi-iface
70
71         local dev
72         for dev in $(echo "$radio_devs" | sort -u); do
73                 /sbin/wifi up "$dev"
74         done
75 fi