download.pl: use http://sources.lede-project.org as download mirror
[openwrt/openwrt.git] / scripts / download.pl
index 3b8b267a427eef70c49ef1c9453f1b568b834fdc..548eb7a14f2c1442705e8dd71a3db560aa67ffb3 100755 (executable)
@@ -1,6 +1,7 @@
 #!/usr/bin/env perl
 # 
 # Copyright (C) 2006 OpenWrt.org
+# Copyright (C) 2016 LEDE project
 #
 # This is free software, licensed under the GNU General Public License v2.
 # See /LICENSE for more information.
@@ -63,7 +64,7 @@ sub hash_cmd() {
        my $len = length($file_hash);
        my $cmd;
 
-       $len == 64 and return "openssl dgst -sha256";
+       $len == 64 and return "openssl dgst -sha256 | sed -e 's,.*= ,,'";
        $len == 32 and do {
                my $cmd = which("md5sum") || which("md5") || die 'no md5 checksum program found, please install md5 or md5sum';
                chomp $cmd;
@@ -118,7 +119,7 @@ sub download
                copy($link, "$target/$filename.dl");
 
                $hash_cmd and do {
-                       if (system("$hash_cmd '$target/$filename.dl' > '$target/$filename.hash'")) {
+                       if (system("cat '$target/$filename.dl' | $hash_cmd > '$target/$filename.hash'")) {
                                print("Failed to generate hash for $filename\n");
                                return;
                        }
@@ -176,6 +177,17 @@ foreach my $mirror (@ARGV) {
                for (1 .. 5) {
                        push @mirrors, "http://downloads.sourceforge.net/$1";
                }
+       } elsif ($mirror =~ /^\@APACHE\/(.+)$/) {
+               push @mirrors, "http://ftp.tudelft.nl/apache/$1";
+               push @mirrors, "http://apache.openmirror.de/$1";
+               push @mirrors, "http://mirrors.ocf.berkeley.edu/apache/$1";
+               push @mirrors, "http://mirror.cc.columbia.edu/pub/software/apache/$1";
+               push @mirrors, "http://ftp.jaist.ac.jp/pub/apache/$1";
+       } elsif ($mirror =~ /^\@GITHUB\/(.+)$/) {
+               # give github a few more tries (different mirrors)
+               for (1 .. 5) {
+                       push @mirrors, "https://raw.githubusercontent.com/$1";
+               }
        } elsif ($mirror =~ /^\@GNU\/(.+)$/) {
                push @mirrors, "http://ftpmirror.gnu.org/$1";
                push @mirrors, "http://ftp.gnu.org/pub/gnu/$1";
@@ -213,6 +225,7 @@ foreach my $mirror (@ARGV) {
 }
 
 #push @mirrors, 'http://mirror1.openwrt.org';
+push @mirrors, 'http://sources.lede-project.org';
 push @mirrors, 'http://mirror2.openwrt.org/sources';
 push @mirrors, 'http://downloads.openwrt.org/sources';