]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/patches/SuSE10.2/grubonce
Hinzugefuegt:
[people/pmueller/ipfire-2.x.git] / src / patches / SuSE10.2 / grubonce
CommitLineData
73276c91
HS
1#!/usr/bin/perl
2
3# Keep this sort of configurable for the future.
4$GRUBDIR="/boot/grub";
5
6# Parse the menu file, and see if we can get a match for a maybe given arg.
7open(MENU, "<$GRUBDIR/menu.lst") || die "no menu.lst in $GRUBDIR";
8$gotit = 0;
9$titleno = -1;
10$global_default = undef;
11while(<MENU>) {
12 m,\s*default\s+(.+), && $titleno == -1 && ($global_default = $1);
13 next unless m,\s*title\s+(.*),i;
14 $title_name = $1;
15 $titleno++;
16
17 if (@ARGV > 0) {
18 # Argument may be entirely numerical, in which case it is an index,
19 # or a perl RE that leads to the first title matching.
20 if (( $ARGV[0] =~ m,[0-9]+, && $titleno eq $ARGV[0] ) ||
21 ( $ARGV[0] !~ m,[0-9]+, && $title_name =~ m,$ARGV[0],i) ) {
22 $gotit = 1;
23 last;
24 }
25 } else {
26 print "$titleno: $title_name\n";
27 }
28}
29close(MENU);
30
31print "Warning: you haven't set a global default!\n" if !defined($global_default);
32
33# Without a command line argument, we have now listet the titles and are done.
34exit 0 if @ARGV < 1;
35
36# Else the user wants to write the default file. We have better found a match!
37if ($gotit > 0) {
38 print "Warning: your global default is 'saved'; changing default permanently!"
39 if $global_default eq "saved";
40
41 print "Using entry #$titleno: $title_name\n";
42
43 # set the magic one-time flag
44 $titleno |= 0x4000;
45
46 open(DEFFILE, ">$GRUBDIR/default") ||
47 die "Cannot open default file for writing";
48 $buf = $titleno . "\0" . "\n" x 9;
49 syswrite(DEFFILE, $buf, 10);
50 close(DEFFILE);
51
52 exit 0;
53} else {
54 print $ARGV[0] . " not found in $GRUBDIR/menu.lst\n";
55 exit 1;
56}
57