From f34cf67bc094e0131c81a33eb507eace581c9a4c Mon Sep 17 00:00:00 2001 From: Pascal Terjan Date: Thu, 11 Feb 2010 23:12:39 +0000 Subject: Add a menu --- rebootin | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/rebootin b/rebootin index ae9a9fd..25d34fa 100644 --- a/rebootin +++ b/rebootin @@ -1,6 +1,6 @@ #!/usr/bin/perl #-------------------------------------------------------------------- -# Copyright (C) 2000, 2001, 2002 by Mandriva, +# Copyright (C) 2000-2010 by Mandriva, # Pixel , # Chmouel Boudjnah , # Redistribution of this file is permitted under the terms of the GNU @@ -16,7 +16,7 @@ use strict; my $lilo_conf = "/etc/lilo.conf"; my $grub_menu = "/boot/grub/menu.lst"; -my ($fastboot, $noreboot, $list); +my ($fastboot, $noreboot, $list, $menu); while ($ARGV[0] =~ /^-/) { local $_ = shift; @@ -26,12 +26,16 @@ while ($ARGV[0] =~ /^-/) { $list++; } elsif (/^-n/) { $noreboot++; + } elsif (/^-m/) { + $menu++; } else { die "Unknown switch $_\n"; } } -$list || @ARGV == 1 && $ARGV[0] or usage(); +$menu || $list || @ARGV == 1 && $ARGV[0] or usage(); +!$menu || @ARGV == 0 or usage(); + my ($wanted_entry) = @ARGV; my $bootloader = `/usr/sbin/detectloader -q` or die "Can't detect your bootloader\n";chomp $bootloader; @@ -50,11 +54,25 @@ exec "reboot" unless $noreboot; sub list_entries { print "$_\n" foreach @entries; exit(0) } +sub select_entry { + my $i = 1; + print $i++.") $_\n" foreach @entries; + print "0) exit\n"; + my $userinput; + do { + print "> "; + $userinput = ; + chomp $userinput; + } while ($userinput ge $i); + exit(1) unless $userinput; + $entries[$userinput-1]; +} sub lilo_conf { open(my $F, $lilo_conf) or die "lilo is not installed ($lilo_conf is missing)\n"; @entries = map { /="?([^"\n]+)/ } grep { /\s*label=\S*/ } <$F>; list_entries() if $list; + $wanted_entry = select_entry() if $menu; @entries > 0 or die "Bad lilo.conf (no entry found)\n"; grep { $_ eq $wanted_entry } @entries or usage(); write_fast_boot() if $fastboot; @@ -72,6 +90,7 @@ sub grub_conf { } } list_entries() if $list; + $wanted_entry = select_entry() if $menu; @entries > 0 or die "bad menu.lst (no entry found)\n"; for (my $i = 0; $i < @entries; $i++) { @@ -95,6 +114,7 @@ sub usage { my $entries = @entries ? " where