#!/bin/bash # # ACPI Suspend by # Based on rc.sysinit and rc.halt from Red Hat Linux 7.3 # # chkconfig: 4 00 00 # description: Prepare the system for suspended mode using ACPI # Source functions .. /etc/init.d/functions if [ -f /etc/sysconfig/clock ]; then . /etc/sysconfig/clock fi revive() { # Set the system clock. ARC=0 SRM=0 UTC=0 if [ -f /etc/sysconfig/clock ]; then # convert old style clock config to new values if [ "${CLOCKMODE}" = "GMT" ]; then UTC=true elif [ "${CLOCKMODE}" = "ARC" ]; then ARC=true fi fi CLOCKDEF="" CLOCKFLAGS="$CLOCKFLAGS --hctosys" case "$UTC" in yes|true) CLOCKFLAGS="$CLOCKFLAGS --utc"; CLOCKDEF="$CLOCKDEF (utc)"; ;; no|false) CLOCKFLAGS="$CLOCKFLAGS --localtime"; CLOCKDEF="$CLOCKDEF (localtime)"; ;; esac case "$ARC" in yes|true) CLOCKFLAGS="$CLOCKFLAGS --arc"; CLOCKDEF="$CLOCKDEF (arc)"; ;; esac case "$SRM" in yes|true) CLOCKFLAGS="$CLOCKFLAGS --srm"; CLOCKDEF="$CLOCKDEF (srm)"; ;; esac /sbin/hwclock $CLOCKFLAGS action $"Setting clock $CLOCKDEF: `date`" date # Initialize USB controller and HID devices usb=0 if ! grep -iq "nousb" /proc/cmdline 2>/dev/null && ! grep -q "usb" /proc/devices 2>/dev/null ; then action $"Reinitializing USB: " true aliases=`/sbin/modprobe -c | awk '/^alias usb-controller/ { print $3 }'` if [ -n "$aliases" -a "$aliases" != "off" ] ; then modprobe usbcore action $"Mounting USB filesystem: " mount -t usbdevfs usbdevfs /proc/bus/usb for alias in $aliases ; do [ "$alias" != "off" ] && action $"Initializing USB controller ($alias): " modprobe $alias done [ $? -eq 0 -a -n "$aliases" ] && usb=1 fi fi if ! grep -iq "nousb" /proc/cmdline 2>/dev/null && grep -q "usb" /proc/devices 2>/dev/null ; then usb=1 fi needusbstorage= if [ $usb = "1" ]; then sleep 5 mouseoutput=`cat /proc/bus/usb/devices 2>/dev/null|grep -E "^I.*Cls=03..*Prot=02"` kbdoutput=`cat /proc/bus/usb/devices 2>/dev/null|grep -E "^I.*Cls=03.*Prot=01"` needusbstorage=`cat /proc/bus/usb/devices 2>/dev/null|grep -e "^I.*Cls=08"` if [ -n "$kbdoutput" ] || [ -n "$mouseoutput" ]; then action $"Initializing USB HID interface: " modprobe hid 2> /dev/null fi if [ -n "$kbdoutput" ]; then action $"Initializing USB keyboard: " modprobe keybdev fi if [ -n "$mouseoutput" ]; then action $"Initializing USB mouse: " modprobe mousedev fi fi # Enter (potentially) /proc/bus/usb into mtab. #[ -d /proc/bus/usb ] && mount -f -t usbdevfs usbdevfs /proc/bus/usb # Load usb storage here, to match most other things if [ -n "$needusbstorage" ]; then modprobe usb-storage >/dev/null 2>&1 fi } snooze() { # Sync the system clock. ARC=0 SRM=0 UTC=0 if [ -f /etc/sysconfig/clock ]; then # convert old style clock config to new values if [ "${CLOCKMODE}" = "GMT" ]; then UTC=true elif [ "${CLOCKMODE}" = "ARC" ]; then ARC=true fi fi CLOCKDEF="" CLOCKFLAGS="$CLOCKFLAGS --systohc" case "$UTC" in yes|true) CLOCKFLAGS="$CLOCKFLAGS -u"; CLOCKDEF="$CLOCKDEF (utc)"; ;; no|false) CLOCKFLAGS="$CLOCKFLAGS --localtime"; CLOCKDEF="$CLOCKDEF (localtime)"; ;; esac case "$ARC" in yes|true) CLOCKFLAGS="$CLOCKFLAGS -A"; CLOCKDEF="$CLOCKDEF (arc)"; ;; esac case "$SRM" in yes|true) CLOCKFLAGS="$CLOCKFLAGS -S"; CLOCKDEF="$CLOCKDEF (srm)"; ;; esac action $"Syncing hardware clock to system time" /sbin/hwclock $CLOCKFLAGS [ -d /proc/bus/pccard ] && \ action $"Unloading PCMCIA modules" /sbin/modprobe -r pcmcia_core if [ -d /proc/bus/usb ] ; then umount /proc/bus/usb mods=`cat /proc/modules | sed -e '/(unused)/d' -e '/^[^ ]*usb/!d' -e 's/^\([^ ]*usb[^ ]*\) .*\[\([^]]*\)\]/\1 \2/'` action $"Unloading USB modules: " \ /sbin/modprobe -r $mods grep usb /proc/modules fi if [ -f /sleep ] ; then action $"Suspending system" true cat /sleep >/proc/acpi/sleep else action $"Sleep state not specified (/sleep)" false fi revive [ -n "$PREVLEVEL" ] && \ action $"Restoring initial runlevel" /sbin/init $PREVLEVEL } case "$1" in start|snooze) snooze ;; stop|revive) echo $"I'm awake already!" ;; *) echo $"Usage: $prog {start|snooze|stop|revive}" exit 1 esac exit 0