#!/usr/bin/perl #- Copyright (C) 2000 MandrakeSoft (fpons@mandrakesoft.com) #- #- This program is free software; you can redistribute it and/or modify #- it under the terms of the GNU General Public License as published by #- the Free Software Foundation; either version 2, or (at your option) #- any later version. #- #- This program is distributed in the hope that it will be useful, #- but WITHOUT ANY WARRANTY; without even the implied warranty of #- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #- GNU General Public License for more details. #- #- You should have received a copy of the GNU General Public License #- along with this program; if not, write to the Free Software #- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #- this program is based upon urpmi. #use strict qw(subs vars refs); use urpm; # get I18N translation method. import urpm _; #- default options. my $query = {}; my @files; my @names; sub usage { print STDERR _("urpmq version %s Copyright (C) 2000, 2001 MandrakeSoft. This is free software and may be redistributed under the terms of the GNU GPL. usage: -h - print this help message. -v - verbose mode. -d - extend query to package dependencies. -u - remove package if a better version is already installed. -m - extend query to package dependencies, remove already installed package that provide what is necessary, add packages that may be block the upgrade. -M - extend query to package dependencies and remove already installed package only if they are newer or the same. -c - choose complete method for resolving requires closure. -p - allow search in provides to find package. -g - print groups too with name. -r - print version and release too with name. --update - use only update media. --auto-select - automatically select packages for upgrading the system. --headers - extract headers for package listed from urpmi db to stdout (root only). --sources - give all source packages before downloading (root only). --force - force invocation even if some package do not exist. names or rpm files given on command line are queried. ", $urpm::VERSION); exit(0); } #- parse arguments list. my @nextargv; for (@ARGV) { /^--help$/ and do { usage; next }; /^--update$/ and do { $query->{update} = 1; next }; /^--auto-select$/ and do { $query->{auto_select} = 1; next }; /^--headers$/ and do { $query->{headers} = 1; next }; /^--sources$/ and do { $query->{sources} = 1; next }; /^--force$/ and do { $query->{force} = 1; next }; /^-(.*)$/ and do { foreach (split //, $1) { /[\?h]/ and do { usage; next }; /d/ and do { $query->{deps} = 1; next }; /u/ and do { $query->{upgrade} = 1; next }; /m/ and do { $query->{minimal} = 1; next }; /M/ and do { $query->{minimal} = 0; next }; /c/ and do { $query->{complete} = 1; next }; /g/ and do { $query->{group} = 1; next }; /p/ and do { $query->{use_provides} = 1; next }; /v/ and do { $query->{verbose} = 1; next }; /r/ and do { $query->{version} = $query->{release} = 1; next }; print STDERR _("urpmq: unknown option \"-%s\", check usage with --help\n", $1); exit(1) } next }; @nextargv and do { my $r = shift @nextargv; $r and $$r = $_; next }; /\.rpm$/ and do { if (-r $_) { push @files, $_; } else { print STDERR _("urpmq: cannot read rpm file \"%s\"\n", $_); } next }; push @names, $_; } #- params contains informations to parse installed system. my $urpm = new urpm; #- remove verbose if not asked. $query->{verbose} or $urpm->{log} = sub {}; $urpm->read_depslist; $query->{group} and $urpm->read_compss; $query->{use_provides} and $urpm->read_provides; if (@files) { #- read provides file which is needed only to compute incremental #- dependencies, of files provided. $query->{use_provides} or $urpm->read_provides; #- build closure with local package and return list of names. push @names, $urpm->register_local_packages($query->{minimal}, @files); } #- reparse whole internal depslist to match against newer packages only. if ($query->{update}) { $urpm->read_config(nocheck_access => 1); $urpm->filter_active_media(use_update => 1); } $urpm->relocate_depslist_provides(use_active => $query->{update}); #- search the packages according the selection given by the user, #- basesystem is added to the list so if it need to be upgraded, all its dependency #- will be updated too. my %packages; $urpm->search_packages(\%packages, [ @names ], use_provides => $query->{use_provides}, use_active => $query->{update}) or $query->{force} or exit 1; #- auto select package for upgrading the distribution. if ($query->{auto_select}) { my (%to_remove, %keep_files); $urpm->select_packages_to_upgrade('', \%packages, \%to_remove, \%keep_files); if (keys(%to_remove) > 0) { $urpm->{error}(_("some package have to be removed for being upgraded, this is not supported yet\n")); } } #- filter to add in packages selected required packages. if ($query->{minimal}) { $query->{use_provides} || @files or $urpm->read_provides; $query->{update} or $urpm->read_config(nocheck_access => 1); $urpm->filter_minimal_packages_to_upgrade(\%packages, undef); } else { $query->{deps} && !$query->{upgrade} and $urpm->compute_closure(\%packages); $query->{upgrade} and $urpm->filter_packages_to_upgrade(\%packages, undef, complete => $query->{complete}); } #- get out of package that should not be upgraded. $urpm->deselect_unwanted_packages(\%packages); if ($query->{headers} || $query->{sources}) { $urpm->read_config(); my ($local_sources, $list) = $urpm->get_source_packages(\%packages); unless ($local_sources || $list) { $urpm->{fatal}(1, _("unable to get source packages, aborting")); } if ($query->{headers}) { #- now examine source package to build headers list to extract. @$local_sources and system 'rpm2header', @$local_sources; foreach (0..$#{$urpm->{media} || []}) { my @headers = (grep { my $file = "$urpm->{cachedir}/headers/$_"; -s $file and system 'cat', $file; ! -s $file } map { /(.*)\/([^\/]*)-([^-]*)-([^-]*)\.([^\.]*)\.rpm/ and "$2-$3-$4.$5" } @{$list->[$_]}); @headers > 0 or next; require packdrake; my $packer = new packdrake("$urpm->{statedir}/$urpm->{media}[$_]{hdlist}"); $packer->extract_archive(undef, @headers); } } else { print join "\n", @$local_sources; @$local_sources and print "\n"; foreach (0..$#{$urpm->{media} || []}) { print join "\n", @{$list->[$_]}; @{$list->[$_]} and print "\n"; } } exit 0; } #- print sub for query. my $query_sub = sub { my ($id) = @_; my $info = $urpm->{params}{depslist}[$id]; my $str = ''; $query->{group} and $str .= $info->{group} . '/'; $str .= $info->{name}; $query->{version} and $str .= '-' . $info->{version}; $query->{release} and $str .= '-' . $info->{release}; $str; }; my %hack_only_one; foreach my $id (keys %packages) { my $class = $packages{$id}; if (ref $class) { foreach my $choices (@{$class || []}) { exists $hack_only_one{$choices} and next; print join('|', map { $query_sub->($_) } @$choices), "\n"; $hack_only_one{$choices} = undef; } } else { exists $packages{$id} and print $query_sub->($id), "\n"; } }