Index: gen_bootloader.sh =================================================================== --- gen_bootloader.sh (revision 22) +++ gen_bootloader.sh (working copy) @@ -46,10 +46,37 @@ if [ ! -e $GRUB_CONF ] then + # grub.conf doesn't exist - create it with standard defaults touch $GRUB_CONF + echo "# Generated by genkernel on `date +\"%Y%m%d %H:%M\"`" >> $GRUB_CONF + echo "#" >> $GRUB_CONF + echo "# This file is generated by genkernel to track kernel definition for the grub bootloader.">> $GRUB_CONF + echo "# Genkernel expects the following format :">> $GRUB_CONF + echo -e "#\tgeneral option 1">> $GRUB_CONF + echo -e "#\tgeneral option 2">> $GRUB_CONF + echo -e "#\t">> $GRUB_CONF + echo -e "#\ttitle=Gentoo Linux (Kernel Version)">> $GRUB_CONF + echo -e "#\t\troot (hd0,0)">> $GRUB_CONF + echo -e "#\t\tkernel /kernel-Kernel.Version kernel_options">> $GRUB_CONF + echo -e "#\t\tinitrd /initrd-Kernel.Version">> $GRUB_CONF + echo -e "#\t">> $GRUB_CONF + echo -e "#\ttitle=Gentoo Linux (Kernel Version)">> $GRUB_CONF + echo -e "#\t\troot (hd0,0)">> $GRUB_CONF + echo -e "#\t\tkernel /kernel-Kernel.Version kernel_options">> $GRUB_CONF + echo -e "#\t\tinitrd /initrd-Kernel.Version">> $GRUB_CONF + echo -e "#\t">> $GRUB_CONF + echo "#">> $GRUB_CONF + echo "# A blank line is used to separate the \"general option\" section from the first kernel entry.">> $GRUB_CONF + echo "# and between each kernel entry">> $GRUB_CONF + echo "#">> $GRUB_CONF + echo "# The first kernel entry is used as a template when adding a new kernel entry.">> $GRUB_CONF + echo "# So add specific kernel parameters to the first entry and they will be kept">> $GRUB_CONF + echo "# during kernel upgrades.">> $GRUB_CONF + echo "#">> $GRUB_CONF echo 'default 0' >> $GRUB_CONF echo 'timeout 5' >> $GRUB_CONF + echo "" >> $GRUB_CONF # Add grub configuration to grub.conf echo "title=Gentoo Linux ($KV)" >> $GRUB_CONF @@ -61,16 +88,20 @@ echo -e "\tkernel /kernel-$KV root=/dev/ram0 init=/linuxrc real_root=$GRUB_ROOTFS" >> $GRUB_CONF echo -e "\tinitrd /initrd-$KV" >> $GRUB_CONF fi + echo "" >> $GRUB_CONF else # grub.conf already exists; so... - # * Copy the first boot definition and change the version. + # ... Clone the first boot definition and change the version. cp $GRUB_CONF $GRUB_CONF.bak - awk 'BEGIN { RS="title=";FS="\n";OFS="\n";ORS=""} - NR == 2 { - sub(/\(.+\)/,"(" ch KV ch ")",$1); + awk 'BEGIN { RS="" ; FS="\n" ; OFS="\n" ; ORS="\n\n" } + NR == 1 { $1="# Generated by genkernel -- " strftime( "%Y%m%d %H:%M", systime() ); print $0; } + NR == 2 { + ORIG=$0; + sub(/\(.+\)/,"(" KV ")",$1); sub(/kernel-[[:alnum:][:punct:]]+/, "kernel-" KV, $3); sub(/initrd-[[:alnum:][:punct:]]+/, "initrd-" KV, $4); - print RS ch $0 }' \ - KV=$KV $GRUB_CONF.bak >> $GRUB_CONF + print RS $0; + print RS ORIG;} + NR > 2 { print RS $0; }' KV=$KV $GRUB_CONF.bak > $GRUB_CONF fi }