#!/bin/sh

# If you have problems with suspend/resume
# follow the instructions given @ 
# http://en.opensuse.org/ACPI_Suspend_debugging
# and proceed step by step testing all modules
# Common ones known to cause problems are
# USB and wifi (depending on your card)
# 
# X22/X24 users should use the radeonfb kernel patch 
# to fix the high power drain rate during ACPI sleep

grep -q closed /proc/acpi/button/lid/*/state
if [ $? = 0 ]
then
        chvt 1

        # Unmount any NFS or SMB filesystems:
        umount -a -r -t nfs,smbfs

        # remove modules
        rmmod uhci-hcd   ## USB module

	# disable wakeup-on-lan (reduces power consumption in sleep)
        ethtool -s eth0 wol d

        # update the disk super block
        sync

        # wait a second
        sleep 1

        # turn the LCD off
        # not needed if radeonfb patch is used
        radeontool light off

        # suspend to ram
        echo -n mem > /sys/power/state

        # load modules back
        modprobe uhci-hcd

        # go back to X
        chvt 7

	# restart laptop-mode only if your HDD does
	# not go into powersaving mode when on battery 
	#/etc/init.d/laptop-mode restart

	# this is needed only if the sound
	# is muted on resume
	#amixer set Master mute >/dev/null 2>&1
	#amixer set PCM mute >/dev/null 2>&1
	#amixer set Master unmute >/dev/null 2>&1
	#amixer set PCM unmute >/dev/null 2>&1
fi
