#!/usr/bin/perl
#
# This script reads all the AGENT_* variables from your environment,
# strips the AGENT_ from the name, and prints them out in a format
# suitable for tacking onto the java command line.  This adds these
# variables to the properties list of the agent.  Since JAF gives
# precedence to properties over items in the config file, using
# this script gives you an easy way to override parameters specified
# in the (relatively static) config file, but just setting an
# environment variable.
#
# Bryan Horling - April 2001
# ########################################################################

# Get the parameters
while ($_ = shift(@ARGV)) {
	if (/-l/) {
		$LIST = 1;
	} else {
		print "usage: makeagentenv [-l]\n";
		exit;
	}
}

# Get the env args
foreach $KEY (keys %ENV) {
	if ($KEY =~ /^AGENT_/i) {
		$TEMP = $KEY;
		$TEMP =~ s/^AGENT_//i;
		$ARGS{$TEMP} = $ENV{$KEY};
	}
}

if ($LIST) {
	foreach $KEY (keys %ARGS) {
		print "$KEY:$ARGS{$KEY}\n";
	}
	exit;
}

# Construct the arg string
foreach $KEY (keys %ARGS) {
	$ARGS .= " -D" . $KEY . "=\"" . $ARGS{$KEY} . "\"";
}

print $ARGS;
