Handle hostnames with upper-case letters
[webmin.git] / cluster-software / do_install_serial.cgi
1 #!/usr/local/bin/perl
2 # do_install.cgi
3 # Install some package on all hosts, in parallel. If the package was
4 # downloaded from a URL, have the hosts do the same - otherwise, transfer
5 # it to each.
6
7 require './cluster-software-lib.pl';
8 &ReadParse();
9 @packages = &foreign_call("software", "file_packages", $in{'file'});
10 foreach $p (@packages) {
11         local ($n, $d) = split(/\s+/, $p, 2);
12         push(@names, $n); push(@descs, $d);
13         }
14 -r $in{'file'} || &error($text{'do_edeleted'});
15 &ui_print_header(undef, $text{'do_title'}, "");
16 print "<b>",&text('do_header', join(" ", @names)),"</b><p>\n";
17
18 @hosts = &list_software_hosts();
19 @servers = &list_servers();
20 foreach $h (@hosts) {
21         # Check if already installed
22         local ($s) = grep { $_->{'id'} == $h->{'id'} } @servers;
23         local $d = $s->{'desc'} ? $s->{'desc'} : $s->{'host'};
24         local ($a) = grep { &indexof($_->{'name'}, @names) >= 0 }
25                           @{$h->{'packages'}};
26         #if ($a) {
27         #       print &text('do_already', $d),"<br>\n";
28         #       next;
29         #       }
30
31         &remote_foreign_require($s->{'host'}, "software", "software-lib.pl");
32         local $rfile;
33         local $need_unlink = 1;
34         if (!$s->{'id'}) {
35                 # This host, so we already have the file
36                 $rfile = $in{'file'};
37                 $need_unlink = 0;
38                 }
39         elsif ($in{'source'} == 2 && $in{'down'}) {
40                 # Ask the remote server to download the file
41                 $rfile = &remote_eval($s->{'host'}, "software", '&tempname()');
42                 if ($in{'ftpfile'}) {
43                         &remote_foreign_call($s->{'host'}, "software",
44                                 "ftp_download", $in{'host'}, $in{'ftpfile'},
45                                 $rfile);
46                         }
47                 else {
48                         &remote_foreign_call($s->{'host'}, "software",
49                                 "http_download", $in{'host'}, $in{'port'},
50                                 $in{'page'}, $rfile);
51                         }
52                 }
53         else {
54                 # Need to copy the file across :(
55                 $rfile = &remote_write($s->{'host'}, $in{'file'});
56                 }
57
58         # Do the install ..
59         for($i=0; $i<@names; $i++) {
60                 local $error = &remote_foreign_call($s->{'host'}, "software",
61                                     "install_package", $rfile, $names[$i], \%in);
62                 if ($error) {
63                         print &text('do_failed', $d, $error),"<br>\n";
64                         }
65                 else {
66                         # Success .. get the package details and add to list
67                         print &text('do_success', $d),"<br>\n";
68                         if (!$pinfo[$i]) {
69                                 $pinfo[$i] = [ &remote_foreign_call($s->{'host'}, "software",
70                                                 "package_info", $names[$i]) ];
71                                 }
72                         if (&indexof($names[$i], @{$h->{'packages'}}) < 0) {
73                                 push(@{$h->{'packages'}},
74                                      { 'name' => $names[$i],
75                                        'desc' => $descs[$i],
76                                        'class' => $pinfo[$i]->[1] });
77                                 &save_software_host($h);
78                                 }
79                         }
80                 }
81         &remote_eval($s->{'host'}, "software", "unlink('$rfile')") if ($need_unlink);
82         }
83 unlink($in{'file'}) if ($in{'need_unlink'});
84 print "<p><b>$text{'do_done'}</b><p>\n";
85
86 for($i=0; $i<@names; $i++) {
87         next if (!$pinfo[$i]);
88         print "<table border width=100%>\n";
89         print "<tr $tb> <td><b>$text{'do_details'}</b></td> </tr>\n";
90         print "<tr $cb> <td><table width=100%>\n";
91         print "<tr> <td valign=top width=20%><b>$text{'do_desc'}</b></td>\n";
92         print "<td colspan=3><font size=+1><pre>$pinfo[$i]->[2]</pre></font></td> </tr>\n";
93
94         print "<tr> <td width=20%><b>$text{'do_pack'}</b></td> <td>$pinfo[$i]->[0]</td>\n";
95         print "<td width=20%><b>$text{'do_class'}</b></td> <td>",
96                 $pinfo[$i]->[1] ? $pinfo[$i]->[1] : $text{'do_none'},"</td> </tr>\n";
97
98         print "<tr> <td width=20%><b>$text{'do_ver'}</b></td> <td>$pinfo[$i]->[4]</td>\n";
99         print "<td width=20%><b>$text{'do_vend'}</b></td> <td>$pinfo[$i]->[5]</td> </tr>\n";
100
101         print "<tr> <td width=20%><b>$text{'do_arch'}</b></td> <td>$pinfo[$i]->[3]</td>\n";
102         print "<td width=20%><b>$text{'do_inst'}</b></td> <td>$pinfo[$i]->[6]</td> </tr>\n";
103         print "</table></td></tr></table><p>\n";
104         }
105
106 &remote_finished();
107 &ui_print_footer("", $text{'index_return'});
108