diff options
author | Olivier Blin <oblin@mandriva.com> | 2010-06-16 09:18:25 +0000 |
---|---|---|
committer | Olivier Blin <oblin@mandriva.com> | 2010-06-16 09:18:25 +0000 |
commit | 3fff793cffd8170e0f15a8138e5f9fd7e40cb0cc (patch) | |
tree | d6ded36fbeb704a0d217ea0bc5f24bb22991a8e7 /urpm/media.pm | |
parent | c5580c7aba7a49df77d221c69aea3da2adc0ff8b (diff) | |
download | urpmi-3fff793cffd8170e0f15a8138e5f9fd7e40cb0cc.tar urpmi-3fff793cffd8170e0f15a8138e5f9fd7e40cb0cc.tar.gz urpmi-3fff793cffd8170e0f15a8138e5f9fd7e40cb0cc.tar.bz2 urpmi-3fff793cffd8170e0f15a8138e5f9fd7e40cb0cc.tar.xz urpmi-3fff793cffd8170e0f15a8138e5f9fd7e40cb0cc.zip |
add --zeroconf support in urpmi.addmedia
Diffstat (limited to 'urpm/media.pm')
-rw-r--r-- | urpm/media.pm | 57 |
1 files changed, 56 insertions, 1 deletions
diff --git a/urpm/media.pm b/urpm/media.pm index b7b7f6cb..9f8c138c 100644 --- a/urpm/media.pm +++ b/urpm/media.pm @@ -755,10 +755,61 @@ sub _compute_flags_for_instlist { } +sub maybe_find_zeroconf { + my ($urpm, $url, $options) = @_; + if (delete $options->{zeroconf}) { + $url and die "unexpected url $url together with zeroconf\n"; + $url = find_zeroconf_repository($urpm); + if ($url) { + $url = urpm::mirrors::_add__with_dir($url, delete $options->{"with-dir"}); + delete $options->{mirrorlist}; + } + } + return $url; +} + +sub find_zeroconf_repository { + my ($urpm) = @_; + + my $zeroconf_timeout = 10; + my $res; + eval { + local $SIG{ALRM} = sub { die "timeout" }; + alarm($zeroconf_timeout); + + $urpm->{debug} and $urpm->{debug}("trying to find a zeroconf repository"); + require Net::Bonjour; + $res = Net::Bonjour->new('mdv_urpmi'); + + alarm(0); + }; + + if ($@) { + $urpm->{error}("zeroconf error: $@"), return; + } + + require urpm::mirrors; + my $product_id = urpm::mirrors::parse_LDAP_namespace_structure(cat_('/etc/product.id')); + my $path_suffix = join('/', lc($product_id->{branch}), $product_id->{version}, $product_id->{arch}); + + foreach my $entry ($res->entries) { + my $base_url = $entry->attribute('protocol') . '://' .$entry->address . ':' . $entry->port . $entry->attribute('path'); + my $url = $base_url . '/' . $path_suffix; + my $distribconf = _new_distribconf_and_download($urpm, { url => $url }); + if ($distribconf) { + $urpm->{log}(sprintf("found zeroconf repository: %s", $url)); + return $url; + }; + } + + $urpm->{debug} and $urpm->{debug}("unable to find zeroconf repository"); + return; +} + #- add a new medium, sync the config file accordingly. #- returns the new medium's name. (might be different from the requested #- name if index_name was specified) -#- options: ignore, index_name, nolock, update, virtual, media_info_dir, mirrorlist, with-dir, xml-info, on_the_fly +#- options: ignore, index_name, nolock, update, virtual, media_info_dir, mirrorlist, zeroconf, with-dir, xml-info, on_the_fly sub add_medium { my ($urpm, $name, $url, $with_synthesis, %options) = @_; @@ -777,6 +828,8 @@ sub add_medium { name2medium($urpm, $name) and $urpm->{fatal}(5, N("medium \"%s\" already exists", $name)); } + $url = maybe_find_zeroconf($urpm, $url, \%options); + $url =~ s,/*$,,; #- clear URLs for trailing /es. #- creating the medium info. @@ -878,6 +931,7 @@ sub _register_media_cfg { #- - ask_media : callback to know whether each media should be added #- - only_updates : only add "update" media (used by rpmdrake) #- - mirrorlist +#- - zeroconf #- other options are passed to add_medium(): ignore, nolock, virtual sub add_distrib_media { my ($urpm, $name, $url, %options) = @_; @@ -903,6 +957,7 @@ sub add_distrib_media { _register_media_cfg($urpm, $dir, undef, $distribconf, $media_cfg); } } else { + $url = maybe_find_zeroconf($urpm, $url, \%options); if ($options{mirrorlist}) { $url and die "unexpected url $url together with mirrorlist $options{mirrorlist}\n"; } |