summaryrefslogtreecommitdiffstats
path: root/contrib/pm-utils.handler
blob: 79cad6ac502bb677cd5f2df041c95622c169a9f7 (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
66
67
68
69
70
71
72
73
74
#!/bin/bash

. /usr/lib/pm-utils/functions

[[ -f /usr/lib/network/network ]] || exit $NA
. /usr/lib/network/network
. /etc/rc.conf
. /etc/conf.d/netcfg

WIRELESS_INTERFACE=${WIRELESS_INTERFACE:-wlan0}

auto_resume()
{
    if checkyesno ${RESTOREPROFILES:-no}; then
        all_resume
        sleep 2
    fi
    restartservice net-auto-wireless
    restartservice net-auto-wired
    restartservice net-profiles
}

daemon_suspend_all()
{
    stopservice net-auto-wireless
    stopservice net-auto-wired
    stopservice net-profiles
}

case "$1" in
    hibernate|suspend_hybrid|suspend)
        report_notice "suspending all interfaces..."
        daemon_suspend_all
        if checkyesno "${RESTOREPROFILES:-no}"; then        
            interface_suspend all
        fi
        ;;
    thaw|resume)
        if [ -f "$STATE_DIR/interface/${WIRELESS_INTERFACE}" ]; then
            report_notice "resuming all interfaces..."
            auto_resume ${WIRELESS_INTERFACE}
        else
            report_notice "resuming all interfaces except wireless..."
            all_resume ${WIRELESS_INTERFACE}
        fi
        ;;
    radio_off)
        report_notice "suspending wireless interface..."
        interface_suspend ${WIRELESS_INTERFACE} no
        set_iface disabled ${WIRELESS_INTERFACE}
        bring_interface forcedown ${WIRELESS_INTERFACE}
        ;;
    radio_on)
        report_notice "resuming wireless interface..."
        auto_resume ${WIRELESS_INTERFACE}
        if [ -x /etc/pm/power.d/??wifi ]; then
            /usr/bin/on_ac_power    # this is in pm-utils
            case $? in
                0)  # on ac
                    /etc/pm/power.d/??wifi false
                    ;;
                1)  # on battery
                    /etc/pm/power.d/??wifi true
                    ;;
            esac
        fi
        ;;
    *)
        ;;
esac

exit $?

# vim: ft=sh ts=4 et sw=4: