summaryrefslogtreecommitdiff
path: root/src/pm-action
blob: 7c2643b0959c4110e0fd0accbbf4f8e51a203497 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
#
# Simple suspend script
#
# Copyright 2006 Red Hat, Inc.
#
# Based on work from:
#    Bill Nottingham <notting@redhat.com>
#    Peter Jones <pjones@redhat.com>
#    David Zeuthen <davidz@redhat.com>
#    Richard Hughes <richard@hughsie.com>
#
# 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 "$(basename "$0") [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-reset-brightness"
	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

# Get the command line options
while [ $# -gt 0 ]
do
	case "$1" in
		--quirk-dpms-on)
			export DISPLAY_QUIRK_DPMS_ON="true" ;;
		--quirk-dpms-suspend)
			export DISPLAY_QUIRK_DPMS_SUSPEND="true" ;;
		--quirk-radeon-off)
			export DISPLAY_QUIRK_RADEON_OFF="true" ;;
		--quirk-reset-brightness)
			export DISPLAY_QUIRK_RESET_BRIGHTNESS="true" ;;
		--quirk-s3-bios)
			export DISPLAY_QUIRK_S3_BIOS="true" ;;
		--quirk-s3-mode)
			export DISPLAY_QUIRK_S3_MODE="true" ;;
		--quirk-vbe-post)
			export DISPLAY_QUIRK_VBE_POST="true" ;;
		--quirk-vbemode-restore)
			export DISPLAY_QUIRK_VBEMODE_RESTORE="true" ;;
		--quirk-vbestate-restore)
			export DISPLAY_QUIRK_VBESTATE_RESTORE="true" ;;
		--quirk-vga-mode3)
			export DISPLAY_QUIRK_VGA_MODE_3="true" ;;
		--help)
			help_options
			exit 0 ;;
		*)
			break ;; # terminate while loop
	esac
	shift
done

. /usr/lib/pm-utils/functions

[ -f /sys/power/state ] || exit 1


ACTION=$(basename "$0")
ACTION=${ACTION#pm-}
ACTION=${ACTION/-/_}

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 $?