diff options
author | Zhang Qiang <qiang.z.zhang@intel.com> | 2014-04-03 15:53:09 +0800 |
---|---|---|
committer | Zhang Qiang <qiang.z.zhang@intel.com> | 2014-04-03 15:53:09 +0800 |
commit | b979ae3b9b879ce19582770e2ba89eb3e66f964a (patch) | |
tree | 758e7684bbaa43d8899ccbc49b133ff0112d3a88 /download | |
download | build-b979ae3b9b879ce19582770e2ba89eb3e66f964a.tar.gz build-b979ae3b9b879ce19582770e2ba89eb3e66f964a.tar.bz2 build-b979ae3b9b879ce19582770e2ba89eb3e66f964a.zip |
Imported Upstream version 2013.11.12upstream/2013.11.12
Diffstat (limited to 'download')
-rwxr-xr-x | download | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/download b/download new file mode 100755 index 0000000..9ac2bdf --- /dev/null +++ b/download @@ -0,0 +1,56 @@ +#!/usr/bin/perl -w + +use Net::SSL (); +BEGIN { + $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0, + unshift @INC, ($::ENV{'BUILD_DIR'} || '/usr/lib/build'); +} + +use LWP::UserAgent; +use URI; +use File::Path; +use File::Basename; + +use strict; + +die "USAGE: $0 DIR URLS..." unless $#ARGV >= 1; + +my $dir = shift @ARGV; + +my $ua = LWP::UserAgent->new( + agent => "openSUSE build script", + timeout => 42); + +for my $url (@ARGV) { + if ($url =~ /^zypp:\/\/([^\/]*)\/?/) { + use Build::Zypp; + my $repo = Build::Zypp::parsecfg($1); + die "can't parse $1\n" unless $repo; + die "missing url in repo ".$repo->{'name'}."\n" unless exists $repo->{'baseurl'}; + my $u = $repo->{'baseurl'}; + $u .= '/' unless substr($u, -1, 1) eq '/'; + $url =~ s/^zypp:\/\/[^\/]*\/*//; + $url = URI->new($u.$url); + if ($url->scheme eq 'dir') { + my $dest = "$dir/".basename($url->path); + unlink($dest); # just in case + system('cp', $url->path, $dest) && die("cp $url->path $dest failed\n"); + last; + } + } else { + $url = URI->new($url); + } + $ua->env_proxy if $url->scheme ne 'https'; + my $dest = "$dir/".basename($url->path); + unlink($dest); # just in case + my $retry = 3; + while ($retry--) { + my $res = $ua->mirror($url, $dest); + last if $res->is_success; + # if it's a redirect we probably got a bad mirror and should just retry + die "requesting $url failed: ".$res->status_line."\n" unless $retry && $res->previous; + warn "retrying $url\n"; + } +} + +# vim:sw=2 |