Root/package/network/config/netifd/files/sbin/ifup

1#!/bin/sh
2
3ifup_all=
4setup_wifi=
5
6if_call() {
7    local interface="$1"
8    for mode in $modes; do
9        ubus call $interface $mode
10    done
11}
12
13case "$0" in
14    *ifdown) modes=down;;
15    *ifup)
16        modes="down up"
17        setup_wifi=1
18    ;;
19    *) echo "Invalid command: $0";;
20esac
21
22while :; 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
36done
37
38[ "$modes" = "down up" ] && ubus call network reload
39if [ -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
45else
46    ubus -S list "network.interface.$1" > /dev/null || {
47        echo "Interface $1 not found"
48        exit
49    }
50    if_call "network.interface.$1"
51fi
52
53if [ -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    local radio_devs
71    local network="$1"
72    config_load wireless
73    config_foreach find_related_radios wifi-iface
74
75    local dev
76    for dev in $(echo "$radio_devs" | sort -u); do
77        /sbin/wifi up "$dev"
78    done
79fi
80

Archive Download this file



interactive