summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrancois Pons <fpons@mandriva.com>2001-01-25 16:16:04 +0000
committerFrancois Pons <fpons@mandriva.com>2001-01-25 16:16:04 +0000
commit8a7854e2c4e3838d3760440334803993ce149dd5 (patch)
tree8e90fd11116cb70d0648cef5af7c33a5687d4735
parentf2ffe35cc38bbc06c4b22752659f6ba2fc241f21 (diff)
downloadurpmi-8a7854e2c4e3838d3760440334803993ce149dd5.tar
urpmi-8a7854e2c4e3838d3760440334803993ce149dd5.tar.gz
urpmi-8a7854e2c4e3838d3760440334803993ce149dd5.tar.bz2
urpmi-8a7854e2c4e3838d3760440334803993ce149dd5.tar.xz
urpmi-8a7854e2c4e3838d3760440334803993ce149dd5.zip
*** empty log message ***
-rw-r--r--urpm.pm159
-rwxr-xr-xurpmi65
-rw-r--r--urpmi.spec11
3 files changed, 126 insertions, 109 deletions
diff --git a/urpm.pm b/urpm.pm
index cef92dee..afe08022 100644
--- a/urpm.pm
+++ b/urpm.pm
@@ -107,18 +107,15 @@ sub read_config {
/^\s*}$/ and last;
/^\s*$/ or $urpm->{error}("syntax error at line $. in $urpm->{config}");
}
- $urpm->probe_medium($medium);
- push @{$urpm->{media}}, $medium;
+ $urpm->probe_medium($medium) and push @{$urpm->{media}}, $medium;
next; };
/^\s*(.*?[^\\])\s+(.*?[^\\])\s+with\s+(.*)$/ and do { #- urpmi.cfg old format for ftp
my $medium = { name => unquotespace($1), clear_url => unquotespace($2), with_hdlist => unquotespace($3) };
- $urpm->probe_medium($medium);
- push @{$urpm->{media}}, $medium;
+ $urpm->probe_medium($medium) and push @{$urpm->{media}}, $medium;
next; };
/^\s*(.*?[^\\])\s+(?:(.*?[^\\])\s*)?$/ and do { #- urpmi.cfg old format (assume hdlist.<name>.cz2?)
my $medium = { name => unquotespace($1), clear_url => unquotespace($2) };
- $urpm->probe_medium($medium);
- push @{$urpm->{media}}, $medium;
+ $urpm->probe_medium($medium) and push @{$urpm->{media}}, $medium;
next; };
/^\s*$/ or $urpm->{error}("syntax error at line $. in [$urpm->{config}]");
}
@@ -130,10 +127,10 @@ sub read_config {
foreach (@{$urpm->{media}}) {
exists $hdlists{$_->{hdlist}} and
$_->{ignore} = 1, $urpm->{error}("medium \"$_->{name}\" try to use an already used hdlist, medium ignored");
- $_->{ignore} or $hdlists{$_->{hdlist}} = undef;
+ $hdlists{$_->{hdlist}} = undef;
exists $lists{$_->{list}} and
$_->{ignore} = 1, $urpm->{error}("medium \"$_->{name}\" try to use an already used list, medium ignored");
- $_->{ignore} or $lists{$_->{list}} = undef;
+ $lists{$_->{list}} = undef;
}
#- urpmi.cfg if old is not enough to known the various media, track
@@ -151,14 +148,12 @@ sub read_config {
} else {
my $medium;
foreach (@{$urpm->{media}}) {
- $_->{ignore} and next;
$_->{name} eq $2 and $medium = $_, last;
}
$medium and $urpm->{error}("unable to use name \"$2\" for unamed medium because it is already used"), next;
$medium = { name => $2, hdlist => "hdlist.$1", list => "list.$2" };
- $urpm->probe_medium($medium);
- push @{$urpm->{media}}, $medium;
+ $urpm->probe_medium($medium) and push @{$urpm->{media}}, $medium;
}
} else {
$urpm->{error}("unable to take medium \"$2\" into account as no list file [$urpm->{statedir}/list.$2] exists");
@@ -184,6 +179,12 @@ sub read_config {
sub probe_medium {
my ($urpm, $medium) = @_;
+ my $existing_medium;
+ foreach (@{$urpm->{media}}) {
+ $_->{name} eq $medium->{name} and $existing_medium = $_, last;
+ }
+ $existing_medium and $urpm->{error}("trying to bypass existing medium \"$medium->{name}\", avoiding"), return;
+
unless ($medium->{ignore} || $medium->{hdlist}) {
$medium->{hdlist} = "hdlist.$medium->{name}.cz";
-e "$urpm->{statedir}/$medium->{hdlist}" or $medium->{hdlist} = "hdlist.$medium->{name}.cz2";
@@ -197,7 +198,7 @@ sub probe_medium {
}
#- there is a little more to do at this point as url is not known, inspect directly list file for it.
- unless ($medium->{ignore} || $medium->{url} || $medium->{clear_url}) {
+ unless ($medium->{url} || $medium->{clear_url}) {
my %probe;
local (*F, $_);
open F, "$urpm->{statedir}/$medium->{list}";
@@ -208,15 +209,18 @@ sub probe_medium {
foreach (sort { length($a) <=> length($b) } keys %probe) {
if ($medium->{url}) {
$medium->{url} eq substr($_, 0, length($medium->{url})) or
- $medium->{ignore} = 1, $urpm->{error}("incoherent list file for \"$medium->{name}\", medium ignored"), last;
+ $medium->{ignore} || $urpm->{error}("incoherent list file for \"$medium->{name}\", medium ignored"),
+ $medium->{ignore} = 1, last;
} else {
$medium->{url} = $_;
}
}
$medium->{url} or
- $medium->{ignore} = 1, $urpm->{error}("unable to inspect list file for \"$medium->{name}\", medium ignored");
+ $medium->{ignore} || $urpm->{error}("unable to inspect list file for \"$medium->{name}\", medium ignored"),
+ $medium->{ignore} = 1, last;
}
$medium->{url} ||= $medium->{clear_url};
+ $medium;
}
#- write back urpmi.cfg code to allow modification of medium listed.
@@ -253,7 +257,6 @@ sub add_medium {
#- we have to exit now
my ($medium);
foreach (@{$urpm->{media}}) {
- $_->{ignore} and next;
$_->{name} eq $2 and $medium = $_;
}
$medium and $urpm->{error}("medium \"$medium\" already exists"), return;
@@ -630,6 +633,7 @@ sub try_mounting {
}
}
}
+ -e $dir;
}
#- read depslist file using rpmtools, this file is not managed directly by urpm.
@@ -722,9 +726,9 @@ sub search_packages {
} else {
my $l = $found{$_} || $foundi{$_};
if (@{$l || []} == 0) {
- $urpm->{error}(_("no package named %s\n", $_)); $result = 0;
+ $urpm->{error}(sprintf("no package named %s\n", $_)); $result = 0;
} elsif (@$l > 1 && !$options{all}) {
- $urpm->{error}(_("The following packages contain %s: %s\n", $_, join(' ', map { $_->{name} } @$l))); $result = 0;
+ $urpm->{error}(sprintf("The following packages contain %s: %s\n", $_, join(' ', map { $_->{name} } @$l))); $result = 0;
} else {
foreach (@$l) {
$packages->{$_->{id}} = undef;
@@ -893,7 +897,7 @@ sub get_source_packages {
#- check version, release and id selected.
#- TODO arch is not checked at this point.
- $pkg->{version} cmp $2 && $pkg->{release} cmp $3 or next;
+ $pkg->{version} eq $2 && $pkg->{release} eq $3 or next;
exists $packages->{$pkg->{id}} or next;
#- make sure only the first matching is taken...
@@ -902,6 +906,7 @@ sub get_source_packages {
#- we have found one source for id.
push @local_sources, "$urpm->{cachedir}/rpms/$1-$2-$3.$4.rpm";
} else {
+ -d "$urpm->{cachedir}/rpms/$_" and next;
$error = 1;
$urpm->{error}("unable to determine rpms cache directory $urpm->{cachedir}/rpms");
}
@@ -920,7 +925,7 @@ sub get_source_packages {
#- check version, release and id selected.
#- TODO arch is not checked at this point.
- $pkg->{version} cmp $3 && $pkg->{release} cmp $4 or next;
+ $pkg->{version} eq $3 && $pkg->{release} eq $4 or next;
exists $packages->{$pkg->{id}} or next;
#- make sure only the first matching is taken...
@@ -949,9 +954,9 @@ sub get_source_packages {
#- try to find which one.
my $pkg = $urpm->{params}{depslist}[$_];
if ($pkg) {
- $urpm->{error}("internal error for selecting unknown package for id=$_");
- } else {
$urpm->{error}("package $pkg->{name}-$pkg->{version}-$pkg->{release} is not found");
+ } else {
+ $urpm->{error}("internal error for selecting unknown package for id=$_");
}
}
@@ -963,60 +968,110 @@ sub get_source_packages {
#- change location to find the right package in the local
#- filesystem for only one transaction.
#- try to mount/eject removable media here.
-#- return a hash saying if a package has been uploaded or is local.
-sub upload_packages_for_install {
- my ($urpm, $local_sources, $list) = @_;
+#- return a list of package ready for rpm.
+sub upload_source_packages {
+ my ($urpm, $local_sources, $list, $force_local, $ask_for_medium) = @_;
+ my (@sources, @distant_sources, %media, %removables);
#- make sure everything is correct on input...
@{$urpm->{media}} == @$list or return;
#- removable media have to be examined to keep mounted the one that has
#- more package than other (size is better ?).
- my %removables;
+ my $examine_removable_medium = sub {
+ my ($id, $device, $copy) = @_;
+ my $medium = $urpm->{media}[$id];
+ $media{$id} = undef;
+ if (my ($prefix, $dir) = $medium->{url} =~ /^(removable_[^:]*|file):\/(.*)/) {
+ until (-e $dir) {
+ #- the directory given does not exist or may be accessible
+ #- by mounting some other. try to figure out these directory and
+ #- mount everything necessary.
+ unless ($urpm->try_mounting($dir)) {
+ system("eject", $device); #- umount too... TODO
+ $ask_for_medium->($medium->{name}) or last;
+ }
+ }
+ if (-e $dir) {
+ my @removable_sources;
+ foreach (@{$list->[$id]}) {
+ /^(removable_[^:]*|file):\/(.*\/([^\/]*))/ or next;
+ -r $2 or $urpm->{error}("unable to read rpm file [$2] from medium \"$medium->{name}\"");
+ if ($copy) {
+ push @removable_sources, $2;
+ push @sources, "$urpm->{cachedir}/rpms/$3";
+ } else {
+ push @sources, $2;
+ }
+ }
+ if (@removable_sources) {
+ system("cp", "-a", @removable_sources, "$urpm->{cachedir}/rpms");
+ }
+ } else {
+ $urpm->{error}("medium \"$medium->{name}\" is not selected");
+ }
+ } else {
+ #- we have a removable device that is not removable, well...
+ $urpm->{error}("incoherent medium \"$medium->{name}\" marked removable but not really");
+ }
+ };
foreach (0..$#$list) {
- @{$list->[$_]} || $urpm->{media}[$_]{removable} or next;
+ @{$list->[$_]} && $urpm->{media}[$_]{removable} or next;
push @{$removables{$urpm->{media}[$_]{removable}} ||= []}, $_;
}
- foreach (keys %removables) {
+ foreach my $device (keys %removables) {
#- here we have only removable device.
#- if more than one media use this device, we have to sort
#- needed package to copy first the needed rpms files.
- if (@{$removables{$_}} > 1) {
- my @sorted_media = sort { @{$list->[$a]} <=> @{$list->[$b]} } @{$removables{$_}};
+ if (@{$removables{$device}} > 1) {
+ my @sorted_media = sort { @{$list->[$a]} <=> @{$list->[$b]} } @{$removables{$device}};
#- mount all except the biggest one.
foreach (@sorted_media[0 .. $#sorted_media-1]) {
- my $medium = $urpm->{media}[$_];
- if (my ($prefix, $dir) = $medium->{url} =~ /^(removable_.*?|file):\/(.*)/) {
- #- the directory given does not exist or may be accessible
- #- by mounting some other. try to figure out these directory and
- #- mount everything necessary.
- $urpm->try_mounting($dir);
-
- #- TODO to cut... and ask if correct to the user
- system("cp", "-a", map { /^(removable_.*?|file):\/(.*)/ && $1 } @{$list->[$_]}, "$urpm->{cachedir}/rpms");
- } else {
- #- we have a removable device that is not removable, well...
- $urpm->{error}("incoherent medium \"$medium->{name}\" marked removable but not really");
- }
+ $examine_removable_medium->($_, $device, 'copy');
}
#- now mount the last one...
- $removables{$_} = [ $sorted_media[-1] ];
+ $removables{$device} = [ $sorted_media[-1] ];
}
#- mount the removable device, only one or the important one.
- my $i = $removables{$_}[0];
- if (my ($prefix, $dir) = $urpm->{media}[$i]{url} =~ /^(removable_.*?|file):\/(.*)/) {
- $urpm->try_mounting($dir);
- system("cp", "-a", map { /^(removable_.*?|file):\/(.*)/ && $1 } @{$list->[$i]}, "$urpm->{cachedir}/rpms");
- } else {
- #- we have a removable device that is not removable, well...
- $urpm->{error}("incoherent medium \"$urpm->{media}[$i]{name}\" marked removable but not really");
+ $examine_removable_medium->($removables{$device}[0], $device);
+ }
+
+ #- get back all ftp and http accessible rpms file into the local cache
+ #- if necessary (as used by checksig or any other reasons).
+ #- we are using wget for that with an input from its stdin.
+ foreach (0..$#$list) {
+ exists $media{$_} and next;
+ @{$list->[$_]} or next;
+ foreach (@{$list->[$_]}) {
+ if (/^(removable_[^:]*|file):\/(.*)/) {
+ push @sources, $2;
+ } elsif (/^([^:]*):\/(.*\/([^\/]*))/) {
+ if ($force_local) {
+ push @distant_sources, $_;
+ push @sources, "$urpm->{cachedir}/rpms/$3";
+ } else {
+ push @sources, $_;
+ }
+ } else {
+ $urpm->{error}("malformed input: [$_]");
+ }
+ }
+ }
+ if (@distant_sources) {
+ local *F;
+ open F, "| wget -NP $urpm->{cachedir}/rpms -i -";
+ foreach (@distant_sources) {
+ print F "$_\n";
}
+ close F or $urpm->{error}("cannot get distant rpms files (maybe wget is missing?)");
}
- #- get back all ftp and http accessible rpms file into the local cache.
- #- TODO
+ #- need verification of available files... TODO
+
+ #- return the list of rpm file that have to be installed, they are all local now.
+ @sources;
}
diff --git a/urpmi b/urpmi
index 90c60c3b..fb06e9fa 100755
--- a/urpmi
+++ b/urpmi
@@ -161,68 +161,21 @@ if (!$auto) {
}
}
-my $to_install = join '|', map { quotemeta($_) } @to_install;
-my %long;
-my %name;
-my %removables;
-
-foreach my $list (rpmlistfiles($datadir)) {
- open F, "$datadir/$list" or die("urpmi: error opening $list\n");
- $list =~ s/list\.//;
- foreach (<F>) { chop; m|/($to_install)| and $long{$1} = untaint($_), $name{$1} = untaint($list) }
- close F;
-}
+$urpm->read_config();
-foreach (@files) {
- m|/($to_install)| and $long{$1} = $_
+my ($local_sources, $list) = $urpm->get_source_packages(\%packages);
+unless ($local_sources || $list) {
+ die("unable to get source packages, aborting");
+ exit 1;
}
-my %try2mount;
-my @to_install_long;
-
-foreach my $l (@to_install) {
- local $_ = $long{$l} or die("urpmi: package $l is not available\n");
- if (s|removable_(\w+)_(\d*):/||) {
- my $n = "$2-$name{$l}";
- $removables{$n}->{name} = $name{$l};
- $removables{$n}->{device} = $1;
- push @{$removables{$n}->{list}}, $_;
- } else {
- if (s|^file:/||) {
- if (m|^(/mnt/.*?)/|) {
- -e $_ || $try2mount{$1} or $try2mount{$1} = 1, `mount $1 2>/dev/null`;
- }
- }
- push @to_install_long, $_;
- }
-}
+my @sources = $urpm->upload_source_packages($local_sources, $list, sub {
+ die "not implemented yet... change medium";
+ });
my $something_was_installed;
-install(@to_install_long) unless $removables{0} || $removables{1};
-
-foreach (sort keys %removables) {
- my $f = @{$removables{$_}->{list}}[0];
- my $dev = $removables{$_}->{device};
- `mount /dev/$dev 2>/dev/null`;
- unless (-e $f) {
- `umount /dev/$dev 2>/dev/null ; eject $dev 2>/dev/null`;
- message(_("Please insert the %s named %s", $removables{$_}->{device}, $removables{$_}->{name}));
- unless ($X) {
- print SAVEOUT _("Press enter when it's done...");
- <STDIN>;
- }
- `mount /dev/$dev 2>/dev/null`;
- unless (-e $f) {
- message(_("Sorry can't find file %s, exiting", $f));
- exit 1;
- }
- }
- install(@{$removables{$_}->{list}});
-}
-
-install(@to_install_long) if $removables{0} || $removables{1};
-
+install(@sources);
$something_was_installed or message_auto(_("everything already installed"));
diff --git a/urpmi.spec b/urpmi.spec
index 393332ae..08d05394 100644
--- a/urpmi.spec
+++ b/urpmi.spec
@@ -45,6 +45,10 @@ Auto install of rpm on demand
rm -rf $RPM_BUILD_ROOT
make PREFIX=$RPM_BUILD_ROOT MANDIR=$RPM_BUILD_ROOT%{_mandir} install
install -d $RPM_BUILD_ROOT/var/lib/urpmi/autoirpm.scripts
+for dir in partial headers rpms
+do
+ install -d $RPM_BUILD_ROOT/var/cache/urpmi/$dir
+done
install -m 644 autoirpm.deny $RPM_BUILD_ROOT/etc/urpmi
mkdir -p $RPM_BUILD_ROOT%{perl_sitearch}
install -m 644 urpm.pm $RPM_BUILD_ROOT%{perl_sitearch}
@@ -81,6 +85,10 @@ autoirpm.uninstall
%defattr(-,root,root)
%attr(0755, root, urpmi) %dir /etc/urpmi
%attr(0755, root, urpmi) %dir /var/lib/urpmi
+%attr(0755, root, urpmi) %dir /var/cache/urpmi
+%attr(0755, root, urpmi) %dir /var/cache/urpmi/partial
+%attr(0755, root, urpmi) %dir /var/cache/urpmi/headers
+%attr(0755, root, urpmi) %dir /var/cache/urpmi/rpms
%attr(4750, root, urpmi) %{_bindir}/urpmi
%{_bindir}/urpmi_rpm-find-leaves
%{_bindir}/urpmf
@@ -105,9 +113,10 @@ autoirpm.uninstall
%changelog
-* Tue Jan 23 2001 François Pons <fpons@ackbar.mandrakesoft.com> 1.4-3mdk
+* Thu Jan 25 2001 François Pons <fpons@mandrakesoft.com> 1.4-3mdk
- need rpmtools-2.1-9mdk or above for hdlist building extension.
- introduced cache directory for medium and rpms manipulation.
+- added code to search for source rpms file to install.
* Wed Jan 17 2001 François Pons <fpons@mandrakesoft.com> 1.4-2mdk
- removed PreReq on genbasefiles, now PreReq rpmtools-2.1-8mdk or above.