Guest User

Untitled

a guest
Oct 17th, 2017
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 1.52 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # grub2lilo.pl Make grub look like lilo for kdm.
  3. # Coplyleft 2003 Gerald Teschl <gt@esi.ac.at>
  4.  
  5. use strict;
  6.  
  7. my $GRUB="/sbin/grub";
  8. my $GRUBCONF="/boot/grub/grub.conf";
  9. my $Default= 0;
  10. my $Title;
  11. my $q= 0;
  12. my $R= 0;
  13.  
  14. foreach my $arg (@ARGV) {
  15.         if ($arg eq "-R") {
  16.                 $R= 1;
  17.         } elsif ($arg eq "-q") {
  18.                 $q= 1;
  19.                 last;
  20.         } elsif ($R) {
  21.                 $Title= $arg;
  22.                 last;
  23.         }
  24. }
  25. exit 0 unless ($q or $R);
  26.  
  27. open (CONF, "<$GRUBCONF") or die ("Failed to open: $GRUBCONF: $!");
  28.  
  29. print "Images:\n" if ($q);
  30.  
  31. my $i= -1;
  32. foreach my $line (<CONF>) {
  33.         next if ($line =~ /^#/);
  34.         if ($line =~ /default\s*=\s*(\d+)\s*$/) {
  35.                 $Default= $1;
  36.         } elsif ($line =~ /title\s+(\S.*)$/) {
  37.                 my $title= $1;
  38.                 $i++;
  39.                 if ($title =~ /^(.*\S)\s+$/) {
  40.                         $title= $1;
  41.                 }
  42.                 if ($q) { # print the title
  43.                         print "  $title";
  44.                         print " *" if ($i == $Default);
  45.                         print "\n";
  46.                 } elsif ($title eq $Title) { # change default for next boot
  47.                         open(PROC, "|$GRUB --batch &> /dev/null") or die ("Failed to execute: $GRUB: $!");
  48.                         print PROC "savedefault --default=$i --once\n";
  49.                         close(PROC) or exit 1;
  50.                         exit 0;
  51.                 }
  52.         }
  53. }
  54.  
  55. exit 0;
Add Comment
Please, Sign In to add comment