summaryrefslogtreecommitdiffstats
path: root/scripts/netcfg-wpa_actiond-action
blob: 1f293643dfe04d032311d221ec19de1e67a6205d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#! /bin/bash

interface="$1"
ssid="$2"
profile="$3"
action="$4"

. /usr/lib/network/network
[[ "$profile" ]] && load_profile "$profile"

case $action in
    CONNECT)
        if [[ -z $profile ]]; then
            # Load interface specific config
            [[ -f "$IFACE_DIR/$interface" ]] && source "$IFACE_DIR/$interface"
            dhcpcd -qL -t "${DHCP_TIMEOUT:-10}" -K $DHCP_OPTIONS "$interface"
            exit $?
        fi
        if ! DHCPCD_INTERNAL_OPTIONS="-K" $CONN_DIR/ethernet up "$profile"; then
            exit 1 # what to do if fail?
        fi

        set_profile up "$profile"

        if ! ( eval $POST_UP ); then    # JP: sandbox the eval
            # failing POST_UP will take interface down
            "$CONN_DIR/$ethernet" down "$profile"
            exit 1
        fi
        ;;
    DISCONNECT)
        if [[ -z $profile ]]; then
            dhcpcd -k "$interface"
            exit $?
        fi
        if ! ( eval $PRE_DOWN ); then   # JP: sandbox the eval
            exit 1
        fi
        if ! "$CONN_DIR/ethernet" down "$profile"; then
            exit 1
        fi
        if ! ( eval $POST_DOWN ); then  # JP: sandbox the eval
            exit 1
        fi
        set_profile down "$profile"
        ;;
    LOST|REESTABLISHED)
        # Not handled.
        exit 0
        ;;
    *)
        # ???
        exit 1
        ;;
esac