Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- # grub2lilo.pl Make grub look like lilo for kdm.
- # Coplyleft 2003 Gerald Teschl <gt@esi.ac.at>
- use strict;
- my $GRUB="/sbin/grub";
- my $GRUBCONF="/boot/grub/grub.conf";
- my $Default= 0;
- my $Title;
- my $q= 0;
- my $R= 0;
- foreach my $arg (@ARGV) {
- if ($arg eq "-R") {
- $R= 1;
- } elsif ($arg eq "-q") {
- $q= 1;
- last;
- } elsif ($R) {
- $Title= $arg;
- last;
- }
- }
- exit 0 unless ($q or $R);
- open (CONF, "<$GRUBCONF") or die ("Failed to open: $GRUBCONF: $!");
- print "Images:\n" if ($q);
- my $i= -1;
- foreach my $line (<CONF>) {
- next if ($line =~ /^#/);
- if ($line =~ /default\s*=\s*(\d+)\s*$/) {
- $Default= $1;
- } elsif ($line =~ /title\s+(\S.*)$/) {
- my $title= $1;
- $i++;
- if ($title =~ /^(.*\S)\s+$/) {
- $title= $1;
- }
- if ($q) { # print the title
- print " $title";
- print " *" if ($i == $Default);
- print "\n";
- } elsif ($title eq $Title) { # change default for next boot
- open(PROC, "|$GRUB --batch &> /dev/null") or die ("Failed to execute: $GRUB: $!");
- print PROC "savedefault --default=$i --once\n";
- close(PROC) or exit 1;
- exit 0;
- }
- }
- }
- exit 0;
Add Comment
Please, Sign In to add comment