#!/usr/bin/perl ############################################################################ # This file is part of FreeFEM. # # # # FreeFEM is free software: you can redistribute it and/or modify # # it under the terms of the GNU Lesser General Public License as # # published by the Free Software Foundation, either version 3 of # # the License, or (at your option) any later version. # # # # FreeFEM is distributed in the hope that it will be useful, # # but WITHOUT ANY WARRANTY; without even the implied warranty of # # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # # GNU Lesser General Public License for more details. # # # # You should have received a copy of the GNU Lesser General Public License # # along with FreeFEM. If not, see . # ############################################################################ # SUMMARY : Download third-party packages independently of FF configuration # LICENSE : LGPLv3 # ORG : LJLL Universite Pierre et Marie Curie, Paris, FRANCE # AUTHORS : Antoine Le Hyaric # E-MAIL : http://www.ljll.math.upmc.fr/lehyaric use strict; use Getopt::Std; use Digest::MD5 qw(md5_hex); # [[http://perldoc.perl.org/Digest/MD5.html]] # This download script needs to be able to work on platforms that do not have threads (eg Mingw). my $can_use_threads = eval 'use threads;use threads::shared;1'; my %opts; getopts( 'afho:', \%opts ); if ( $opts{h} ) { print <create( \&downloadone, $_ ) } foreach (@threads) { $_->join() } } else { foreach (@downloads) { downloadone($_) } } if ( $errors ne '' ) { print "\n$errors"; exit 1; } sub download { my ( $title, $url, $lic, $pkg, $md5, $opts ) = @_; # skip packages that have not been requested explicitely return if ( $only && !defined $packs{$title} ); # skip packages that are already present if ( -f "pkg/$pkg" && !$opts{f} ) { my $md5check = md5_hex(`cat pkg/$pkg`); if ( ( $md5 eq "none" ) || ( $md5check eq $md5 ) ) { print "$title $pkg done\n"; return; } else { print "$title $pkg md5 change => reget \n"; } } # we do not store the answers to these questions. To repeat the same downloads without manual input, options "-a" and # "-o names" are provided. if ( !$opts{a} ) { print "$title: please check the licence at $lic. Do you want to download $url? (yN)\n"; my $ans = uc ; chomp $ans; return if $ans ne 'Y'; } # uses [[file:../bin/build/download]] push @downloads, "$url,$pkg,$md5,$opts"; } sub downloadone{ ## correct rescue server for done load my($url,$pkg,$md5,$opts)=split(/,/,$_[0]);# warning just $pkg without pkg/$pkg my $cmd="../bin/build/download $url pkg/$pkg $opts"; print "$cmd\n"; system $cmd; if($?){ print "Download failed from $url of $pkg\n"; my $url="https://www.ljll.fr/hecht/pkg/$pkg"; my $cmd="../bin/build/download $url pkg/$pkg $opts"; print "Try other site: $url\n"; system $cmd; if($?){ print "Download 2 times failed from $url of $pkg\n"; my $url="https://joliv.et/freefem/pkg/$pkg"; my $cmd="../bin/build/download $url pkg/$pkg $opts"; print "Try (2 times) other site: $url\n"; system $cmd; if ($?){ $errors.="ERROR: $cmd FAILED\n" } } } # check if resulting package contents are valid my $md5check=md5_hex(`cat pkg/$pkg`); if( ( $md5 ne "none") && ($md5check ne $md5)){ print "Download failed (MD5 check $md5check) from $url of $pkg\n"; my $url="https://www.ljll.fr/hecht/pkg/$pkg"; my $cmd="../bin/build/download $url pkg/$pkg $opts"; print "Try other site: $url\n"; system $cmd; if($?){ $errors.="ERROR 2: $cmd FAILED\n" } else { $md5check=md5_hex(`cat pkg/$pkg`);} if( ($md5check ne $md5)) { $errors.="ERROR2: INVALID MD5 for $pkg $md5check\n"} } }