Handle hostnames with upper-case letters
[webmin.git] / grub / install.cgi
1 #!/usr/local/bin/perl
2 # install.cgi
3 # Install the GRUB boot loader
4
5 require './grub-lib.pl';
6 &error_setup($text{'install_err'});
7 &ReadParse();
8
9 # Find out which partition the menu file is on
10 @st = stat($config{'menu_file'});
11 &foreign_require("mount", "mount-lib.pl");
12 foreach $d (sort { length($a->[0]) <=> length($b->[0]) }
13                  &mount::list_mounted()) {
14         @fst = stat($d->[0]);
15         $mount = $d->[0] if ($fst[0] == $st[0]);
16         }
17 $mount =~ s/\/$//;
18 $menu_file = $config{'menu_file'};
19 $menu_file =~ s/^\Q$mount\E//;
20
21 # Ask grub where the menu.lst file is
22 $temp = &transname();
23 open(TEMP, ">$temp");
24 print TEMP "find $menu_file\n";
25 close(TEMP);
26 open(GRUB, "$config{'grub_path'} --batch <$temp |");
27 while(<GRUB>) {
28         if (/find\s+(\S+)/ && $1 eq $menu_file) {
29                 $out .= $_;
30                 $_ = <GRUB>;
31                 if (/^\s*(\(\S+\))/) {
32                         $root = $1;
33                         }
34                 }
35         $out .= $_;
36         }
37 close(GRUB);
38 unlink($temp);
39 if (!$root || $?) {
40         # Didn't find it!
41         &error($text{'install_efind'},"<pre>",$out,"</pre>");
42         }
43
44 # Setup on the chosen device
45 &ui_print_header(undef, $text{'install_title'}, "");
46 print &text('install_desc', $in{'dev'}, "<tt>root $root</tt>",
47             "<tt>setup $config{'install'}</tt>"),"<p>\n";
48 print "<pre>";
49 open(TEMP, ">$temp");
50 print TEMP "root $root\n";
51 print TEMP "setup $config{'install'}\n";
52 close(TEMP);
53 open(GRUB, "$config{'grub_path'} --batch <$temp |");
54 while(<GRUB>) {
55         if (/\d+\s+sectors\s+are\s+embedded/i) {
56                 $embedded++;
57                 }
58         elsif (/error/) {
59                 $error++;
60                 }
61         print &html_escape($_);
62         }
63 close(GRUB);
64 print "</pre>\n";
65 if (!$embedded || $? || $error) {
66         print "$text{'install_failed'}<p>\n";
67         }
68 else {
69         print "$text{'install_ok'}<p>\n";
70         }
71
72 &webmin_log("install");
73 &ui_print_footer("", $text{'index_return'});
74