summaryrefslogtreecommitdiffstats
path: root/rc.d/net-auto-wireless
blob: d6a3c44bb9dc18f3c60d851da7d61b1be11ad3d6 (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
57
58
59
60
61
62
63
64
65
#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions
. /usr/lib/network/globals
. /etc/conf.d/netcfg

if [[ ! -x /usr/sbin/wpa_actiond ]]; then
   echo "Please install 'wpa_actiond' to use net-auto-wireless"
   exit 1
fi

if [ -z "${WIRELESS_INTERFACE}" ]; then
    echo "No interface name set. Add to /etc/conf.d/netcfg a line"
    echo "  WIRELESS_INTERFACE=\"your_interface\""
    exit 1
fi

case "$1" in
    start)
        if ! ck_daemon net-auto-wireless; then
            exit_stderr "net-auto-wireless has already been started: try \"/etc/rc.d/net-auto-wireless restart\""
        fi
        # Ensure any device renaming has occurred as intended
        for daemon in "${DAEMONS[@]}"; do
            if [[ "$daemon" = "${daemon#!}" && "$daemon" = "net-rename" ]]; then
                if ck_daemon net-rename; then
                    /etc/rc.d/net-rename start
                fi
            fi
        done

        stat_busy "Starting netcfg auto-wireless mode for interface ${WIRELESS_INTERFACE}"
        /usr/bin/netcfg-wpa_actiond "${WIRELESS_INTERFACE}" >/dev/null
        if [ $? -eq 0 ]; then
            add_daemon net-auto-wireless
            stat_done
        else
            stat_fail
        fi
        ;;
    stop)
        if ! ck_daemon net-auto-wireless; then
            stat_busy "Stopping netcfg auto-wireless mode for interface ${WIRELESS_INTERFACE}"
            /usr/bin/netcfg-wpa_actiond stop "${WIRELESS_INTERFACE}" >/dev/null
            if [ $? -eq 0 ]; then
                rm_daemon net-auto-wireless
                stat_done
            else
                stat_fail
            fi
        fi
        ;;
    restart)
        "$0" stop
        sleep 1
        "$0" start
        ;;
    *)
        echo "Usage: $0 {start|stop|restart}"
        exit 1
        ;;
esac
exit 0
# vim: ft=sh ts=4 et sw=4: