#!/bin/bash
#
# suspend.sh
#

# let's make sure we don't do re-suspend
if [ -f /tmp/suspended ] ; then exit; fi

touch /tmp/suspended

# Stop MySQL during suspend if running (and indicate it was running)
#/sbin/service mysqld status > /dev/null
#if [ $? == 0 ]; then
#	touch /tmp/mysql_was_running
	/sbin/service mysqld stop
#fi

# Stop mDNSResponder during suspend if running (and indicate it was running)
#/sbin/service mDNSResponder status > /dev/null
#if [ $? == 0 ]; then
#	touch /tmp/mdns_was_running
	/sbin/service mDNSResponder stop
#fi

# unmount any network filesystems
/sbin/service netfs stop

# stop wpa_supplicant
/sbin/service wpa_supplicant stop
# remove ndiswrapper
/sbin/rmmod ndiswrapper

# remove usb stuffs
/sbin/rmmod uhci_hcd
/sbin/rmmod ehci_hcd

# sync our system clock to hardware clock
/sbin/hwclock --systohc

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

### SUSPENDED; we resume here ###

## fix the video
/usr/local/sbin/video_post

# sync our hardware clock to system clock
/sbin/hwclock --hctosys

# put usb stuffs back
/sbin/modprobe ehci_hcd
/sbin/modprobe uhci_hcd

# install ndiswrapper
/sbin/modprobe ndiswrapper
# start wpa_supplicant
/sbin/service wpa_supplicant start

# mount any network filesystems
/sbin/service netfs start

# Restart mDNSResponder if it was running
#if [ -f /tmp/mdns_was_running ]; then
	/sbin/service mDNSResponder start
#	rm /tmp/mdns_was_running
#fi

# Restart MySQL if it was running
#if [ -f /tmp/mysql_was_running ]; then
	/sbin/service mysqld start
#	rm /tmp/mysql_was_running
#fi

# remove our lockfile
rm -f /tmp/suspended


