3 ################################################################
5 # Copyright (c) 1995-2014 SUSE Linux Products GmbH
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License version 2 or 3 as
9 # published by the Free Software Foundation.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program (see the file COPYING); if not, write to the
18 # Free Software Foundation, Inc.,
19 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
21 ################################################################
24 unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
36 $url =~ s|://[^@]*@|://|;
40 die "USAGE: $0 DIR URLS..." unless $#ARGV >= 1;
42 my $dir = shift @ARGV;
44 my $ua = LWP::UserAgent->new(
45 agent => "openSUSE build script",
53 if ($url =~ /^zypp:\/\/([^\/]*)\/?/) {
55 my $repo = Build::Zypp::parserepo($1);
56 die "can't parse $1\n" unless $repo;
57 die "missing url in repo ".$repo->{'name'}."\n" unless exists $repo->{'baseurl'};
58 my $u = $repo->{'baseurl'};
59 $u .= '/' unless $u =~ /\/$/;
60 $url =~ s/^zypp:\/\/[^\/]*\/*//;
61 $url = URI->new($u.$url);
62 if ($url->scheme eq 'dir') {
63 my $dest = "$dir/".basename($url->path);
64 unlink($dest); # just in case
65 system('cp', $url->path, $dest) && die("cp $url->path $dest failed\n");
70 if ( defined $ENV{BUILD_ROOT} && -e $ENV{BUILD_ROOT} . "/.repo.config" ) {
71 open FILE, "<", $ENV{BUILD_ROOT} . "/.repo.config" or die $!;
73 next if ($_ !~ /^http[s]?:\/\/([^\/]*)\/?/);
75 my $hidden = URI->new($_);
76 my $ui = $hidden->userinfo;
77 $hidden->userinfo(undef);
78 if ( $url =~ m/^$hidden/ ) {
79 $url = URI->new($url);
88 $url = URI->new($url);
92 my $dest = "$dir/".basename($url->path).".tmp";
93 unlink($dest); # just in case
96 my $res = $ua->mirror($url, $dest);
97 last if $res->is_success;
98 # if it's a redirect we probably got a bad mirror and should just retry
99 die "reqesting " . hide_passwd($original) . " failed: ".$res->status_line."\n" unless $retry;
100 warn "retrying " . hide_passwd($original) . "\n";
102 rename($dest, "$dir/".basename($url->path));