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 120
|
# -*- sh -*-
# vim:ft=sh:ts=8:sw=4:noet
# Vbetool scriptlet requires Matt J Garrett's vbetool package to be useful.
# http://www.srcf.ucam.org/~mjg59/vbetool/
#
# This scriptlet Copyright (C) Cameron Patrick, 2005, and may be
# used under the same terms as hibernate-script itself.
AddConfigHandler VbetoolOptions
AddConfigHelp "EnableVbetool <boolean>" "Save and restore video state using vbetool before and after suspending."
AddConfigHelp "RestoreVbeStateFrom <filename>" "If set, will restore the VBE state with the data stored in <filename>. Use this if your card requires you to restore it with a state captured at boot (from single user mode, run \"vbetool vbestate save > /var/lib/vbetool/vbestate\"). If this option is not set, the state is saved just before suspending."
AddConfigHelp "VbetoolPost <boolean>" "If yes, will call the video BIOS's POST routine to reinitialise the video card. Some cards need this to turn on the backlight back and be useful after resuming. Other video cards will hang if you attempt to POST them. Try it with yours and see."
AddConfigHelp "RestoreVCSAData <boolean>" "If yes, will call save and restore some of the video card's state from /dev/vcsa. This helps certain drivers such as ATI's fglrx driver to resume properly."
# hopefully this is a good choice and nothing else uses it :-/
VBETOOL_VT=61
VBETOOL_ENABLED=
VBETOOL_POST=
VBETOOL_SAVED_STATE=
VBETOOL_SAVEVCSADATA=
VbetoolSaveState() {
# Saving /dev/vcsa data is really independent of VBETool itself.
if [ x"$VBETOOL_SAVEVCSADATA" = "x1" ] ; then
if [ -r "/dev/vcsa" ] ; then
VBETOOL_VCSADATAFILE=`mktemp /tmp/tmp.hibernate-vcsa.XXXXXX`
cat < /dev/vcsa > $VBETOOL_VCSADATAFILE
else
VBETOOL_VCSADATAFILE=
vecho 1 "'/dev/vcsa' not found or not readable. Not saving."
fi
fi
# if we're switched off, don't do nuffin
[ x"$VBETOOL_ENABLED" = "x1" ] || return 0
# Make sure we have a vbetool.
if ! command -v vbetool > /dev/null 2>&1 ; then
VBETOOL_ENABLED=0
vecho 1 "'vbetool' utility not found. Vbetool disabled."
return 0
fi
# If we already have a saved state, don't bother saving it now.
[ -n "$VBETOOL_SAVED_STATE" ] && return 0
# save our previous VT and switch to a new one
VBETOOL_ORIG_VT=`fgconsole 2>/dev/null` || VBETOOL_ORIG_VT=1
chvt $VBETOOL_VT
TERM=linux tput clear
VBETOOL_FILE=`mktemp /tmp/tmp.hibernate.XXXXXX`
# save the vbe state
(vbetool vbestate save 2>&1 >&3 | vcat 2 >&2) 3> $VBETOOL_FILE || return 1
return 0
}
VbetoolRestoreState() {
# Restoring /dev/vcsa data is really independent of VBETool itself.
if [ x"$VBETOOL_SAVEVCSADATA" = "x1" ] && [ -r "$VBETOOL_VCSADATAFILE" ] ; then
cat < $VBETOOL_VCSADATAFILE > /dev/vcsa
rm -f $VBETOOL_VCSADATAFILE
fi
# if we're switched off, don't do nuffin
[ x"$VBETOOL_ENABLED" = "x1" ] || return 0
# POST if we're asked to
[ x"$VBETOOL_POST" = "x1" ] && (vbetool post 2>&1 >&3 | vcat 2 >&2) 3>&1
# Restore a saved state.
if [ -n "$VBETOOL_SAVED_STATE" ] ; then
(vbetool vbestate restore < $VBETOOL_SAVED_STATE 2>&1 >&3 | vcat 2 >&2) 3>&1
elif [ -n "$VBETOOL_FILE" ] ; then
(vbetool vbestate restore < $VBETOOL_FILE 2>&1 >&3 | vcat 2 >&2) 3>&1
rm -f $VBETOOL_FILE
fi
# see if we can power on the display too
(vbetool dpms on 2>&1 >&3 | vcat 2 >&2) 3>&1
# change back to our original VT
chvt $VBETOOL_ORIG_VT
}
VbetoolOptions() {
case $1 in
enablevbetool)
BoolIsOn "$1" "$2" && VBETOOL_ENABLED=1 || return 0
;;
vbetoolpost)
BoolIsOn "$1" "$2" && VBETOOL_POST=1 || return 0
;;
restorevbestatefrom)
VBETOOL_SAVED_STATE=$2
if ! [ -r "$VBETOOL_SAVED_STATE" ] ; then
vecho 0 "$EXE: vbetool: Saved state file does not exist ($VBETOOL_SAVED_STATE)"
vecho 0 "$EXE: vbetool: Saving state on suspend instead."
VBETOOL_SAVED_STATE=
return 0
fi
;;
restorevcsadata)
BoolIsOn "$1" "$2" && VBETOOL_SAVEVCSADATA=1 || return 0
;;
*)
return 1
esac
if [ -z "$VBETOOL_HOOKED" ] ; then
AddSuspendHook 97 VbetoolSaveState
AddResumeHook 97 VbetoolRestoreState
VBETOOL_HOOKED=1
fi
return 0
}
# $Id: vbetool 1067 2006-10-04 12:13:03Z madduck $
|