#!/bin/bash # Copyright Jean-Philippe Guillemin . This program is free software; you can redistribute # it and/or modify it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or (at your option) # any later version. Please take a look at http://www.gnu.org/copyleft/gpl.htm # If possible, log events in /var/log/messages: if [ -x /usr/bin/logger ]; then LOGGER="/usr/bin/logger -t ${0##*/}" else LOGGER='/bin/cat > /dev/null' fi # Dealing with the video card configuration tmpfile=$(mktemp /tmp/video_state.XXXXXX) trap 'rm -f $tmpfile' 0 1 15 vid=$(/sbin/lspci | sed -e '/VGA/!d' -e 's/ .*//' -e 's@0000:@@' -e 's@:@/@' -eq) procvideoid="/proc/bus/pci/$vid" unloadlist="/etc/modules.suspend" reload_modules(){ for module in $(/sbin/lsmod | sed -n 's/^\([^ \t]*\)[ \t]*[0-9]\+[ \t]*[0-9]*.*[ \t]*$/\1/p' | egrep -f $unloadlist) ; do /sbin/rmmod -f $module 2>&1 | $LOGGER /sbin/modprobe $module 2>&1 | $LOGGER done } suspend(){ sync echo 3 > /proc/sys/vm/drop_caches /sbin/swapoff -a /sbin/swapon -a /sbin/hwclock --systohc 2>&1 | $LOGGER /usr/sbin/alsactl store 2>&1 | $LOGGER for mixer in $(/usr/bin/amixer scontrols | sed -n "s/.*'\(.*\)',/\1/p") ; do /usr/bin/amixer -q sset $mixer mute | $LOGGER done #fuser -k /dev/snd/* 2>&1 | $LOGGER #fuser -k /dev/sound/* 2>&1 | $LOGGER chmod 000 /dev/snd/* /dev/sound/* cat $procvideoid > $tmpfile echo -n $1 > /sys/power/state } resume(){ cat $tmpfile > $procvideoid /sbin/hwclock --hctosys 2>&1 | $LOGGER reload_modules chmod 666 /dev/snd/* /dev/sound/* /etc/rc.d/rc.alsa 2>&1 | $LOGGER /usr/sbin/alsactl restore 2>&1 | $LOGGER /etc/rc.d/rc.inet1 wakup rm -f $tmpfile } standby(){ if [ "$(grep "standby" /sys/power/state)" ] ; then suspend standby resume exit elif [ "$(grep "mem" /sys/power/state)" ] ; then suspend mem resume exit else echo "No standby or suspend to memory power state available, exiting" exit fi } hibernate(){ if [ "$(grep "disk" /sys/power/state)" ] ; then suspend disk resume exit else echo "No suspend to disk power state available, trying standby..." standby fi } case "${0##*/}" in 'hibernate') hibernate ;; 'standby') standby ;; *) echo "Usage : [hibernate|standby]" exit 1 ;; esac