2003-03-20 17:52:30 +01:00
|
|
|
#! /usr/bin/perl -w
|
|
|
|
|
2003-03-20 23:23:48 +01:00
|
|
|
use strict;
|
|
|
|
use FileHandle;
|
|
|
|
use File::Spec;
|
2003-03-25 12:39:51 +01:00
|
|
|
use Digest::MD5;
|
2003-03-20 23:23:48 +01:00
|
|
|
|
2003-03-24 13:49:40 +01:00
|
|
|
my $system = "@SYSTEM@";
|
|
|
|
|
2003-03-21 15:10:06 +01:00
|
|
|
my $outdir = File::Spec->rel2abs($ARGV[0]);
|
|
|
|
my $netdir = File::Spec->rel2abs($ARGV[1]);
|
2003-03-20 23:23:48 +01:00
|
|
|
|
|
|
|
my %donetmpls = ();
|
|
|
|
|
2003-03-21 15:10:06 +01:00
|
|
|
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";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-25 12:39:51 +01:00
|
|
|
sub hashFile {
|
|
|
|
my $file = shift;
|
|
|
|
open FILE, "< $file" or die "cannot open $file";
|
|
|
|
# !!! error checking
|
|
|
|
my $hash = Digest::MD5->new->addfile(*FILE)->hexdigest;
|
|
|
|
close FILE;
|
|
|
|
return $hash;
|
|
|
|
}
|
|
|
|
|
2003-03-20 23:23:48 +01:00
|
|
|
sub convert {
|
|
|
|
my $descr = shift;
|
|
|
|
|
|
|
|
if (defined $donetmpls{$descr}) {
|
|
|
|
return $donetmpls{$descr};
|
2003-03-20 17:52:30 +01:00
|
|
|
}
|
|
|
|
|
2003-03-20 23:23:48 +01:00
|
|
|
my ($x, $dir, $fn) = File::Spec->splitpath($descr);
|
|
|
|
|
|
|
|
print "$descr\n";
|
|
|
|
|
|
|
|
my $IN = new FileHandle;
|
|
|
|
my $OUT = new FileHandle;
|
2003-03-25 12:39:51 +01:00
|
|
|
my $tmpfile = "$outdir/$fn-tmp";
|
2003-03-20 23:23:48 +01:00
|
|
|
open $IN, "< $descr" or die "cannot open $descr";
|
|
|
|
|
2003-04-01 16:00:47 +02:00
|
|
|
# Descr([Bind("x", Str("y")), Bind("x", File("1234")), Bind("x", Pkg("1234"))])
|
|
|
|
# bindings alphabetisch gesorteerd
|
|
|
|
|
|
|
|
my %bindings;
|
2003-03-24 13:49:40 +01:00
|
|
|
|
2003-03-20 23:23:48 +01:00
|
|
|
while (<$IN>) {
|
|
|
|
chomp;
|
2003-04-01 16:00:47 +02:00
|
|
|
s/\s*#.*$//;
|
|
|
|
next if (/^$/);
|
2003-03-20 23:23:48 +01:00
|
|
|
|
2003-03-21 15:10:06 +01:00
|
|
|
if (/^(\w+)\s*=\s*([^\#\s]*)\s*(\#.*)?$/) {
|
|
|
|
my ($name, $loc) = ($1, $2);
|
|
|
|
my $file = fetchFile($loc);
|
2003-03-20 23:23:48 +01:00
|
|
|
$file = File::Spec->rel2abs($file, $dir);
|
2003-03-25 12:39:51 +01:00
|
|
|
my $hash = hashFile($file);
|
2003-04-01 16:00:47 +02:00
|
|
|
$bindings{$name} = "File(\"$hash\")";
|
2003-03-20 23:23:48 +01:00
|
|
|
} elsif (/^(\w+)\s*<-\s*([+\w\d\.\/-]+)\s*(\#.*)?$/) {
|
|
|
|
my $name = $1;
|
|
|
|
my $file = $2;
|
|
|
|
$file = File::Spec->rel2abs($file, $dir);
|
|
|
|
$file = convert($file);
|
2003-03-25 12:39:51 +01:00
|
|
|
my $hash = hashFile($file);
|
2003-04-01 16:00:47 +02:00
|
|
|
$bindings{$name} = "Pkg(\"$hash\")";
|
|
|
|
} elsif (/^(\w+)\s*:\s*([+\w\d\.\/-]+)\s*(\#.*)?$/) {
|
|
|
|
my $name = $1;
|
|
|
|
my $value = $2;
|
|
|
|
$bindings{$name} = "Str(\"$value\")";
|
2003-03-20 23:23:48 +01:00
|
|
|
} else {
|
2003-04-01 16:00:47 +02:00
|
|
|
die "syntax error: $_";
|
2003-03-20 23:23:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-03-25 12:39:51 +01:00
|
|
|
close $IN;
|
|
|
|
|
2003-04-01 16:00:47 +02:00
|
|
|
$bindings{"system"} = "Str(\"$system\")";
|
|
|
|
|
|
|
|
open $OUT, "| baffle -wt > $tmpfile" or die "cannot create $tmpfile";
|
|
|
|
print $OUT "Descr([";
|
|
|
|
my $first = 1;
|
|
|
|
foreach my $name (sort (keys %bindings)) {
|
|
|
|
if (!$first) { print $OUT ","; };
|
|
|
|
print $OUT "Bind(\"$name\",$bindings{$name})";
|
|
|
|
$first = 0;
|
|
|
|
}
|
|
|
|
print $OUT "])";
|
|
|
|
close $OUT;
|
|
|
|
|
2003-03-25 12:39:51 +01:00
|
|
|
my $hash = hashFile($tmpfile);
|
|
|
|
|
2003-04-01 16:00:47 +02:00
|
|
|
my $outfile = "$outdir/$fn-$hash";
|
2003-03-25 12:39:51 +01:00
|
|
|
rename($tmpfile, $outfile) or die "cannot rename $tmpfile to $outfile";
|
|
|
|
|
2003-03-20 23:23:48 +01:00
|
|
|
$donetmpls{$descr} = $outfile;
|
|
|
|
return $outfile;
|
2003-03-20 17:52:30 +01:00
|
|
|
}
|
|
|
|
|
2003-03-21 15:10:06 +01:00
|
|
|
for (my $i = 2; $i < scalar @ARGV; $i++) {
|
2003-03-20 23:23:48 +01:00
|
|
|
convert(File::Spec->rel2abs($ARGV[$i]));
|
|
|
|
}
|