2 # Functions for redhat linux package management
4 sub list_package_system_commands
9 # list_packages([package]*)
10 # Fills the array %packages with all or listed packages
13 local($i, $list); $i = 0;
14 $list = @_ ? join(' ', map { quotemeta($_) } @_) : "-a";
16 &open_execute_command(RPM, "rpm -q $list --queryformat \"%{NAME}\\n%{VERSION}-%{RELEASE}\\n%{EPOCH}\\n%{GROUP}\\n%{SUMMARY}\\n\\n\"", 1, 1);
17 while($packages{$i,'name'} = <RPM>) {
18 chop($packages{$i,'name'});
19 chop($packages{$i,'version'} = <RPM>);
20 chop($packages{$i,'epoch'} = <RPM>);
21 $packages{$i,'epoch'} = undef if ($packages{$i,'epoch'} eq '(none)');
22 chop($packages{$i,'class'} = <RPM>);
26 $packages{$i,'desc'} .= $_;
28 if ($packages{$i,'name'} eq 'gpg-pubkey') {
29 # Bogus pseudo-package we don't want to include
30 $packages{$i,'desc'} = undef;
36 return 0 if ($?); # couldn't find the package
40 # package_info(package, [version])
41 # Returns an array of package information in the order
42 # name, class, description, arch, version, vendor, installtime
46 local $n = $_[1] ? "$_[0]-$_[1]" : $_[0];
47 &open_execute_command(RPM, "rpm -q $n --queryformat \"%{NAME}\\n%{GROUP}\\n%{ARCH}\\n%{VERSION}-%{RELEASE}\\n%{VENDOR}\\n%{INSTALLTIME}\\n\" 2>/dev/null", 1, 1);
50 local $ex = close(RPM);
51 if (!@tmp || $tmp[0] =~ /not\s+installed/) { return (); }
52 &open_execute_command(RPM, "rpm -q $n --queryformat \"%{DESCRIPTION}\"", 1, 1);
53 while(<RPM>) { $d .= $_; }
55 return ($tmp[0], $tmp[1], $d, $tmp[2], $tmp[3], $tmp[4], &make_date($tmp[5]));
59 # Check if some file is a package file
63 local $real = &translate_filename($_[0]);
65 # a directory .. see if it contains any .rpm files
67 local @list = grep { /\.rpm$/ } readdir(DIR);
71 elsif ($real =~ /\*|\?/) {
72 # a wildcard .. see what it matches
73 local @list = glob($real);
77 # just a normal file .. check if it is an RPM and not an SRPM
78 local $qm = quotemeta($_[0]);
79 $out = &backquote_command("rpm -q -p $qm 2>&1", 1);
80 if ($out =~ /does not appear|No such file|with major numbers|not an rpm/i || $?) {
83 &open_execute_command(OUT, "rpm -q -p -l $qm 2>&1", 1, 1);
85 return 0 if (/^([^\/\s]+)\.spec$/);
93 # Returns a list of all packages in the given file, in the form
94 # package-version description
97 local $real = &translate_filename($_[0]);
98 local $qm = quotemeta($_[0]);
101 &open_execute_command(RPM, "cd $qm ; rpm -q -p *.rpm --queryformat \"%{NAME} %{SUMMARY}\\n\" 2>&1", 1, 1);
104 push(@rv, $_) if (!/does not appear|query of.*failed|warning:/);
109 elsif ($_[0] =~ /\*|\?/) {
111 &open_execute_command(RPM, "rpm -q -p $_[0] --queryformat \"%{NAME} %{SUMMARY}\\n\" 2>&1", 1);
114 push(@rv, $_) if (!/does not appear|query of.*failed|warning:/);
121 $out = &backquote_command("rpm -q -p $qm --queryformat \"%{NAME} %{SUMMARY}\\n\" 2>&1", 1);
122 $out =~ s/warning:.*\n//;
128 # install_options(file, package)
129 # Outputs HTML for choosing install options for some package
132 print &yesno_input($text{'rpm_upgrade'}, "upgrade", 1, 0, 1);
133 print &yesno_input($text{'rpm_replacepkgs'}, "replacepkgs", 1, 0);
135 print &yesno_input($text{'rpm_nodeps'}, "nodeps", 1, 0);
136 print &yesno_input($text{'rpm_oldpackage'}, "oldpackage", 1, 0);
138 print &yesno_input($text{'rpm_noscripts'}, "noscripts", 0, 1);
139 print &yesno_input($text{'rpm_excludedocs'}, "excludedocs", 0, 1);
141 print &yesno_input($text{'rpm_notriggers'}, "notriggers", 0, 1);
142 print &yesno_input($text{'rpm_ignoresize'}, "ignoresize", 0, 1);
144 print &yesno_input($text{'rpm_replacefiles'}, "replacefiles", 1, 0);
145 print &ui_table_row(&hlink($text{'rpm_root'}, "root"),
146 &ui_textbox("root", "/", 50)." ".
147 &file_chooser_button("root", 1), 3);
152 return &ui_table_row(&hlink($_[0], $_[1]),
153 &ui_radio($_[1], int($_[4]),
154 [ [ $_[2], $text{'yes'} ],
155 [ $_[3], $text{'no'} ] ]));
158 # install_package(file, package, [&inputs])
159 # Install the given package from the given file, using options from %in
163 local $real = &translate_filename($file);
164 local $in = $_[2] ? $_[2] : \%in;
166 foreach $o ('oldpackage', 'replacefiles', 'replacepkgs', 'noscripts',
167 'excludedocs', 'nodeps', 'upgrade', 'notriggers', 'ignoresize') {
168 if ($in->{$o}) { $opts .= " --$o"; }
170 if ($in->{'root'} =~ /^\/.+/) {
171 if (!(-d $in{'root'})) {
172 return &text('rpm_eroot', $in->{'root'});
174 $opts .= " --root $in->{'root'}";
177 # Find the package in the directory
180 while($f = readdir(DIR)) {
181 next if ($f !~ /\.rpm$/);
182 $out = &backquote_command("rpm -q -p $file/$f --queryformat \"%{NAME}\\n\" 2>&1", 1);
183 $out =~ s/warning:.*\n//;
191 &error(&text('rpm_erpm', $_[1], $out)) if ($file eq $_[0]);
193 elsif ($file =~ /\*|\?/) {
194 # Find the package in the glob
195 # XXX won't work when translation is in effect
197 foreach $f (glob($real)) {
198 $out = &backquote_command("rpm -q -p $f --queryformat \"%{NAME}\\n\" 2>&1", 1);
199 $out =~ s/warning:.*\n//;
206 &error(&text('rpm_erpm', $_[1], $out)) if ($file eq $_[0]);
208 local $temp = &transname();
209 local $rv = &system_logged("rpm -i $opts ".quotemeta($file)." >$temp 2>&1");
210 local $out = &backquote_command("cat $temp");
211 $out =~ s/warning:.*\n//;
214 return "<pre>$out</pre>";
219 # install_packages(file, [&inputs])
220 # Installs all the packages in the given file or glob
224 local $in = $_[1] ? $_[1] : \%in;
226 foreach $o ('oldpackage', 'replacefiles', 'replacepkgs', 'noscripts',
227 'excludedocs', 'nodeps', 'upgrade', 'notriggers', 'ignoresize') {
228 if ($in->{$o}) { $opts .= " --$o"; }
230 if ($in->{'root'} =~ /^\/.+/) {
231 if (!(-d $in{'root'})) {
232 return &text('rpm_eroot', $in->{'root'});
234 $opts .= " --root $in->{'root'}";
236 if (-d &translate_filename($file)) {
237 # Install everything in a directory
238 $file = "$file/*.rpm";
241 # Install packages matching a glob (no need for any special action)
243 local $temp = &transname();
244 local $rv = &system_logged("rpm -i $opts $file >$temp 2>&1");
245 local $out = &backquote_command("cat $temp");
246 $out =~ s/warning:.*\n//;
249 return "<pre>$out</pre>";
254 # check_files(package, version)
255 # Fills in the %files array with information about the files belonging
256 # to some package. Values in %files are path type user group size error
259 local($i, $_, @w, %errs, $epath); $i = 0;
260 local $n = $_[1] ? "$_[0]-$_[1]" : $_[0];
261 local $qn = quotemeta($n);
262 &open_execute_command(RPM, "rpm -V $qn", 1, 1);
265 if ($1 eq "missing ") {
266 $errs{$3} = $text{'rpm_missing'};
270 @w = grep { $_ ne "." } split(//, $1);
272 join("\n", map { &text('rpm_checkfail', $etype{$_}) } @w);
276 &open_execute_command(RPM, "rpm -q $qn -l --dump", 1, 1);
280 $files{$i,'path'} = $w[0];
281 if ($w[10] ne "X") { $files{$i,'link'} = $w[10]; }
282 $files{$i,'type'} = $w[10] ne "X" ? 3 :
283 (-d &translate_filename($w[0])) ? 1 :
285 $files{$i,'user'} = $w[5];
286 $files{$i,'group'} = $w[6];
287 $files{$i,'size'} = $w[1];
288 $files{$i,'error'} = $w[7] ? "" : $errs{$w[0]};
295 # package_files(package, [version])
296 # Returns a list of all files in some package
299 local ($pkg, $version) = @_;
300 local $qn = quotemeta($version ? "$pkg-$version" : $pkg);
302 &open_execute_command(RPM, "rpm -q -l $qn", 1, 1);
311 # installed_file(file)
312 # Given a filename, fills %file with details of the given file and returns 1.
313 # If the file is not known to the package system, returns 0
314 # Usable values in %file are path type user group mode size packages
317 local($pkg, @w, $_, @pkgs, @vers);
319 local $qm = quotemeta($_[0]);
320 $pkg = &backquote_command("rpm -q -f $qm --queryformat \"%{NAME}\\n\" 2>&1", 1);
321 if ($pkg =~ /not owned/ || $?) { return 0; }
322 @pkgs = split(/\n/, $pkg);
323 $pkg = &backquote_command("rpm -q -f $qm --queryformat \"%{VERSION}-%{RELEASE}\\n\" 2>&1", 1);
324 @vers = split(/\n/, $pkg);
325 &open_execute_command(RPM, "rpm -q $pkgs[0] -l --dump", 1, 1);
329 if ($w[0] eq $_[0]) {
330 $file{'packages'} = join(' ', @pkgs);
331 $file{'versions'} = join(' ', @vers);
332 $file{'path'} = $w[0];
333 if ($w[10] ne "X") { $files{$i,'link'} = $w[10]; }
334 $file{'type'} = $w[10] ne "X" ? 3 :
335 (-d &translate_filename($w[0])) ? 1 :
337 $file{'user'} = $w[5];
338 $file{'group'} = $w[6];
339 $file{'mode'} = substr($w[4], -4);
340 $file{'size'} = $w[1];
348 # delete_options(package)
349 # Outputs HTML for package uninstall options
352 print "<b>$text{'delete_nodeps'}</b>\n";
353 print &ui_yesno_radio("nodeps", 0),"<br>\n";
355 print "<b>$text{'delete_noscripts'}</b>\n";
356 print &ui_yesno_radio("noscripts", 0),"<br>\n";
359 # delete_package(package, [&options], version)
360 # Attempt to remove some package
364 $opts .= $_[1]->{'nodeps'} ? "--nodeps " : "";
365 $opts .= $_[1]->{'noscripts'} ? "--noscripts " : "";
366 local $n = $_[2] ? "$_[0]-$_[2]" : $_[0];
367 local $qm = quotemeta($n);
368 local $out = &backquote_logged("rpm -e $opts $qm 2>&1");
369 if ($? || $out =~ /error:/) { return "<pre>$out</pre>"; }
373 # delete_packages(&packages, [&options], &versions)
374 # Attempt to remove multiple packages at once
378 $opts .= $_[1]->{'nodeps'} ? "--nodeps " : "";
379 $opts .= $_[1]->{'noscripts'} ? "--noscripts " : "";
380 local $cmd = "rpm -e $opts";
382 for($i=0; $i<@{$_[0]}; $i++) {
384 $cmd .= " ".quotemeta($_[0]->[$i]."-".$_[2]->[$i]);
387 $cmd .= " ".quotemeta($_[0]->[$i]);
390 local $out = &backquote_logged("$cmd 2>&1");
391 if ($? || $out =~ /error:/) { return "<pre>$out</pre>"; }
405 %etype = ( "5", $text{'rpm_md5'}, "S", $text{'rpm_fsize'},
406 "L", $text{'rpm_sym'}, "T", $text{'rpm_mtime'},
407 "D", $text{'rpm_dev'}, "U", $text{'rpm_user'},
408 "M", $text{'rpm_perm'}, "G", $text{'rpm_group'} );
410 $has_search_system = 1;
412 sub search_system_input
414 print "<input type=button onClick='window.ifield = document.forms[2].url; chooser = window.open(\"rpmfind.cgi\", \"chooser\", \"toolbar=no,menubar=no,scrollbars=yes,width=800,height=500\")' value=\"$text{'rpm_find'}\">";