summaryrefslogtreecommitdiffstats
path: root/rebootin
diff options
context:
space:
mode:
authorPascal Terjan <pterjan@mandriva.org>2010-02-11 23:12:39 +0000
committerPascal Terjan <pterjan@mandriva.org>2010-02-11 23:12:39 +0000
commitf34cf67bc094e0131c81a33eb507eace581c9a4c (patch)
treefc5014e0e85c0c832e8780eb76716b195f099d4f /rebootin
parent9b61e565bcf90aa5e3cc48a2f8aab8e01711c007 (diff)
downloadbootloader-utils-f34cf67bc094e0131c81a33eb507eace581c9a4c.tar
bootloader-utils-f34cf67bc094e0131c81a33eb507eace581c9a4c.tar.gz
bootloader-utils-f34cf67bc094e0131c81a33eb507eace581c9a4c.tar.bz2
bootloader-utils-f34cf67bc094e0131c81a33eb507eace581c9a4c.tar.xz
bootloader-utils-f34cf67bc094e0131c81a33eb507eace581c9a4c.zip
Add a menu
Diffstat (limited to 'rebootin')
-rw-r--r--rebootin26
1 files 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 <pixel@mandriva.com>,
# Chmouel Boudjnah <chmouel@mandriva.com>,
# 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 = <STDIN>;
+ 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 <label> is one of " . join(", ", @entries) . "\n" : '';
die <<'EOF' . $entries;
usage: rebootin -l
+ rebootin [-n] [-f] -m
rebootin [-n] [-f] <label>
EOF
}