]> git.deb.at Git - deb/packages.git/blob - lib/Packages/DoDownload.pm
Add missing comma
[deb/packages.git] / lib / Packages / DoDownload.pm
1 package Packages::DoDownload;
2
3 use strict;
4 use warnings;
5
6 use CGI ();
7 use DB_File;
8 use Benchmark ':hireswallclock';
9 use Exporter;
10
11 use Deb::Versions;
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 );
16 use Packages::CGI;
17 use Packages::DB;
18
19 our @ISA = qw( Exporter );
20 our @EXPORT = qw( do_download );
21
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
26 #   -- Joy
27
28 # hint:
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",
44         "debian.rutgers.edu",
45         "debian.oregonstate.edu/debian",
46         );
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",
69         );
70 our @south_american_sites = (
71         "ftp.br.debian.org/debian",
72         "ftp.cl.debian.org/debian",
73         );
74 our @australian_sites = (
75         "ftp.au.debian.org/debian",
76         "ftp.wa.au.debian.org/debian",
77         "ftp.nz.debian.org/debian",
78         );
79 our @asian_sites = (
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",
85         ); 
86
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",
91                                );
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",
105         "backports.sipo.nl",
106         "ftp.tuke.sk",
107                                );
108 our @backports_asian_sites = (
109         "backports.mithril-linux.org",
110                              );
111 our @backports_australian_sites = (
112         "mirror.linux.org.au/backports.org",
113                                   );
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",
121                             );
122 our @amd64_asian_sites = (
123         "hanzubon.jp/debian-amd64/debian",
124                          );
125 our @amd64_north_american_sites = (
126         "mirror.espri.arizona.edu/debian-amd64/debian",
127                                   );
128 our @kfreebsd_north_american_sites = (
129         "www.gtlib.gatech.edu/pub/gnuab/debian",
130                                      );
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",
136         "ftp.sh.cvut.cz/MIRRORS/debian-non-linux",
137         "ftp.eila.jussieu.fr/pub/Debian-gnuab",
138                                );
139 my @kfreebsd_asian_sites = (
140         "ftp.citkit.ru/pub/HURD/debian",
141                             );
142 our @nonus_north_american_sites = (
143 #       "ftp.ca.debian.org/debian-non-US",
144         "debian.yorku.ca/debian/non-US",
145         "mirror.direct.ca/linux/debian-non-US",
146         );
147 our @nonus_european_sites = (
148         "non-us.debian.org/debian-non-US",
149         "ftp.de.debian.org/debian-non-US",
150         "ftp.at.debian.org/debian-non-US",
151         "ftp.bg.debian.org/debian-non-US",
152         "ftp.cz.debian.org/debian-non-US",
153         "ftp.fi.debian.org/debian-non-US",
154         "ftp.fr.debian.org/debian-non-US",
155         "ftp.hr.debian.org/debian-non-US",
156         "ftp.hu.debian.org/debian-non-US",
157         "ftp.ie.debian.org/debian-non-US",
158         "ftp.is.debian.org/debian-non-US",
159         "ftp.it.debian.org/debian-non-US",
160         "ftp.nl.debian.org/debian-non-US",
161         "ftp.no.debian.org/debian-non-US",
162         "ftp.pl.debian.org/debian/non-US",
163         "ftp.si.debian.org/debian-non-US",
164         "ftp.es.debian.org/debian-non-US",
165         "ftp.se.debian.org/debian-non-US",
166         "ftp.tr.debian.org/debian-non-US",
167         "ftp.uk.debian.org/debian/non-US",
168         );
169 our @nonus_australian_sites = (
170         "ftp.au.debian.org/debian-non-US",
171         "ftp.wa.au.debian.org/debian-non-US",
172         "ftp.nz.debian.org/debian-non-US",
173         );
174 our @nonus_asian_sites = (
175         "ftp.jp.debian.org/debian-non-US",
176 #       "ftp.kr.debian.org/debian-non-US",
177         "linux.csie.nctu.edu.tw/debian-non-US",
178         "debian.linux.org.tw/debian-non-US",
179         "linux.cdpa.nsysu.edu.tw/debian-non-US",
180         );
181 our @nonus_south_american_sites = (
182         "ftp.br.debian.org/debian-non-US",
183         "ftp.cl.debian.org/debian-non-US",
184         );
185
186 # list of architectures
187 our %arches = (
188         i386    => 'Intel x86',
189         m68k    => 'Motorola 680x0',
190         sparc   => 'SPARC',
191         alpha   => 'Alpha',
192         powerpc => 'PowerPC',
193         arm     => 'ARM',
194         hppa    => 'HP PA-RISC',
195         ia64    => 'Intel IA-64',
196         mips    => 'MIPS',
197         mipsel  => 'MIPS (DEC)',
198         s390    => 'IBM S/390',
199         "hurd-i386" => 'Hurd (i386)',
200         amd64   => 'AMD64',
201         "kfreebsd-i386" => 'GNU/kFreeBSD (i386)',
202         "kfreebsd-amd64" => 'GNU/kFreeBSD (amd64)'
203 );
204
205 sub do_download {
206     my ($params, $opts, $html_header, $menu, $page_content) = @_;
207
208     if ($params->{errors}{package}) {
209         fatal_error( _g( "package not valid or not specified" ) );
210     }
211     if ($params->{errors}{suite}) {
212         fatal_error( _g( "suite not valid or not specified" ) );
213     }
214     if ($params->{errors}{arch}) {
215         fatal_error( _g( "architecture not valid or not specified" ) );
216     }
217     if (@{$opts->{suite}} > 1) {
218         fatal_error( sprintf( _g( "more than one suite specified for download (%s)" ), "@{$opts->{suite}}" ) );
219     }
220     if (@{$opts->{arch}} > 1) {
221         fatal_error( sprintf( _g( "more than one architecture specified for download (%s)" ), "@{$opts->{arch}}" ) );
222     }
223
224     $opts->{h_sections} = { map { $_ => 1 } @SECTIONS };
225     my $pkg = $opts->{package};
226     my $suite = $opts->{suite}[0];
227     my $arch = $opts->{arch}[0] ||'';
228
229     our (%packages_all);
230     my (@results);
231     my ($final_result, $file, $filen, $md5sum, @file_components, $archive) = ("")x5;
232
233     my $st0 = new Benchmark;
234     unless (@Packages::CGI::fatal_errors) {
235         tie %packages_all, 'DB_File', "$DBDIR/packages_all_$suite.db",
236         O_RDONLY, 0666, $DB_BTREE
237             or die "couldn't tie DB $DBDIR/packages_all_$suite.db: $!";
238         
239         read_entry( \%packages, $pkg, \@results, $opts );
240
241         @results = grep { $_->[7] ne 'v' } @results;
242         unless (@results) {
243             fatal_error( _g( "No such package." )."<br>".
244                          sprintf( _g( '<a href="%s">Search for the package</a>' ), "$SEARCH_URL/$pkg" ) );
245         } else {
246             my $final_result = shift @results;
247             foreach (@results) {
248                 if (version_cmp( $_->[7], $final_result->[7] ) > 0) {
249                     $final_result = $_;
250                 }
251             }
252             
253             debug( "final_result=@$final_result", 1 );
254             $archive = $final_result->[1];
255             my %data = split /\000/, $packages_all{"$pkg $arch $final_result->[7]"};
256             $file = $data{filename};
257             @file_components = split('/', $file);
258             $filen = pop(@file_components);
259             
260             $md5sum = $data{md5sum};
261         }
262     }
263
264     %$html_header = ( title => _g( "Package Download Selection" ),
265                       lang => $opts->{lang},
266                       print_title => 1 );
267
268     if ($file) {
269         if ($arch ne 'all') {
270             $$page_content .= '<h2>'.sprintf( _g('Download Page for <kbd>%s</kbd> on %s machines'), $filen, $arches{$arch} ).'</h2>';
271         } else {
272             $$page_content .= '<h2>'.sprintf( _g('Download Page for <kbd>%s</kbd>'), $filen ).'</h2>';
273         }
274         my $directory = join( '/', @file_components).'/';
275         if ($archive ne 'security' ) {
276             $$page_content .= "<p>".sprintf( _g( 'You can download the requested file from the <tt>%s</tt> subdirectory at any of these sites:' ), $directory )."</p>\n";
277         } else {
278             $$page_content .= "<p>".sprintf( _g( 'You can download the requested file from the <tt>%s</tt> subdirectory at:' ), $directory )."</p>\n";
279         }
280
281         hint(sprintf(_g("If you are running Debian, it's strongly suggested to use a
282             package manager like <a href=\"%s\">aptitude</a> or <a
283             href=\"%s\">synaptic</a> to download and install
284             packages, instead of doing so manually via this website."),
285                      make_url('aptitude','',{arch=>undef}), 
286                      make_url('synaptic','',{arch=>undef}) ) );
287         
288         if ($archive eq 'security') {
289             
290             $$page_content .= "<ul><li><a href=\"http://security.debian.org/debian-security/$file\">security.debian.org/debian-security</a></li></ul>";
291             $$page_content .= '<p>'._g( 'Debian security updates are currently officially distributed only via <tt>security.debian.org</tt>.' ).'</p>';
292         } elsif ($archive eq 'amd64') {
293
294             $$page_content .= print_links( _g( "North America" ), $file, @amd64_north_american_sites );
295             $$page_content .= print_links( _g( "Europe" ), $file, @amd64_european_sites );
296             $$page_content .= print_links( _g( "Asia" ), $file, @amd64_asian_sites );
297
298             $$page_content .= '<p>'._g( '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>';
299         } elsif ($archive eq 'kfreebsd') {
300
301             $$page_content .= print_links( _g( "North America" ), $file, @kfreebsd_north_american_sites );
302             $$page_content .= print_links( _g( "Europe" ), $file, @kfreebsd_european_sites );
303             $$page_content .= print_links( _g( "Asia" ), $file, @kfreebsd_asian_sites );
304         
305             $$page_content .= '<p>'._g( '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>';
306         } elsif ($archive eq 'non-US') {
307
308             $$page_content .= print_links( _g( "North America" ), $file, @nonus_north_american_sites );
309             $$page_content .= print_links( _g( "Europe" ), $file, @nonus_european_sites );
310             $$page_content .= print_links( _g( "Australia and New Zealand" ), $file,
311                                            @nonus_australian_sites );
312             $$page_content .= print_links( _g( "Asia" ), $file, @nonus_asian_sites );
313             $$page_content .= print_links( _g( "South America" ), $file, @nonus_south_american_sites );
314             
315             $$page_content .= '<p>'.sprintf( _g('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>';
316         } elsif ($archive eq 'backports') {
317         
318             $$page_content .= '<div class="cardleft">';
319             $$page_content .= print_links( _g( "Europe" ), $file, @backports_european_sites );
320             $$page_content .= '</div><div class="cardright">';
321             $$page_content .= print_links( _g( "Australia and New Zealand" ), $file,
322                                            @backports_australian_sites );
323             $$page_content .= print_links( _g( "Asia" ), $file, @backports_asian_sites );
324             $$page_content .= '</div>';
325             
326             $$page_content .= '<p style="clear:both">'.sprintf( _g( '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>';
327         } elsif ($archive eq 'volatile') {
328             
329             $$page_content .= print_links( _g( "Europe" ), $file, @volatile_european_sites );
330
331             $$page_content .= '<p>'.sprintf( _g( '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>';
332         } elsif ($archive eq 'us') {
333             
334             $$page_content .= '<div class="cardleft">';
335             $$page_content .= print_links( _g( "North America" ), $file, @north_american_sites );
336             $$page_content .= '</div><div class="cardright">';
337             $$page_content .= print_links( _g( "Europe" ), $file, @european_sites );
338             $$page_content .= '</div><div class="cardleft">';
339             $$page_content .= print_links( _g( "Australia and New Zealand" ), $file, @australian_sites );
340             $$page_content .= '</div><div class="cardright">';
341             $$page_content .= print_links( _g( "Asia" ), $file, @asian_sites );
342             $$page_content .= '</div><div class="cardleft">';
343             $$page_content .= print_links( _g( "South America" ), $file, @south_american_sites );
344             $$page_content .= '</div>';
345             
346             $$page_content .= '<p style="clear:both">'.sprintf( _g( '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         }
348     
349     $$page_content .= '<p>'._g( '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>';
350     $$page_content .= "<p>".sprintf( _g( 'The MD5sum for <tt>%s</tt> is <strong>%s</strong>' ), $filen, $md5sum ).'</p>'
351         if $md5sum;
352     }
353 }
354
355 sub print_links {
356     my ( $title, $file, @servers ) = @_;
357
358     my $str = "<p><em>$title</em></p>";
359     $str .= "<ul>";
360     foreach (@servers) {
361         $str .= "<li><a href=\"http://$_/$file\">$_</a></li>\n";
362         # $str .= "<li><a href=\"ftp://$_/$file\">$_</a></li>\n";
363     }
364     $str .= "</ul>";
365
366     return $str;
367 }
368
369 1;