#!/usr/bin/perl my $menu = "/boot/grub/menu.lst"; my $once = "/boot/grub/menu.once"; open F, $menu or die "grub is not installed ($menu is missing)\n"; my @entries = map { /\s(\S.*)/ } grep { /^title\s/ } my @l = <F>; grep { m|^altconfigfile\s.*grub/menu\.once| } @l or die "rebootin is of no use without altconfigfile\n"; @entries > 0 or die "bad menu.lst (no entry found)\n"; @ARGV == 1 or usage(); for (my $i = 0; $i < @entries; $i++) { $ARGV[0] eq $entries[$i] and set($i); } print STDERR "$ARGV[0] not found\n"; usage(); # not found sub set { open F, ">$once" or die "can't write rebootin file ($once), verify the rights\n"; print F "default $_[0]\ntimeout 0\n"; exec "reboot"; } sub usage { die "usage: rebootin <label>\n where <label> is one of " . join(", ", @entries) . "\n"; }