updated on Thu Jan 26 16:09:46 UTC 2012
[aur-mirror.git] / acpi-eeepc-generic / acpi-eeepc-generic-suspend2ram.sh
blob002ab040bc063f2fa6f94f2396a3863c81df5b97
1 #!/bin/sh
2 # Copyright 2009 Nicolas Bigaouette
3 # This file is part of acpi-eeepc-generic.
4 # http://code.google.com/p/acpi-eeepc-generic/
6 # acpi-eeepc-generic is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # acpi-eeepc-generic is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with acpi-eeepc-generic. If not, see <http://www.gnu.org/licenses/>.
19 . /etc/acpi/eeepc/acpi-eeepc-generic-functions.sh
21 # Make sure we run as root
22 if [[ $EUID -ne 0 ]]; then
23 me="`dirname $0`/`basename $0`"
24 ${SUDO} "${me}"
25 exit 1
28 logger "#############################################"
29 logger "acpi-eeepc-generic-suspend2ram.sh:"
31 if [ -e "${EEEPC_VAR}/power.lock" ]; then
32 msg="Suspend lock exist, canceling suspend"
33 logger "$msg (${EEEPC_VAR}/power.lock)"
34 eeepc_notify "$msg" stop 5000
35 exit 0
38 vga_is_on=`xrandr | grep -A 1 VGA | grep "*"`
39 if [ "x$vga_is_on" != "x" ]; then
40 msg="VGA is up and running, canceling suspend"
41 logger $msg
42 eeepc_notify "$msg" stop 5000
43 exit 0
46 if grep -q mem /sys/power/state ; then
48 # BEGIN SUSPEND SEQUENCE
50 logger "Start suspend sequence"
52 if [[ "$SUSPEND_QUIRKS_VTSWITCH" == "yes" ]]; then
53 # Get console number
54 CONSOLE_NUMBER=$(fgconsole)
55 logger "Saving console number: $CONSOLE_NUMBER"
57 # Turn off external monitor
58 var_xrandr="$EEEPC_VAR/xrandr.log"
59 xrandr > $var_xrandr
60 name_lvds=$(grep -i connected $var_xrandr | grep -i lvds | awk '{print ""$1""}')
61 if [ "x`grep " connected " $var_xrandr | awk '{print ""$1""}' | grep -i VGA`" != "x" ]; then
62 name_vga=$(grep -i connected $var_xrandr | grep -i vga | awk '{print ""$1""}')
63 xrandr --output ${name_lvds} --preferred --output ${name_vga} --off
66 # Change virtual terminal to not screw up X
67 chvt 1
70 # Save logs
71 /etc/rc.d/logsbackup stop
73 # Flush disk buffers
74 sync
76 # Suspend
77 execute_commands "${SUSPEND2RAM_COMMANDS[@]}"
79 logger "BEGIN WAKEUP SEQUENCE..."
81 # Restore screen
82 #/usr/sbin/vbetool post
84 if [[ "$SUSPEND_QUIRKS_VTSWITCH" == "yes" ]]; then
85 # Get back to screen
86 chvt $CONSOLE_NUMBER
89 # Restore brightness
90 restore_brightness
94 exit 0