<?xml version="1.0"?>
<project name="Agent install"  default=""  >

	<target name="configureAgent-win" depends="">
		<antcall target="configureAgent" >
			<param name="extension" value="bat" />
		</antcall>
	</target>
	
	<target name="configureAgent-linux" depends="">
		<antcall target="configureAgent" >
			<param name="extension" value="sh" />
		</antcall>
		<chmod perm="ugo+x" file="${basedir}/../agent/bin/linux-ix86/Attribute" />
		<chmod perm="ugo+x" file="${basedir}/../agent/bin/linux-ix86/Event" />
		<chmod perm="ugo+x" file="${basedir}/../agent/bin/linux-ix86/EventScanner" />
		<chmod perm="ugo+x" file="${basedir}/../agent/bin/linux-ix86/gethostname" />
		<chmod perm="ugo+x" file="${basedir}/../agent/bin/linux-ix86/Topology" />
	</target>

	<target name="configureAgent" depends="" >
		<antcall target="updateDataAgentConfig" />
		<antcall target="updateFabricAgentConfig" />
		<antcall target="updateLaunchScript" >
			<param name="extension" value="${extension}" />
			<param name="maxHeap" value="${agent.heap}" />
		</antcall>
	</target>
	
	<target name="updateDataAgentConfig" depends="" >
		<echo message="Updating the properties file: ${basedir}/../agent/configuration/agent.config" level="info" />
		<copy tofile="${basedir}/../agent/configuration/agent.config" file="${basedir}/templates/agent/configuration/agent.config" overwrite="true" />
		<replace file="${basedir}/../agent/configuration/agent.config" token="@server_hostname@" value="${server.hostname}" />
		<replace file="${basedir}/../agent/configuration/agent.config" token="@server_port@" value="${server.data.port}" />
		<replace file="${basedir}/../agent/configuration/agent.config" token="@port@" value="${agent.port}" />
		<replace file="${basedir}/../agent/configuration/agent.config" token="@base_dir@" value="${basedir}/../agent" />
	</target>

	<target name="updateFabricAgentConfig" depends="" >
		<echo message="Updating the properties file: ${basedir}/../agent/configuration/setup.properties" level="info" />
		<copy tofile="${basedir}/../agent/configuration/setup.properties" file="${basedir}/templates/agent/configuration/setup.properties" overwrite="true" />
		<replace file="${basedir}/../agent/configuration/setup.properties" token="@server_hostname@" value="${server.hostname}" />
		<replace file="${basedir}/../agent/configuration/setup.properties" token="@server_port@" value="${server.device.port}" />
		<replace file="${basedir}/../agent/configuration/setup.properties" token="@port@" value="${agent.port}" />
		<replace file="${basedir}/../agent/configuration/setup.properties" token="@base_dir@" value="${basedir}/../agent" />
	</target>

	<target name="updateLaunchScript" depends="" >
		<echo message="Updating the file: ${basedir}/agent/agent.${extension}" level="info" />
		<copy tofile="${basedir}/../agent/agent.${extension}" file="${basedir}/templates/agent/agent.${extension}" overwrite="true" />
		<replace file="${basedir}/../agent/agent.${extension}" token="@base_dir@" value="${basedir}" />
		<replace file="${basedir}/../agent/agent.${extension}" token="@java_home@" value="${java.home}" />
		<replace file="${basedir}/../agent/agent.${extension}" token="@max_heap@" value="${maxHeap}" />
		<replace file="${basedir}/../agent/agent.${extension}" token="@port@" value="${agent.port}" />

		<chmod perm="ugo+x" file="${basedir}/../agent/agent.${extension}" />
	</target>
	
</project>