reintroduce LINUX_2_4 and LINUX_2_6 as config variables
[openwrt.git] / scripts / download.pl
index 009ed3b..8f5d1d6 100755 (executable)
@@ -18,15 +18,27 @@ my $ok;
 
 @ARGV > 0 or die "Syntax: $0 <target dir> <filename> <md5sum> <mirror> [<mirror> ...]\n";
 
-my $md5cmd = `which md5sum`;
-$md5cmd =~ /not found/ and $md5cmd = `which md5`;
-$md5cmd =~ /not found/ and die 'no md5 checksum program found, please install md5 or md5sum';
+sub which($) {
+       my $prog = shift;
+       my $res = `which $prog`;
+       $res or return undef;
+       $res =~ /^no / and return undef;
+       $res =~ /not found/ and return undef;
+       return $res;
+}
+
+my $md5cmd = which("md5sum");
+$md5cmd or $md5cmd = which("md5");
+$md5cmd or die 'no md5 checksum program found, please install md5 or md5sum';
+chomp $md5cmd;
 
 sub download
 {
        my $mirror = shift;
+       my $options = $ENV{WGET_OPTIONS};
+       $options or $options = "";
 
-       open WGET, "wget -t1 --timeout=20 -O- \"$mirror/$filename\" |" or die "Cannot launch wget.\n";
+       open WGET, "wget -t1 --timeout=20 $options -O- \"$mirror/$filename\" |" or die "Cannot launch wget.\n";
        open MD5SUM, "| $md5cmd > \"$target/$filename.md5sum\"" or die "Cannot launch md5sum.\n";
        open OUTPUT, "> $target/$filename.dl" or die "Cannot create file $target/$filename.dl: $!\n";
        my $buffer;
@@ -45,7 +57,7 @@ sub download
        }
        
        my $sum = `cat "$target/$filename.md5sum"`;
-       $sum =~ /^(\w+)\s+/ or die "Could not generate md5sum\n";
+       $sum =~ /^(\w+)\s*/ or die "Could not generate md5sum\n";
        $sum = $1;
        
        if (($md5sum =~ /\w{32}/) and ($sum ne $md5sum)) {