#!/bin/bash
#
# Copyright (C) 2005  Josef Kufner <jk@myserver.cz>
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#

menu="/boot/grub/menu.lst"
resumever=`uname -r`
root="(hd0,0)"
append="root=/dev/hda1 ro ide0=dma ide1=dma resume2=swap:/dev/hda2"


cat >$menu <<EOF
default=0
timeout=1

splashimage=(hd0,0)/boot/grub/splashimages/01.xpm
foreground ffffff
background 333663

title Software Suspend 2: Resume $resumever
	root (hd0,0)
	kernel /boot/$resumever/vmlinuz-$resumever $append

#-----------------------------------------------------------------------------
# generated items:

EOF

ls -rv1 /boot | grep -e '^[0-9]*\.[0-9]*\.[0-9]*' | while read kernel
do
	if [ -d "/boot/$kernel" ]
	then
		note=""
		[ -r "/boot/$kernel/note" ] && note="  `head -n 1 /boot/$kernel/note`"
		echo "title $kernel$note" >>$menu
		echo "	root $root" >>$menu
		echo "	kernel /boot/$kernel/vmlinuz-$kernel $append" >>$menu
		echo "" >>$menu
	fi
done

cat >>$menu <<EOF
#-----------------------------------------------------------------------------

title Last Build (swsusp2)
	root (hd0,0)
	kernel /vmlinuz root=/dev/hda1 ro ide0=dma ide1=dma resume2=swap:/dev/hda2

EOF

