#!/bin/sh whoami=`whoami` if [ "$whoami" != "root" ]; then echo "Must be ran as root.." logger $0 being ran by $whoami exit fi suspendstring="Suspending" if [ "$1" != "" ]; then if [ "$1" == "hibernate" ]; then HIBERNATE=1 suspendstring=Hibernating fi fi echo "$suspendstring in 5s, ^c to abort.." logger -t Suspend $suspendstring `hostname` sleep 5s # Calls my sleeptime script, if you don't use it, comment this out. Obviously # you'll have to edit the path regardless. /home/wally/bin/sleeptime sleep # You could do special stuff here based on the lid, I decided not to but left # the logic in. lid=`grep closed /proc/acpi/button/lid/LID0/state` if [ -z "$lid" ]; then echo "Lid open, suspending to ram.." else echo "Lid closed, suspending to disk.. (er, not really, disabled)" # HIBERNATE=1 fi # Edit this regardless, but this locks my KDE. dcop --user wally --session .DCOPserver_rivendell__0 kdesktop KScreensaverIface lock # discover video card's ID - This is another video workaround ID=`lspci | grep VGA | awk '{ print $1 }' | sed -e 's@0000:@@' -e 's@:@/@'` # securely create a temporary file TMP_FILE=`mktemp /var/tmp/video_state.XXXXXX` trap 'rm -f $TMP_FILE' 0 1 15 cat /proc/bus/pci/$ID > $TMP_FILE # These modules give me problems or need to be restarted anyway. echo "Stopping network and cpuspeed.." service network stop #service cpuspeed stop service wpa_supplicant stop # Kill ipw3945d, it gives problems if it's loaded echo "Killing 3495 drivers.." ipw3945d --kill service ipw3945 stop # Remove modules, these give me problems if they're still there. echo "Removing modules.." rmmod uhci_hcd rmmod ehci_hcd rmmod ipw3945 rmmod ieee80211 rmmod sdhci rmmod mmc_core #rmmod thermal # Save clock /sbin/hwclock --systohc sync # Change to VT1 (console) This is a workaround for a video issue I think. chvt 1 # Debugging/informative stuff.. date acpitool sleep 1s # Suspend to ram if [ "$HIBERNATE" == "1" ]; then echo "Hibernating.." echo disk > /sys/power/state else echo "Suspending.." echo mem > /sys/power/state fi # This is where we come back to life, script picks up from here on the way back out echo "Resuming.." # Again, info/debugging acpitool date # Reload the modules and such that we unloaded earlier /sbin/hwclock --hctosys echo "Loading modules.." modprobe uhci_hcd modprobe ehci_hcd modprobe ipw3945 modprobe ieee80211 modprobe sdhci modprobe mmc_core #modprobe thermal # Restore the video workaround stuff we did earlier.. cat $TMP_FILE > /proc/bus/pci/$ID rm -f $TMP_FILE # Restart the services we stopped earlier.. echo "Restarting network and cpuspeed.." service ipw3945 start service network start #service cpuspeed start # Restart wpa_supplicant last, delayed a bit, otherwise it sometimes fails. sleep 2s service wpa_supplicant start # Change back to X, yes, we're going to X, console, and back to X. Otherwise # there are sometimes problems here.. sleep 1s chvt 7 chvt 1 chvt 7 # Sleeptime stuff here, edit or remove /home/wally/bin/sleeptime resume logger -t Suspend `/home/wally/bin/sleeptime sleeptime` # Informative stuff.. logger -t Suspend Resumed `hostname` from suspension # More sleeptime stuff here.. This puts a cute message on my screen after everything # is back to working so I can see how long the laptop waa asleep. sleep 10s dcop --user wally --session .DCOPserver_rivendell__0 knotify default notify eventname "Awake again" "`/home/wally/bin/sleeptime sleeptime`" '' '' 17 0