#!/bin/bash

# change to console 1
FGCONSOLE=`fgconsole`
chvt 8

# vbetool vbestate save > /tmp/vbe_state # Doesn't seem to make a difference

# safe video state - needed for R50e or it goes horribly wrong
cat /proc/bus/pci/00/02.0 > /tmp/video_state

# sync filesystem
sync

# sync hardware clock with system time
hwclock --systohc

echo -n "mem" > /sys/power/state


hwclock --hctosys
cat /tmp/video_state > /proc/bus/pci/00/02.0
# vbetool vbestate restore < /tmp/vbe_state # Disabled from above
vbetool post


if [ "$FGCONSOLE" -ge "7" ] ; then
	chvt $FGCONSOLE
else
	chvt 7
	chvt $FGCONSOLE
fi

# clean up behind us
rm /tmp/video_state
