Handle hostnames with upper-case letters
[webmin.git] / software / urpmi-lib.pl
1 # urpmi-lib.pl
2 # Functions for installing packages with Mandrake urpmi
3
4 sub list_update_system_commands
5 {
6 return ("urpmi");
7 }
8
9 # update_system_install([package])
10 # Install some package with urpmi
11 sub update_system_install
12 {
13 local $update = $_[0] || $in{'update'};
14 local (@rv, @newpacks);
15 local $cmd = "urpmi --force --auto --media main";
16 print "<b>",&text('urpmi_install', "<tt>$cmd $update</tt>"),"</b><p>\n";
17 print "<pre>";
18 &additional_log('exec', undef, "$cmd $update");
19 local $qm = join(" ", map { quotemeta($_) } split(/\s+/, $update));
20 &open_execute_command(CMD, "$cmd $qm </dev/null", 2);
21 while(<CMD>) {
22         s/\r|\n//g;
23         if (/installing\s+(\S+)\s+from/) {
24                 # Found a package
25                 local $pkg = $1;
26                 $pkg =~ s/\-\d.*//;     # remove version
27                 push(@rv, $pkg);
28                 }
29         print &html_escape($_."\n");
30         }
31 close(CMD);
32 print "</pre>\n";
33 if ($?) {
34         print "<b>$text{'urpmi_failed'}</b><p>\n";
35         return ( );
36         }
37 else {
38         print "<b>$text{'urpmi_ok'}</b><p>\n";
39         return &unique(@rv);
40         }
41 }
42
43 # update_system_form()
44 # Shows a form for updating all packages on the system
45 sub update_system_form
46 {
47 print &ui_subheading($text{'urpmi_form'});
48 print &ui_form_start("urpmi_upgrade.cgi");
49 print &ui_submit($text{'urpmi_update'}, "update"),"<br>\n";
50 print &ui_submit($text{'urpmi_upgrade'}, "upgrade"),"<br>\n";
51 print &ui_form_end();
52 }
53
54 # update_system_resolve(name)
55 # Converts a standard package name like apache, sendmail or squid into
56 # the name used by YUM.
57 sub update_system_resolve
58 {
59 local ($name) = @_;
60 return $name eq "apache" ? "apache2" :
61        $name eq "dhcpd" ? "dhcp-server" :
62        $name eq "mysql" ? "MySQL MySQL-client MySQL-common" :
63        $name eq "postgresql" ? "postgresql postgresql-server" :
64                            $name;
65 }
66
67 # update_system_available()
68 # Returns a list of package names and versions that are available from URPMI
69 sub update_system_available
70 {
71 local @rv;
72 local %done;
73 &open_execute_command(PKG, "urpmq -f --list", 1, 1);
74 while(<PKG>) {
75         if (/^(\S+)\-(\d[^\-]*)\-([^\.]+)\.(\S+)/) {
76                 next if ($done{$1,$2}++);
77                 push(@rv, { 'name' => $1,
78                             'version' => $2,
79                             'release' => $3,
80                             'arch' => $4 });
81                 }
82         }
83 close(PKG);
84 return @rv;
85 }
86