summaryrefslogtreecommitdiffstats
path: root/hooks/resume
blob: f514eb663077fb71d6a678b2a75281fdc4f440ec (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
# vim:set ft=sh:
run_hook ()
{
    fmtdevice () { echo "${1}:${2}"; }

    if [ -n "${resume}" ]; then
        if echo ${resume} | grep -q ':'; then
            # Tux-on-ice syntax: swap:/dev/sda2 or file:/dev/sda2:0xdeadbeef
            resumedev="$(echo ${resume} | cut -d: -f2)"
        else
            # Classical syntax: just a device
            resumedev="${resume}"
        fi
        if poll_device "${resumedev}" ${rootdelay}; then
            if echo ${resume} | grep -q ':'; then
                # Try resuming with tuxonice
                tuxoniceroot="/sys/power/tuxonice"
                if [ -d "${tuxoniceroot}" ]; then
                    echo ${resume} > ${tuxoniceroot}/resume
                    echo > ${tuxoniceroot}/do_resume
                fi
            else
                # Try resuming with vanilla hibernation
                if [ -e "/sys/power/resume" ]; then
                    printf "%d:%d" $(stat -Lc "0x%t 0x%T" ${resume}) > /sys/power/resume
                fi
            fi
        fi
    fi
}