summaryrefslogtreecommitdiffstats
path: root/contrib/pm-utils.handler
blob: f369a6b1c278a98f0178d592556bab2003cde2a0 (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
#!/bin/bash

. /usr/lib/pm-utils/functions

[[ -f /usr/lib/network/network ]] || exit $NA
. /usr/lib/network/network

auto_resume()
{
    all_resume
    sleep 2
    # if didn't successfully resume wifi, and running net-auto daemon, then restart the daemon
    if [[ -f /var/run/daemons/net-auto && -x /usr/bin/netcfg-auto-wireless ]]; then
        if ! check_iface "$1" >/dev/null; then          # ret=1 when iface down and available
            /usr/bin/netcfg-auto-wireless "$1"
        fi
    fi
}


case "$1" in
    hibernate|suspend_hybrid|suspend)
        report_notify "suspending all interfaces..."
        interface_suspend all
        ;;
    thaw|resume)
        if "$CONN_DIR/wireless" query wlan0 enabled; then
            report_notify "resuming all interfaces..."
            auto_resume wlan0
        else
            report_notify "resuming all interfaces except wireless..."
            all_resume wlan0
        fi
        ;;
    radio_off)
        report_notify "suspending wireless interface..."
        interface_suspend wlan0 no
        set_iface disabled wlan0
        bring_interface forcedown wlan0
        ;;
    radio_on)
        report_notify "resuming wireless interface..."
        auto_resume wlan0
        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: