#!/bin/sh
# /etc/acpi/lidbtn.sh
# Initiates a suspend-to-ram when the lid has been closed

# Initial settings
exec > /dev/null 2>&1
umask 0077
PATH="/sbin:/bin:/usr/sbin:/usr/bin"

# Suspend
echo "Going to sleep at `date`"
echo "* chvt 1"
/usr/bin/chvt 1
echo "* save vbestate"
/usr/sbin/vbetool vbestate save > /etc/acpi/vbestate
echo "* writing to /sys"
echo -n "mem" > /sys/power/state
echo ""

# Resume
echo "Back from sleep at `date`"
echo "* restore vbestate"
/bin/cat /etc/acpi/vbestate | /usr/sbin/vbetool vbestate restore
echo "* restore clock"
/sbin/hwclock --hctosys
echo "* chvt 7"
/usr/bin/chvt 7
echo "* done"
echo ""

# Done
exit 0
