source: freewrt/scripts/download.pl@ 655dec8

Last change on this file since 655dec8 was ebbcca7, checked in by Thorsten Glaser <tg@…>, 19 years ago

sourceforge.net mirrors were parsed from the website output, but
these … change it from time to time, so just add a hard-coded list
of mirrors from mirports framework and openbsd ports tree

git-svn-id: svn://www.freewrt.org/trunk/freewrt@2007 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100755
File size: 3.3 KB
Line 
1#!/usr/bin/perl
2# $FreeWRT$
3#-
4# This file is part of the FreeWRT project. FreeWRT is copyrighted
5# material, please see the LICENCE file in the top-level directory
6# or at http://www.freewrt.org/licence for details.
7
8use strict;
9use warnings;
10
11my $target = shift @ARGV;
12my $filename = shift @ARGV;
13my $md5sum = shift @ARGV;
14my @mirrors;
15
16my $ok;
17
18@ARGV > 0 or die "Syntax: $0 <target dir> <filename> <md5sum> <mirror> [<mirror> ...]\n";
19
20sub download
21{
22 my $mirror = shift;
23
24 open WGET, "wget -t1 --timeout=20 -O- \"$mirror/$filename\" |" or die "Cannot launch wget.\n";
25 open MD5SUM, "| md5sum > \"$target/$filename.md5sum\"" or die "Cannot launch md5sum.\n";
26 open OUTPUT, "> $target/$filename.dl" or die "Cannot create file $target/$filename.dl: $!\n";
27 my $buffer;
28 while (read WGET, $buffer, 1048576) {
29 print MD5SUM $buffer;
30 print OUTPUT $buffer;
31 }
32 close MD5SUM;
33 close WGET;
34 close OUTPUT;
35
36 if (($? >> 8) != 0 ) {
37 print STDERR "Download failed.\n";
38 cleanup();
39 return;
40 }
41
42 my $sum = `cat "$target/$filename.md5sum"`;
43 $sum =~ /^(\w+)\s+/ or die "Could not generate md5sum\n";
44 $sum = $1;
45
46 if ($md5sum ne 'NO') {
47 if ($sum ne $md5sum) {
48 print STDERR "MD5 sum of the downloaded file does not match - deleting download.\n";
49 cleanup();
50 return;
51 }
52 }
53
54 unlink "$target/$filename";
55 system("mv \"$target/$filename.dl\" \"$target/$filename\"");
56 cleanup();
57}
58
59sub cleanup
60{
61 unlink "$target/$filename.dl";
62 unlink "$target/$filename.md5sum";
63}
64
65foreach my $mirror (@ARGV) {
66 if ($mirror =~ /^\@SF\/(.+)$/) {
67 my $sfpath = $1;
68 push @mirrors, "http://easynews.dl.sourceforge.net/sourceforge/$sfpath";
69 push @mirrors, "http://puzzle.dl.sourceforge.net/sourceforge/$sfpath";
70 push @mirrors, "http://optusnet.dl.sourceforge.net/sourceforge/$sfpath";
71 push @mirrors, "http://heanet.dl.sourceforge.net/sourceforge/$sfpath";
72 push @mirrors, "http://jaist.dl.sourceforge.net/sourceforge/$sfpath";
73 push @mirrors, "http://nchc.dl.sourceforge.net/sourceforge/$sfpath";
74 push @mirrors, "http://switch.dl.sourceforge.net/sourceforge/$sfpath";
75 push @mirrors, "http://kent.dl.sourceforge.net/sourceforge/$sfpath";
76 push @mirrors, "http://internap.dl.sourceforge.net/sourceforge/$sfpath";
77 push @mirrors, "http://mesh.dl.sourceforge.net/sourceforge/$sfpath";
78 push @mirrors, "http://ovh.dl.sourceforge.net/sourceforge/$sfpath";
79 push @mirrors, "http://surfnet.dl.sourceforge.net/sourceforge/$sfpath";
80 push @mirrors, "http://ufpr.dl.sourceforge.net/sourceforge/$sfpath";
81 push @mirrors, "http://dl.sourceforge.net/sourceforge/$sfpath";
82 } elsif ($mirror =~ /^\@GNU\/(.+)$/) {
83 my $gnupath = $1;
84 push @mirrors, "ftp://ftp.gnu.org/gnu/$gnupath";
85 push @mirrors, "ftp://ftp.belnet.be/mirror/ftp.gnu.org/gnu/$gnupath";
86 push @mirrors, "ftp://ftp.mirror.nl/pub/mirror/gnu/$gnupath";
87 push @mirrors, "http://mirror.switch.ch/ftp/mirror/gnu/$gnupath";
88 push @mirrors, "ftp://ftp.uu.net/archive/systems/gnu/$gnupath";
89 push @mirrors, "ftp://ftp.eu.uu.net/pub/gnu/$gnupath";
90 push @mirrors, "ftp://ftp.leo.org/pub/comp/os/unix/gnu/$gnupath";
91 push @mirrors, "ftp://ftp.digex.net/pub/gnu/$gnupath";
92 } else {
93 push @mirrors, $mirror;
94 }
95}
96
97push @mirrors, 'http://www.freewrt.org/distfiles/';
98
99while (!$ok) {
100 my $mirror = shift @mirrors;
101 $mirror or die "No more mirrors to try - giving up.\n";
102
103 download($mirror);
104 -f "$target/$filename" and $ok = 1;
105}
106
107$SIG{INT} = \&cleanup;
108
Note: See TracBrowser for help on using the repository browser.