1 package Packages::DoDownload;
8 use Benchmark ':hireswallclock';
12 use Packages::I18N::Locale;
13 use Packages::HTML ();
14 use Packages::Search qw( :all );
15 use Packages::Config qw( $HOME $DBDIR @SUITES @ARCHIVES @SECTIONS @ARCHITECTURES $SEARCH_URL );
19 our @ISA = qw( Exporter );
20 our @EXPORT = qw( do_download );
22 # TODO: find a way to get the U.S. mirror list from a more authoritive
23 # location automatically. might not be overly smart to automatize it
24 # completely, since I hand pick sites that are up-to-date, fast, and
25 # have HTTP on a reasonably short URL
29 # grep-dctrl -F Site,Alias -e '(udel|bigfoot|kernel|crosslink|internap|cerias|lcs.mit|progeny)' Mirrors.masterlist | timestamps/archive_mirror_check.py
30 our @north_american_sites = (
31 "ftp.us.debian.org/debian",
32 "http.us.debian.org/debian",
33 "ftp.debian.org/debian",
34 # "ftp.ca.debian.org/debian",
35 "ftp.egr.msu.edu/debian",
36 "mirrors.kernel.org/debian",
37 "archive.progeny.com/debian",
38 "debian.crosslink.net/debian",
39 "ftp-mirror.internap.com/pub/debian",
40 "ftp.cerias.purdue.edu/pub/os/debian",
41 "ftp.lug.udel.edu/debian",
42 "debian.lcs.mit.edu/debian",
43 "debian.teleglobe.net",
45 "debian.oregonstate.edu/debian",
47 our @european_sites = (
48 "ftp.de.debian.org/debian",
49 "ftp.at.debian.org/debian",
50 "ftp.bg.debian.org/debian",
51 "ftp.cz.debian.org/debian",
52 "ftp.dk.debian.org/debian",
53 "ftp.ee.debian.org/debian",
54 "ftp.fi.debian.org/debian",
55 "ftp.fr.debian.org/debian",
56 "ftp.hr.debian.org/debian",
57 "ftp.hu.debian.org/debian",
58 "ftp.ie.debian.org/debian",
59 "ftp.is.debian.org/debian",
60 "ftp.it.debian.org/debian",
61 "ftp.nl.debian.org/debian",
62 "ftp.no.debian.org/debian",
63 "ftp.pl.debian.org/debian",
64 "ftp.si.debian.org/debian",
65 "ftp.es.debian.org/debian",
66 "ftp.se.debian.org/debian",
67 "ftp.tr.debian.org/debian",
68 "ftp.uk.debian.org/debian",
70 our @south_american_sites = (
71 "ftp.br.debian.org/debian",
72 "ftp.cl.debian.org/debian",
74 our @australian_sites = (
75 "ftp.au.debian.org/debian",
76 "ftp.wa.au.debian.org/debian",
77 "ftp.nz.debian.org/debian",
80 "ftp.jp.debian.org/debian",
81 # "ftp.kr.debian.org/debian",
82 "linux.csie.nctu.edu.tw/debian",
83 "debian.linux.org.tw/debian",
84 "linux.cdpa.nsysu.edu.tw/debian",
87 our @volatile_european_sites = (
88 "volatile.debian.net/debian-volatile",
89 "ftp2.de.debian.org/debian-volatile",
90 "ftp.sk.debian.org/debian-volatile",
92 our @backports_european_sites = (
93 "www.backports.org/debian",
94 "debian.sil.at/backports.org/",
95 "backports.debian.or.at/backports.org",
96 "mirror.realroute.net/backports.org",
97 "backports.cisbg.com",
98 "backports.linuxdediziert.de/backports.org",
99 "debian.netcologne.de/debian-backports",
100 "ftp.de.debian.org/backports.org",
101 "mirror.buildd.net/backports.org",
102 "ftp.estpak.ee/backports.org",
103 "debian.acantho.net/backports.org",
104 "backports.essentkabel.com/backports.org",
108 our @backports_asian_sites = (
109 "backports.mithril-linux.org",
111 our @backports_australian_sites = (
112 "mirror.linux.org.au/backports.org",
114 our @amd64_european_sites = (
115 "amd64.debian.net/debian",
116 "ftp.de.debian.org/debian-amd64/debian",
117 "bach.hpc2n.umu.se/debian-amd64/debian",
118 "bytekeeper.as28747.net/debian-amd64/debian",
119 "mirror.switch.ch/debian-amd64/debian",
120 "ftp.nl.debian.org/debian-amd64/debian",
122 our @amd64_asian_sites = (
123 "hanzubon.jp/debian-amd64/debian",
125 our @amd64_north_american_sites = (
126 "mirror.espri.arizona.edu/debian-amd64/debian",
128 our @kfreebsd_north_american_sites = (
129 "www.gtlib.gatech.edu/pub/gnuab/debian",
131 our @kfreebsd_european_sites = (
132 # master site, aka ftp.gnuab.org
133 "kfreebsd-gnu.debian.net/debian",
134 "ftp.easynet.be/ftp/gnuab/debian",
135 "ftp.de.debian.org/debian-kfreebsd",
137 our @nonus_north_american_sites = (
138 # "ftp.ca.debian.org/debian-non-US",
139 "debian.yorku.ca/debian/non-US",
140 "mirror.direct.ca/linux/debian-non-US",
142 our @nonus_european_sites = (
143 "non-us.debian.org/debian-non-US",
144 "ftp.de.debian.org/debian-non-US",
145 "ftp.at.debian.org/debian-non-US",
146 "ftp.bg.debian.org/debian-non-US",
147 "ftp.cz.debian.org/debian-non-US",
148 "ftp.fi.debian.org/debian-non-US",
149 "ftp.fr.debian.org/debian-non-US",
150 "ftp.hr.debian.org/debian-non-US",
151 "ftp.hu.debian.org/debian-non-US",
152 "ftp.ie.debian.org/debian-non-US",
153 "ftp.is.debian.org/debian-non-US",
154 "ftp.it.debian.org/debian-non-US",
155 "ftp.nl.debian.org/debian-non-US",
156 "ftp.no.debian.org/debian-non-US",
157 "ftp.pl.debian.org/debian/non-US",
158 "ftp.si.debian.org/debian-non-US",
159 "ftp.es.debian.org/debian-non-US",
160 "ftp.se.debian.org/debian-non-US",
161 "ftp.tr.debian.org/debian-non-US",
162 "ftp.uk.debian.org/debian/non-US",
164 our @nonus_australian_sites = (
165 "ftp.au.debian.org/debian-non-US",
166 "ftp.wa.au.debian.org/debian-non-US",
167 "ftp.nz.debian.org/debian-non-US",
169 our @nonus_asian_sites = (
170 "ftp.jp.debian.org/debian-non-US",
171 # "ftp.kr.debian.org/debian-non-US",
172 "linux.csie.nctu.edu.tw/debian-non-US",
173 "debian.linux.org.tw/debian-non-US",
174 "linux.cdpa.nsysu.edu.tw/debian-non-US",
176 our @nonus_south_american_sites = (
177 "ftp.br.debian.org/debian-non-US",
178 "ftp.cl.debian.org/debian-non-US",
181 # list of architectures
184 m68k => 'Motorola 680x0',
187 powerpc => 'PowerPC',
189 hppa => 'HP PA-RISC',
190 ia64 => 'Intel IA-64',
192 mipsel => 'MIPS (DEC)',
194 "hurd-i386" => 'Hurd (i386)',
196 "kfreebsd-i386" => 'GNU/kFreeBSD (i386)'
200 my ($params, $opts, $html_header, $menu, $page_content) = @_;
202 if ($params->{errors}{package}) {
203 fatal_error( _( "package not valid or not specified" ) );
205 if ($params->{errors}{suite}) {
206 fatal_error( _( "suite not valid or not specified" ) );
208 if ($params->{errors}{arch}) {
209 fatal_error( _( "architecture not valid or not specified" ) );
211 if (@{$opts->{suite}} > 1) {
212 fatal_error( sprintf( _( "more than one suite specified for download (%s)" ), "@{$opts->{suite}}" ) );
214 if (@{$opts->{arch}} > 1) {
215 fatal_error( sprintf( _( "more than one architecture specified for download (%s)" ), "@{$opts->{arch}}" ) );
218 $opts->{h_sections} = { map { $_ => 1 } @SECTIONS };
219 my $pkg = $opts->{package};
220 my $suite = $opts->{suite}[0];
221 my $arch = $opts->{arch}[0] ||'';
225 my ($final_result, $file, $filen, $md5sum, @file_components, $archive) = ("")x5;
227 my $st0 = new Benchmark;
228 unless (@Packages::CGI::fatal_errors) {
229 tie %packages_all, 'DB_File', "$DBDIR/packages_all_$suite.db",
230 O_RDONLY, 0666, $DB_BTREE
231 or die "couldn't tie DB $DBDIR/packages_all_$suite.db: $!";
233 read_entry( \%packages, $pkg, \@results, $opts );
236 fatal_error( _( "No such package." )."<br>".
237 sprintf( _( '<a href="%s">Search for the package</a>' ), "$SEARCH_URL/$pkg" ) );
239 my $final_result = shift @results;
241 if (version_cmp( $_->[7], $final_result->[7] ) > 0) {
246 $archive = $final_result->[1];
247 my %data = split /\000/, $packages_all{"$pkg $arch $final_result->[7]"};
248 $file = $data{filename};
249 @file_components = split('/', $file);
250 $filen = pop(@file_components);
252 $md5sum = $data{md5sum};
256 %$html_header = ( title => _( "Package Download Selection" ),
257 lang => $opts->{lang},
261 if ($arch ne 'all') {
262 $$page_content .= '<h2>'.sprintf( _('Download Page for <kbd>%s</kbd> on %s machines'), $filen, $arches{$arch} ).'</h2>';
264 $$page_content .= '<h2>'.sprintf( _('Download Page for <kbd>%s</kbd>'), $filen ).'</h2>';
266 my $directory = join( '/', @file_components).'/';
267 if ($archive ne 'security' ) {
268 $$page_content .= "<p>".sprintf( _( 'You can download the requested file from the <tt>%s</tt> subdirectory at any of these sites:' ), $directory )."</p>\n";
270 $$page_content .= "<p>".sprintf( _( 'You can download the requested file from the <tt>%s</tt> subdirectory at:' ), $directory )."</p>\n";
273 if ($archive eq 'security') {
275 $$page_content .= "<ul><li><a href=\"http://security.debian.org/debian-security/$file\">security.debian.org/debian-security</a></li></ul>";
276 $$page_content .= '<p>'._( 'Debian security updates are currently officially distributed only via <tt>security.debian.org</tt>.' ).'</p>';
277 } elsif ($arch eq 'amd64') {
279 $$page_content .= print_links( _( "North America" ), $file, @amd64_north_american_sites );
280 $$page_content .= print_links( _( "Europe" ), $file, @amd64_european_sites );
281 # $$page_content .= print_links( "Australia and New Zealand", $file,
282 # @nonus_australian_sites );
283 $$page_content .= print_links( _( "Asia" ), $file, @amd64_asian_sites );
284 # $$page_content .= print_links( "South America", $file, @nonus_south_american_sites );
286 $$page_content .= '<p>'._( 'Note that AMD64 is not officialy included in the Debian archive yet, but the AMD64 porter group keeps their archive in sync with the official archive as close as possible. See the <a href="http://www.debian.org/ports/amd64/">AMD64 ports page</a> for current information.' ).'</p>';
287 } elsif ($arch eq 'kfreebsd-i386') {
289 $$page_content .= print_links( _( "North America" ), $file, @kfreebsd_north_american_sites );
290 $$page_content .= print_links( _( "Europe" ), $file, @kfreebsd_european_sites );
291 # $$page_content .= print_links( "Australia and New Zealand", $file,
292 # @nonus_australian_sites );
293 # $$page_content .= print_links( "Asia", $file, @amd64_asian_sites );
294 # $$page_content .= print_links( "South America", $file, @nonus_south_american_sites );
296 $$page_content .= '<p>'._( 'Note that GNU/kFreeBSD is not officialy included in the Debian archive yet, but the GNU/kFreeBSD porter group keeps their archive in sync with the official archive as close as possible. See the <a href="http://www.debian.org/ports/kfreebsd-gnu/">GNU/kFreeBSD ports page</a> for current information.' ).'</p>';
297 } elsif ($archive eq 'non-US') {
299 $$page_content .= print_links( _( "North America" ), $file, @nonus_north_american_sites );
300 $$page_content .= print_links( _( "Europe" ), $file, @nonus_european_sites );
301 $$page_content .= print_links( _( "Australia and New Zealand" ), $file,
302 @nonus_australian_sites );
303 $$page_content .= print_links( _( "Asia" ), $file, @nonus_asian_sites );
304 $$page_content .= print_links( _( "South America" ), $file, @nonus_south_american_sites );
306 $$page_content .= '<p>'.sprintf( _('If none of the above sites are fast enough for you, please see our <a href="%s">complete mirror list</a>.' ), 'http://www.debian.org/mirror/list-non-US' ).'</p>';
307 } elsif ($archive eq 'backports') {
309 # $$page_content .= print_links( "North America", $file, @nonus_north_american_sites );
310 $$page_content .= '<div class="cardleft">';
311 $$page_content .= print_links( _( "Europe" ), $file, @backports_european_sites );
312 $$page_content .= '</div><div class="cardright">';
313 $$page_content .= print_links( _( "Australia and New Zealand" ), $file,
314 @backports_australian_sites );
315 $$page_content .= print_links( _( "Asia" ), $file, @backports_asian_sites );
316 # $$page_content .= print_links( "South America", $file, @nonus_south_american_sites );
317 $$page_content .= '</div>';
319 $$page_content .= '<p style="clear:both">'.sprintf( _( 'If none of the above sites are fast enough for you, please see our <a href="%s">complete mirror list</a>.'), 'http://www.backports.org/debian/README.mirrors.html' ).'</p>';
320 } elsif ($archive eq 'volatile') {
322 # $$page_content .= print_links( "North America", $file, @nonus_north_american_sites );
323 $$page_content .= print_links( _( "Europe" ), $file, @volatile_european_sites );
324 # $$page_content .= print_links( "Australia and New Zealand", $file,
325 # @nonus_australian_sites );
326 # $$page_content .= print_links( "Asia", $file, @nonus_asian_sites );
327 # $$page_content .= print_links( "South America", $file, @nonus_south_american_sites );
329 $$page_content .= '<p>'.sprintf( _( 'If none of the above sites are fast enough for you, please see our <a href="%s">complete mirror list</a>.' ), 'http://volatile.debian.net/mirrors.html' ).'</p>';
330 } elsif ($archive eq 'us') {
332 $$page_content .= '<div class="cardleft">';
333 $$page_content .= print_links( _( "North America" ), $file, @north_american_sites );
334 $$page_content .= '</div><div class="cardright">';
335 $$page_content .= print_links( _( "Europe" ), $file, @european_sites );
336 $$page_content .= '</div><div class="cardleft">';
337 $$page_content .= print_links( _( "Australia and New Zealand" ), $file, @australian_sites );
338 $$page_content .= '</div><div class="cardright">';
339 $$page_content .= print_links( _( "Asia" ), $file, @asian_sites );
340 $$page_content .= '</div><div class="cardleft">';
341 $$page_content .= print_links( _( "South America" ), $file, @south_american_sites );
342 $$page_content .= '</div>';
344 $$page_content .= '<p style="clear:both">'.sprintf( _( 'If none of the above sites are fast enough for you, please see our <a href="%s">complete mirror list</a>.' ), 'http://www.debian.org/mirror/list' ).'</p>';
347 $$page_content .= '<p>'._( 'Note that in some browsers you will need to tell your browser you want the file saved to a file. For example, in Firefox or Mozilla, you should hold the Shift key when you click on the URL.' ).'</p>';
348 $$page_content .= "<p>".sprintf( _( 'The MD5sum for <tt>%s</tt> is <strong>%s</strong>' ), $filen, $md5sum ).'</p>'
354 my ( $title, $file, @servers ) = @_;
356 my $str = "<p><em>$title</em></p>";
359 $str .= "<li><a href=\"http://$_/$file\">$_</a></li>\n";
360 # $str .= "<li><a href=\"ftp://$_/$file\">$_</a></li>\n";