From 41e32b3391326cf338195e5863121ff36fcd6a81 Mon Sep 17 00:00:00 2001 From: Francois Pons Date: Tue, 27 Nov 2001 18:45:37 +0000 Subject: curl support --- urpm.pm | 67 ++++++++++++++++++++++++++++++++++++++++------------------ urpmi | 8 +++++++ urpmi.addmedia | 41 +++++++++++++++++++++++++---------- urpmi.spec | 9 +++++++- urpmi.update | 15 ++++++++----- 5 files changed, 103 insertions(+), 37 deletions(-) diff --git a/urpm.pm b/urpm.pm index e53ef849..66eacbc1 100644 --- a/urpm.pm +++ b/urpm.pm @@ -78,6 +78,8 @@ sub new { media => undef, params => new rpmtools, + sync => \&sync_curl, #- first argument is directory, others are url to fetch. + fatal => sub { printf STDERR "%s\n", $_[1]; exit($_[0]) }, error => sub { printf STDERR "%s\n", $_[0] }, log => sub { printf STDERR "%s\n", $_[0] }, @@ -88,6 +90,19 @@ sub new { sub quotespace { local $_ = $_[0]; s/(\s)/\\$1/g; $_ } sub unquotespace { local $_ = $_[0]; s/\\(\s)/$1/g; $_ } +#- syncing algorithms, currently is implemented wget and curl methods. +sub sync_wget { + -x "/usr/bin/wget" or die _("wget is missing\n"); + system "/usr/bin/wget", "-NP", @_; + $? == 0 or die _("wget failed\n"); +} +sub sync_curl { + -x "/usr/bin/curl" or die _("curl is missing\n"); + chdir shift @_; + system "/usr/bin/curl", "-R", map { ("-O", $_ ) } @_; + $? == 0 or die _("curl failed\n"); +} + #- read /etc/urpmi/urpmi.cfg as config file, keep compability with older #- configuration file by examining if one entry is of the form #- { @@ -306,9 +321,9 @@ sub add_medium { #- we have to exit now my ($medium); foreach (@{$urpm->{media}}) { - $_->{name} eq $2 and $medium = $_; + $_->{name} eq $name and $medium = $_; } - $medium and $urpm->{fatal}(5, _("medium \"%s\" already exists", $medium)); + $medium and $urpm->{fatal}(5, _("medium \"%s\" already exists", $medium->{name})); #- creating the medium info. $medium = { name => $name, @@ -514,10 +529,21 @@ sub update_media { #- try to get the description if it has been found. unlink "$urpm->{cachedir}/partial/descriptions"; - rename "$urpm->{statedir}/descriptions.$medium->{name}", "$urpm->{cachedir}/partial/descriptions"; - system("wget", "-NP", "$urpm->{cachedir}/partial", "$medium->{url}/../descriptions"); - -e "$urpm->{cachedir}/partial/descriptions" and - rename "$urpm->{cachedir}/partial/descriptions", "$urpm->{statedir}/descriptions.$medium->{name}"; + if (-e "$urpm->{statedir}/descriptions.$medium->{name}") { + rename("$urpm->{statedir}/descriptions.$medium->{name}", + "$urpm->{cachedir}/partial/descriptions") or + system("mv", + "$urpm->{statedir}/descriptions.$medium->{name}", + "$urpm->{cachedir}/partial/descriptions"); + } + eval { $urpm->{sync}("$urpm->{cachedir}/partial", "$medium->{url}/../descriptions") }; + if (-e "$urpm->{cachedir}/partial/descriptions") { + rename("$urpm->{cachedir}/partial/descriptions", + "$urpm->{statedir}/descriptions.$medium->{name}") or + system("mv", + "$urpm->{cachedir}/partial/descriptions", + "$urpm->{statedir}/descriptions.$medium->{name}"); + } #- try to sync (copy if needed) local copy after restored the previous one. unlink "$urpm->{cachedir}/partial/$basename"; @@ -528,11 +554,9 @@ sub update_media { $options{force} >= 2 || ! -e "$urpm->{statedir}/$medium->{hdlist}" or system("cp", "-a", "$urpm->{statedir}/$medium->{hdlist}", "$urpm->{cachedir}/partial/$basename"); } - system("wget", "-NP", "$urpm->{cachedir}/partial", "$medium->{url}/$medium->{with_hdlist}"); - $? == 0 or $error = 1, $urpm->{error}(_("wget of [%s] failed (maybe wget is missing?)", - "/$medium->{with_hdlist}")); + eval { $urpm->{sync}("$urpm->{cachedir}/partial", "$medium->{url}/$medium->{with_hdlist}") }; -s "$urpm->{cachedir}/partial/$basename" or - $error = 1, $urpm->{error}(_("wget of [%s] failed", "/$medium->{with_hdlist}")); + $error = 1, $urpm->{error}(_("retrieve of [%s] failed", "/$medium->{with_hdlist}")); unless ($error) { my @sstat = stat "$urpm->{cachedir}/partial/$basename"; my @lstat = stat "$urpm->{statedir}/$medium->{hdlist}"; @@ -544,7 +568,11 @@ sub update_media { } #- the file are different, update local copy. - rename "$urpm->{cachedir}/partial/$basename", "$urpm->{cachedir}/partial/$medium->{hdlist}"; + rename("$urpm->{cachedir}/partial/$basename", + "$urpm->{cachedir}/partial/$medium->{hdlist}") or + system("mv", + "$urpm->{cachedir}/partial/$basename", + "$urpm->{cachedir}/partial/$medium->{hdlist}"); } } @@ -621,9 +649,13 @@ sub update_media { unlink "$urpm->{statedir}/$medium->{hdlist}"; $medium->{synthesis} and unlink "$urpm->{statedir}/synthesis.$medium->{hdlist}"; unlink "$urpm->{statedir}/$medium->{list}"; - rename "$urpm->{cachedir}/partial/$medium->{hdlist}", $medium->{synthesis} ? - "$urpm->{statedir}/synthesis.$medium->{hdlist}" : "$urpm->{statedir}/$medium->{hdlist}"; - rename "$urpm->{cachedir}/partial/$medium->{list}", "$urpm->{statedir}/$medium->{list}"; + rename("$urpm->{cachedir}/partial/$medium->{hdlist}", $medium->{synthesis} ? + "$urpm->{statedir}/synthesis.$medium->{hdlist}" : "$urpm->{statedir}/$medium->{hdlist}") or + system("mv", "$urpm->{cachedir}/partial/$medium->{hdlist}", $medium->{synthesis} ? + "$urpm->{statedir}/synthesis.$medium->{hdlist}" : + "$urpm->{statedir}/$medium->{hdlist}"); + rename("$urpm->{cachedir}/partial/$medium->{list}", "$urpm->{statedir}/$medium->{list}") or + system("mv", "$urpm->{cachedir}/partial/$medium->{list}", "$urpm->{statedir}/$medium->{list}"); #- and create synthesis file associated. $medium->{synthesis} or $urpm->build_synthesis_hdlist($medium); @@ -1619,7 +1651,6 @@ sub upload_source_packages { #- 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; values %{$list->[$_]} or next; @@ -1638,11 +1669,7 @@ sub upload_source_packages { } } } - foreach (@distant_sources) { - $urpm->{log}(_("retrieving [%s]", $_)); - system "wget", "-NP", "$urpm->{cachedir}/rpms", $_; - $? == 0 or $urpm->{error}(_("wget of [%s] failed", "/$_")); - } + eval { $urpm->{sync}("$urpm->{cachedir}/rpms", @distant_sources) }; #- return the hash of rpm file that have to be installed, they are all local now. %$local_sources, %sources; diff --git a/urpmi b/urpmi index 733135e1..199c0c8d 100755 --- a/urpmi +++ b/urpmi @@ -28,6 +28,7 @@ my $auto = 0; my $allow_medium_change = 0; my $auto_select = 0; my $force = 0; +my $sync = undef; my $X = 0; my $WID = 0; my $all = 0; @@ -54,6 +55,8 @@ usage: ") . _(" --auto - automatically select a good package in choices. ") . _(" --auto-select - automatically select packages for upgrading the system. ") . _(" --force - force invocation even if some package do not exist. +") . _(" --wget - use wget to retrieve distant files. +") . _(" --curl - use curl to retrieve distant files. ") . _(" --X - use X interface. ") . _(" --best-output - choose best interface according to the environment: X or text mode. @@ -75,6 +78,8 @@ for (@ARGV) { /^--allow-medium-change$/ and do { $allow_medium_change = 1; next }; /^--auto-select$/ and do { $auto_select = 1; next }; /^--force$/ and do { $force = 1; next }; + /^--wget$/ and do { $sync = \&urpm::sync_wget; next }; + /^--curl$/ and do { $sync = \&urpm::sync_curl; next }; /^--X$/ and do { $X = 1; next }; /^--WID=(.*)$/ and do { $WID = $1; next }; /^--WID$/ and do { push @nextargv, \$WID; next }; @@ -134,6 +139,9 @@ select STDOUT; $| = 1; # make unbuffered #- params contains informations to parse installed system. my $urpm = new urpm; +#- use specific sync routine. +$sync and $urpm->{sync} = $sync; + #- remove verbose if not asked. $verbose or $urpm->{log} = sub {}; diff --git a/urpmi.addmedia b/urpmi.addmedia index c08e5214..fa807050 100755 --- a/urpmi.addmedia +++ b/urpmi.addmedia @@ -25,32 +25,51 @@ use urpm; import urpm _; sub main { - my ($name, $url, $with, $relative_hdlist) = @_; - $name =~ /^--?update/ and (my $update, $name, $url, $with, $relative_hdlist) = @_; - my $usage = _("usage: urpmi.addmedia [--update] + my ($name, $url, $with, $relative_hdlist, %options); + my $usage = _("usage: urpmi.addmedia [options] [with ] where is one of file:// ftp://:@/ with ftp:/// with http:/// with - removable_:// + removable:// + +and [options] are from +") . _(" -c - clean headers cache directory. +") . _(" -f - force generation of hdlist files. +") . _(" --wget - use wget to retrieve distant files. +") . _(" --curl - use curl to retrieve distant files. "); + + $options{force} = 0; + $options{noclean} = 1; + $options{sync} = undef; + while ($_ = shift @_) { + /^--?c/ and $options{noclean} = 0, next; + /^--?c/ and $options{depslist} = 1, next; + /^--?f/ and ++$options{force}, next; + /^--wget/ and $options{sync} = \&urpm::sync_wget, next; + /^--curl/ and $options{sync} = \&urpm::sync_curl, next; + /^--update$/ and $options{update} = 1, next; + /^-/ and die $usage . _("\nunknown options '%s'\n", $_); + ($name, $url, $with, $relative_hdlist) = ($_, @_); + last; + } $name or die $usage; - my ($type, $dev) = $url =~ m,^(file|ftp|http|removable_(\w+)(?:_\d+)?)://, or die $usage; + my ($type) = $url =~ m,^([^:]*)://, or die $usage; - if ($type eq "removable") { - $dev && -e "/dev/$dev" or die _("%s\ndevice `%s' do not exist\n", $usage, $dev); - } elsif ($with eq "with") { + if ($with eq "with") { $relative_hdlist or die _("%s\n missing\n", $usage); - } elsif ($ftp) { + } elsif ($type =~ /ftp|http/) { $with eq "with" or die _("%s\n`with' missing for ftp media\n", $usage); } my $urpm = new urpm; + $options{sync} and $urpm->{sync} = $options{sync}; $urpm->read_config; - $urpm->add_medium($name, $url, $relative_hdlist, update => $update); - $urpm->update_media(noclean => 1); + $urpm->add_medium($name, $url, $relative_hdlist, update => $options{update}); + $urpm->update_media(%options); #- check creation of media (during update has been successfull) my ($medium) = grep { $_->{name} eq $name } @{$urpm->{media}}; diff --git a/urpmi.spec b/urpmi.spec index 9ffd3f54..dab84086 100644 --- a/urpmi.spec +++ b/urpmi.spec @@ -2,7 +2,7 @@ Name: urpmi Version: 2.1 -Release: 2mdk +Release: 3mdk License: GPL Source0: %{name}.tar.bz2 Source1: %{name}.logrotate @@ -126,6 +126,13 @@ rm -f /var/lib/urpmi/depslist %changelog +* Tue Nov 27 2001 François Pons 2.1-3mdk +- added curl support (kept wget support). +- updated help for urpmi, urpmi.update and urpmi.addmedia. +- fixed bad check of urpmi.addmedium for existing name. +- avoid some error message if description is missing (not all). +- allow any prefix for url (especially removable://...). + * Tue Nov 27 2001 François Pons 2.1-2mdk - removed old optimization to get existing depslist instead of rebuilding it. diff --git a/urpmi.update b/urpmi.update index f7d57663..e35bd65f 100755 --- a/urpmi.update +++ b/urpmi.update @@ -29,18 +29,23 @@ sub main { $options{force} = 0; $options{noclean} = 1; + $options{sync} = undef; foreach (@_) { /^--?a/ and $options{all} = 1, next; /^--?c/ and $options{noclean} = 0, next; /^--?c/ and $options{depslist} = 1, next; /^--?f/ and ++$options{force}, next; + /^--wget/ and $options{sync} = \&urpm::sync_wget, next; + /^--curl/ and $options{sync} = \&urpm::sync_curl, next; /^--?noa/ and next; #- default, keeped for compability. - /^-/ and die _("usage: urpmi.update [-a] ... + /^-/ and die _("usage: urpmi.update [options] ... where is a medium name to update. - -a select all non-removable media. - -c clean headers cache directory. - -f force generation of base files, use another -f for hdlist files. -\nunknown options '%s'\n", $_); +") . _(" -a - select all non-removable media. +") . _(" -c - clean headers cache directory. +") . _(" -f - force generation of hdlist files. +") . _(" --wget - use wget to retrieve distant files. +") . _(" --curl - use curl to retrieve distant files. +") . _("\nunknown options '%s'\n", $_); push @toupdates, $_; } -- cgit v1.2.1