#!/bin/sh

### BEGIN INIT INFO
# Provides:          vbesave
# Required-Start:    $local_fs $remote_fs
# Required-Stop:     $local_fs $remote_fs
# Default-Start:     2 3 4 5
# Default-Stop:      
# Short-Description: Save VESA state at boot time
# Description:       VESA state is saved at boot time so that it can be
#                    restored later to a sane state for example after a suspend.
### END INIT INFO

test -f /usr/share/acpi-support/power-funcs || exit 0

test -x /usr/sbin/vbetool || exit 0
set -e

. /lib/lsb/init-functions

test -f /etc/default/rcS && . /etc/default/rcS
test -f /etc/default/acpi-support && . /etc/default/acpi-support
test -f /usr/share/acpi-support/device-funcs && . /usr/share/acpi-support/device-funcs

case "$1" in
 start)
	if laptop-detect > /dev/null; then
		LAPTOP=true;
	fi

	if [ x$LAPTOP != xtrue ]; then
		exit 0;
	fi

        DeviceConfig
	log_begin_msg "Saving VESA state..."
	if [ "$SAVE_VBE_STATE" = "true" ]; then
	    if [ "$VERBOSE" = no ]; then 
		if ! vbetool vbestate save > $VBESTATE 2>/dev/null; then
		    log_end_msg $?
		    exit 1
		fi
	    else
		if ! vbetool vbestate save > $VBESTATE ; then
		    log_end_msg $?
		    exit 1
		fi
	    fi
	    log_end_msg 0
        fi
        ;;
 stop|restart|force-reload)
	# Doesn't make sense (and shut up lintian)
	;;
 *)
        exit 0
        ;;
esac
