diff options
author | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-03-21T14·10+0000 |
---|---|---|
committer | Eelco Dolstra <e.dolstra@tudelft.nl> | 2003-03-21T14·10+0000 |
commit | e582ee67cd682c13667daccf33e8071189ef946c (patch) | |
tree | dda9e5e2843aef37a345157e4f4afcf1cf155d08 /src | |
parent | 88d257b17f0f668798568d68e2d2063f31fe8a2f (diff) |
* Fetch sources from the network.
Diffstat (limited to 'src')
-rwxr-xr-x | src/nix-instantiate | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/nix-instantiate b/src/nix-instantiate index 4823d221252d..63c858864ddf 100755 --- a/src/nix-instantiate +++ b/src/nix-instantiate @@ -4,10 +4,34 @@ use strict; use FileHandle; use File::Spec; -my $outdir = $ARGV[0]; +my $outdir = File::Spec->rel2abs($ARGV[0]); +my $netdir = File::Spec->rel2abs($ARGV[1]); my %donetmpls = (); +sub fetchFile { + my $loc = shift; + + if ($loc =~ /^([+\w\d\.\/-]+)$/) { + return $1; + } elsif ($loc =~ /^url\((.*)\)$/) { + my $url = $1; + $url =~ /\/([^\/]+)$/ || die "invalid url $url"; + my $fn = "$netdir/$1"; + if (! -f $fn) { + print "fetching $url...\n"; + system "cd $netdir; wget --quiet -N $url"; + if ($? != 0) { + unlink($fn); + die; + } + } + return $fn; + } else { + die "invalid file specified $loc"; + } +} + sub convert { my $descr = shift; @@ -28,9 +52,9 @@ sub convert { while (<$IN>) { chomp; - if (/^(\w+)\s*=\s*([+\w\d\.\/-]+)\s*(\#.*)?$/) { - my $name = $1; - my $file = $2; + if (/^(\w+)\s*=\s*([^\#\s]*)\s*(\#.*)?$/) { + my ($name, $loc) = ($1, $2); + my $file = fetchFile($loc); $file = File::Spec->rel2abs($file, $dir); my $out = `md5sum $file`; die unless ($? == 0); @@ -56,6 +80,6 @@ sub convert { return $outfile; } -for (my $i = 1; $i < scalar @ARGV; $i++) { +for (my $i = 2; $i < scalar @ARGV; $i++) { convert(File::Spec->rel2abs($ARGV[$i])); } |