#!/bin/bash
# This script checks the suspend2 configuration...
#
# (C)opy-left to Trevio - http://italy.copybase.ch/blog/
# Released under FSF GPL license v2.0
#

# Check kernel suspend2 support
susp2enabled="true"
if [ -z "$(cat /proc/cmdline | grep "resume2=")" ]; then 
	echo -e "\nWarning: your kernel hasn't been loaded properly to use suspend2 hibernation!";
	if ( [ ! -z "$(cat /boot/grub/menu.lst | grep "^# kopt=" | grep "resume2=")" ] || [ ! -z "$(cat /boot/grub/menu.lst | grep "^# defoptions=" | grep "resume2=")" ] ); then
		update-grub >/dev/null 2>&1 #2&>/dev/null
		echo -e "  Anyway, looking your grub configuration, it should work properly at next reboot.";
	elif [ ! -z "$(cat /boot/grub/menu.lst | grep "^kernel.*/" --max-count=1 | grep "resume2=")" ]; then
		  echo -e "Anyway, checking your grub configuration, it should work properly at next reboot.\n  However it seems that you've configured only your first kernel in list; please, use the 'kopt' or 'defoptions' variables in your '/boot/grub/menu.lst' not to lose your configuration on next 'update-grub'"
	else
		echo -e "You should add a 'resume2=' option to to your kernel loading options (editing your /boot/grub/menu.lst)\nI.E.: 'resume2=swap:/dev/Swap-Partition' (where Swap-Partition is your swap partiton device i.e.: /dev/hda1); for other resume2 options, see Suspend2 docs"
		susp2enabled="false"
	fi
fi
