#!/usr/bin/perl
# $Id: grub-del.pl,v 1.1 1999/08/30 15:08:23 duwe Exp $

$delimage = "\Q$ARGV[0]";

open (BGML, "</boot/grub/menu.lst") || die;

$elc = "";

$i = 0;

# read /boot/grub/menu.lst line by line, assembling it into "entries"
while (<BGML>) {
  m/^\s*title\s*=/ && $i++; # advance to a new entry
  $elc[$i] .= $_;
}
close BGML;

$secret = "no";

# Now write out all entries but the ones that reference the named kernel.
while (@elc) {
  if ($elc[0] !~
      m,^\s*kernel\s*=\s*/boot/vmlinuz(?:-pc97)?-$delimage-modular\s,sm) {
    print $elc[0];
    ($elc[0] =~ m,^\s*password\s*=,sim) && ($secret = "yes");
  }
  shift @elc;
}

chmod 0600, "/proc/self/fd/1" unless ($secret eq "no");
