Viewing file: pm-suspend (4.05 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) | #!/bin/bash
#
# Simple suspend script
#
# Copyright 2006 Red Hat, Inc.
#
# Based on work from:
# Bill Nottingham
# Peter Jones
# David Zeuthen
# Richard Hughes
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of version 2 of the GNU General Public License as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# The rule here? Simplicity.
help_options() {
echo "pm-action [options]"
echo
echo "Options can change how the supend or hibernate is done."
echo
echo "Possible actions are:"
echo
echo " --quirk-dpms-on"
echo " --quirk-dpms-suspend"
echo " --quirk-radeon-off"
echo " --quirk-s3-bios"
echo " --quirk-s3-mode"
echo " --quirk-vbe-post"
echo " --quirk-vbemode-restore"
echo " --quirk-vbestate-restore"
echo " --quirk-vga-mode3"
echo
}
if [ -n "$EUID" -a "$EUID" != "0" ]; then
echo This utility may only be run by the root user. 1>&2
exit 1
fi
export LC_COLLATE=C
export AUTO_QUIRK="false"
export QUIRKOPTS="false"
export FROM_HAL="false"
# Get the command line options
while [ $# -gt 0 ]
do
case "$1" in
--quirk-dpms-on)
export DISPLAY_QUIRK_DPMS_ON="true"
export QUIRKOPTS="true" ;;
--quirk-dpms-suspend)
export DISPLAY_QUIRK_DPMS_SUSPEND="true"
export QUIRKOPTS="true" ;;
--quirk-radeon-off)
export DISPLAY_QUIRK_RADEON_OFF="true"
export QUIRKOPTS="true" ;;
--quirk-s3-bios)
export DISPLAY_QUIRK_S3_BIOS="true"
export QUIRKOPTS="true" ;;
--quirk-s3-mode)
export DISPLAY_QUIRK_S3_MODE="true"
export QUIRKOPTS="true" ;;
--quirk-vbe-post)
export DISPLAY_QUIRK_VBE_POST="true"
export QUIRKOPTS="true" ;;
--quirk-vbemode-restore)
export DISPLAY_QUIRK_VBEMODE_RESTORE="true"
export QUIRKOPTS="true" ;;
--quirk-vbestate-restore)
export DISPLAY_QUIRK_VBESTATE_RESTORE="true"
export QUIRKOPTS="true" ;;
--quirk-vga-mode3)
export DISPLAY_QUIRK_VGA_MODE_3="true"
export QUIRKOPTS="true" ;;
--quirk-none)
export QUIRKOPTS="true" ;;
--quirk-old)
export FROM_HAL="true"
export AUTO_QUIRK="true"
export QUIRKOPTS="true" ;;
--from-hal)
export FROM_HAL="true" ;;
--help)
help_options
exit 0 ;;
*)
# In case of a wrong option warn the user, output the useage and abort
# the operation
echo "Unknown option: " $1
help_options
exit 1 ;;
esac
shift
done
. /usr/lib/pm-utils/functions
. /etc/sysconfig/pm-action
[ -f /sys/power/state ] || exit 1
# Enable autoquirks in case we come from HAL (or explicitly using old quirks)
# and no other quirks have been used (as HAL tells us that way that no FDI
# file for that model/vendor exists). Additionally need to "simulate"
# that we have used some quirks via QUIRKOPTS, otherwise we end up in an
# endless loop with HAL.
if [ "${FROM_HAL}" == "true" -a "${QUIRKOPTS}" == "false" ]; then
export AUTO_QUIRK="true"
export QUIRKOPTS="true"
fi
if [ "${AUTO_QUIRK}" == "true" ]; then
do_autoquirks
fi
ACTION=$(basename "$0")
ACTION=${ACTION#pm-}
ACTION=${ACTION/-/_}
[ -x /etc/init.d/messagebus ] && /etc/init.d/messagebus status > /dev/null 2>&1
if [ ! $? -eq 0 -a "${QUIRKOPTS}" == "false" ]; then
echo "Required service messagebus is not running, aborting action."
exit 1
fi
case "$ACTION" in
suspend)
if ! grep -q mem /sys/power/state ; then
echo "Error: kernel cannot suspend to ram." 1>&2
exit 1
fi
REVERSE=resume ;;
hibernate)
if ! grep -q disk /sys/power/state ; then
echo "Error: kernel cannot suspend to disk." 1>&2
exit 1
fi
REVERSE=thaw
;;
*)
exit 1
;;
esac
export PM_CMDLINE="$@"
pm_main "$ACTION" "$REVERSE"
exit $?
|