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 ################################################################
25 $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0,
26 unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
38 $url =~ s|://[^@]*@|://|;
42 die "USAGE: $0 DIR URLS..." unless $#ARGV >= 1;
44 my $dir = shift @ARGV;
46 my $ua = LWP::UserAgent->new(
47 agent => "openSUSE build script",
52 if ($url =~ /^zypp:\/\/([^\/]*)\/?/) {
54 my $repo = Build::Zypp::parserepo($1);
55 die "can't parse $1\n" unless $repo;
56 die "missing url in repo ".$repo->{'name'}."\n" unless exists $repo->{'baseurl'};
57 my $u = $repo->{'baseurl'};
58 $u .= '/' unless $u =~ /\/$/;
59 $url =~ s/^zypp:\/\/[^\/]*\/*//;
60 $url = URI->new($u.$url);
61 if ($url->scheme eq 'dir') {
62 my $dest = "$dir/".basename($url->path);
63 unlink($dest); # just in case
64 system('cp', $url->path, $dest) && die("cp $url->path $dest failed\n");
69 if ( defined $ENV{BUILD_ROOT} && -e $ENV{BUILD_ROOT} . "/.repo.config" ) {
70 open FILE, "<", $ENV{BUILD_ROOT} . "/.repo.config" or die $!;
72 next if ($_ !~ /^http[s]?:\/\/([^\/]*)\/?/);
74 my $hidden = URI->new($_);
75 my $ui = $hidden->userinfo;
76 $hidden->userinfo(undef);
77 if ( $url =~ m/^$hidden/ ) {
78 $url = URI->new($url);
87 $url = URI->new($url);
90 $ua->env_proxy if $url->scheme ne 'https';
91 my $dest = "$dir/".basename($url->path);
92 unlink($dest); # just in case
95 my $res = $ua->mirror($url, $dest);
96 last if $res->is_success;
97 # if it's a redirect we probably got a bad mirror and should just retry
98 die "reqesting " . hide_passwd($original) . " failed: ".$res->status_line."\n" unless $retry && $res->previous;
99 warn "retrying " . hide_passwd($original) . "\n";