2008-03-14 13:51:43 +00:00
|
|
|
#! /usr/bin/perl -w
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
|
|
|
|
my $list = shift;
|
|
|
|
my $expr = shift;
|
|
|
|
|
|
|
|
open LIST, "<$list";
|
|
|
|
open NEW, ">$list.tmp";
|
|
|
|
open EXPR, ">$expr";
|
|
|
|
|
|
|
|
print EXPR "{fetchurl}: [\n";
|
|
|
|
|
|
|
|
my $baseURL;
|
|
|
|
|
|
|
|
while (<LIST>) {
|
|
|
|
|
|
|
|
if (/^\s*baseURL\s+(\S+)\s*$/) {
|
|
|
|
$baseURL = $1;
|
|
|
|
print NEW "baseURL $baseURL\n";
|
|
|
|
}
|
|
|
|
|
2008-03-18 14:56:47 +00:00
|
|
|
elsif (/^\s*(\S+)(\s+([a-z0-9]+))?\s*$/) {
|
2008-03-14 13:51:43 +00:00
|
|
|
my $pkgName = $1;
|
|
|
|
my $url = "$baseURL/$pkgName";
|
|
|
|
my $hash = $3;
|
|
|
|
if (!defined $hash) {
|
|
|
|
$hash = `nix-prefetch-url '$url'`;
|
|
|
|
die "fetch of `$url' failed" if ($? != 0);
|
|
|
|
chomp $hash;
|
|
|
|
}
|
|
|
|
print NEW "$pkgName $hash\n";
|
2008-03-18 14:56:47 +00:00
|
|
|
if (length $hash == 32) {
|
|
|
|
print EXPR " (fetchurl {url=$url; md5=\"$hash\";})\n";
|
|
|
|
} else {
|
|
|
|
print EXPR " (fetchurl {url=$url; sha256=\"$hash\";})\n";
|
|
|
|
}
|
2008-03-14 13:51:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
else {
|
|
|
|
die "invalid line"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
print EXPR "]\n";
|
|
|
|
|
|
|
|
close LIST;
|
|
|
|
close NEW;
|
|
|
|
close EXPR;
|
|
|
|
|
|
|
|
rename "$list\.tmp", "$list" or die "cannot rename";
|