#!/bin/sh

# if launched through a lid event and lid is open, do nothing
echo "$1" | grep "button/lid" && grep -q open /proc/acpi/button/lid/LID/state && exit 0

# remove USB drivers
rmmod uhci_hcd
rmmod ehci_hcd
sleep 2
 
# sync filesystem and clock
sync
/sbin/hwclock --systohc

# go to sleep
sleep 3 ; echo -n "mem" > /sys/power/state

# readjust the clock (it might be off a bit after suspend)
/sbin/hwclock --adjust
/sbin/hwclock --hctosys

# reload USB 1.1 driver
modprobe uhci_hcd
modprobe ehci_hcd
