#!/usr/bin/ash
# SPDX-License-Identifier: GPL-2.0-only

run_hook () {
    local resumedev

    case $resume in
        '')
            err "resume: no device specified for hibernation"
            return 1;
            ;;
        swap:*|file:*)
            # tux-on-ice syntax: swap:/dev/sda2 or file:/dev/sda2:0xdeadbeef
            if [ -d /sys/power/tuxonice  ]; then
                echo "$resume" >/sys/power/tuxonice/resume
                echo >/sys/power/tuxonice/do_resume
                return 0
            else
                err "resume: tux-on-ice syntax detected, but no support found"
                return 1
            fi
            ;;

        *)
            # standard hibernation
            if resumedev=$(resolve_device "$resume" "$rootdelay"); then
                if [ -e /sys/power/resume ]; then
                    printf "%d:%d" $(stat -Lc "0x%t 0x%T" "$resumedev") >/sys/power/resume
                    return 0
                else
                    err "resume: no hibernation support found"
                    return 1
                fi
            fi
            ;;
    esac

    err "resume: hibernation device '$resume' not found"
    return 1
}

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