2 # Functions for installing packages with yum
4 $yum_config = $config{'yum_config'} || "/etc/yum.conf";
6 sub list_update_system_commands
11 # update_system_install([package], [&in])
12 # Install some package with yum
13 sub update_system_install
15 local $update = $_[0] || $in{'update'};
18 if ($in->{'enablerepo'}) {
19 $enable = "enablerepo=".quotemeta($in->{'enablerepo'});
21 local (@rv, @newpacks);
22 print "<b>",&text('yum_install', "<tt>yum $enable -y install $update</tt>"),"</b><p>\n";
24 &additional_log('exec', undef, "yum $enable -y install $update");
25 local $qm = join(" ", map { quotemeta($_) } split(/\s+/, $update));
26 &open_execute_command(CMD, "yum $enable -y install $qm </dev/null", 2);
29 if (/^\[(update|install|deps):\s+(\S+)\s+/) {
32 elsif (/^(Installed|Dependency Installed|Updated|Dependency Updated):\s*(.*)/) {
35 # wbt-virtual-server-theme.x86
36 local @pkgs = split(/\s+/, $2);
38 # Wrapped to next line
42 @pkgs = split(/\s+/, $_);
44 foreach my $p (@pkgs) {
45 if ($p !~ /:/ && $p =~ /^(\S+)\.(\S+)$/) {
47 if ($p =~ /[^0-9\.\-\_i]/) {
53 elsif (/^\s+Updating\s+:\s+(\S+)/) {
55 # Updating : wbt-virtual-server-theme 1/2
58 if (!/ETA/ && !/\%\s+done\s+\d+\/\d+\s*$/) {
59 print &html_escape($_."\n");
65 print "<b>$text{'yum_failed'}</b><p>\n";
69 print "<b>$text{'yum_ok'}</b><p>\n";
74 # update_system_operations(packages)
75 # Given a list of packages, returns a list containing packages that will
76 # actually get installed, each of which is a hash ref with name and version.
77 sub update_system_operations
80 my $temp = &transname();
81 &open_tempfile(SHELL, ">$temp", 0, 1);
82 &print_tempfile(SHELL, "install $packages\n");
83 &print_tempfile(SHELL, "transaction solve\n");
84 &close_tempfile(SHELL);
86 open(SHELL, "yum shell $temp |");
88 if (/Package\s+(\S+)\s+(\S+)\s+set/i) {
89 my $pkg = { 'name' => $1,
91 if ($pkg->{'name'} =~ s/\.([^\.]+)$//) {
94 if ($pkg->{'version'} =~ s/^(\S+)://) {
105 # show_update_system_opts()
106 # Returns HTML for enabling a repository, if any are disabled
107 sub show_update_system_opts
109 local @pinfo = &package_info("yum");
110 if (&compare_versions($pinfo[4], "2.1.10") > 0) {
111 local $conf = &get_yum_config();
113 foreach my $r (@$conf) {
114 if ($r->{'values'}->{'enabled'} eq '0') {
115 push(@ena, $r->{'name'});
119 return $text{'yum_enable'}." ".
120 &ui_select("enablerepo", "",
121 [ [ "", $text{'yum_none'} ],
122 map { [ $_ ] } @ena ]);
128 # update_system_form()
129 # Shows a form for updating all packages on the system
130 sub update_system_form
132 print &ui_subheading($text{'yum_form'});
133 print &ui_form_start("yum_upgrade.cgi");
134 print &ui_form_end([ [ undef, $text{'yum_apply'} ] ]);
137 # update_system_resolve(name)
138 # Converts a standard package name like apache, sendmail or squid into
139 # the name used by YUM.
140 sub update_system_resolve
143 return $name eq "apache" ? "httpd" :
144 $name eq "dhcpd" ? "dhcp" :
145 $name eq "mysql" ? "mysql mysql-server mysql-devel" :
146 $name eq "openssh" ? "openssh openssh-server" :
147 $name eq "postgresql" ? "postgresql postgresql-libs postgresql-server" :
148 $name eq "openldap" ? "openldap-servers openldap-clients" :
152 # update_system_available()
153 # Returns a list of package names and versions that are available from YUM
154 sub update_system_available
158 &open_execute_command(PKG, "yum info", 1, 1);
161 if (/^Name\s*:\s*(\S+)/) {
163 # Seen before .. update with newer info. This can happen
164 # when YUM shows the installed version first.
166 delete($pkg->{'epoch'});
167 delete($pkg->{'version'});
170 # Start of a new package
171 $pkg = { 'name' => $1 };
172 $done{$pkg->{'name'}} = $pkg;
176 elsif (/^Arch\s*:\s*(\S+)/) {
179 elsif (/^Version\s*:\s*(\S+)/) {
180 $pkg->{'version'} = $1;
181 if ($pkg->{'version'} =~ s/^(\S+)://) {
182 $pkg->{'epoch'} = $1;
185 elsif (/^Release\s*:\s*(\S+)/) {
186 $pkg->{'version'} .= "-".$1;
188 elsif (/^Repo\s*:\s*(\S+)/) {
189 $pkg->{'source'} = $1;
191 elsif (/^Summary\s*:\s*(\S.*)/) {
194 elsif (/^Epoch\s*:\s*(\S.*)/) {
195 $pkg->{'epoch'} = $1;
199 &set_yum_security_field(\%done);
203 # set_yum_security_field(&package-hash)
204 # Set security field on packages which are security updates
205 sub set_yum_security_field
208 &open_execute_command(PKG, "yum list-sec 2>/dev/null", 1, 1);
211 if (/^\S+\s+security\s+(\S+?)\-([0-9]\S+)\.([^\.]+)$/) {
212 local ($name, $ver) = ($1, $2);
213 if ($done->{$name}) {
214 $done->{$name}->{'source'} = 'security';
215 $done->{$name}->{'security'} = 1;
222 # update_system_updates()
223 # Returns a list of package updates available from yum
224 sub update_system_updates
228 &open_execute_command(PKG, "yum check-update 2>/dev/null", 1, 1);
231 if (/^(\S+)\.([^\.]+)\s+(\S+)\s+(\S+)/) {
232 local $pkg = { 'name' => $1,
236 if ($pkg->{'version'} =~ s/^(\S+)://) {
237 $pkg->{'epoch'} = $1;
239 $done{$pkg->{'name'}} = $pkg;
244 &set_yum_security_field(\%done);
249 # Returns entries from the YUM config file, as a list of hash references
254 open(CONF, $yum_config);
258 if (/^\s*\[(.*)\]/) {
260 $sect = { 'name' => $1,
264 elsif (/^\s*(\S+)\s*=\s*(.*)/ && $sect) {
266 $sect->{'values'}->{lc($1)} = $2;