#!/usr/bin/perl -w
# Get specific value from the repository.
# Written by: Erez Strauss <erezs@voltaire.com>.

die ("usage: rep-get key field.") if @ARGV != 2;
$key=$ARGV[0];
$field=$ARGV[1];

open (R, "</usr/voltaire/config/repository.rps") or die "no repository.";

my $found = 0;

while (<R>)
{
        $found = 1, next if m,^\[voltaire/$key/\],;

        exit (1) if $found && /^\s*\[.*\]/;

        if ( $found && /"$field"\s*=\s*"?([^"]+)"?/i ) {
		my $x;
		chomp ($x = $1);
        	print "$x\n";
		exit (0);
	}
}
exit (1);
