<?xml version="1.0"?>
<project name="Aperi Device Server Installer"  default=""  >
	<taskdef name="createDevicePwd" classname="org.eclipse.aperi.install.CreateDeviceServerPassword"/>

	<target name="configureDeviceServer" depends="" >
		<echo message="Configuring the Device Server" level="info" />
		
		<!-- Update Device Server Configuration -->
		<antcall target="updateDeviceServerConfig"/>
				
		<!-- Update Device Server Launch Script -->
		<antcall target="updateDeviceServerLaunchScript">
			<param name="extension" value="${extension}"/>
		</antcall>
	</target>
	
	<target name="updateDeviceServerConfig" depends="">
		<echo>"Updating the properties file: ${basedir}/../devsvr/configuration/setup.properties</echo>
		<copy tofile="${basedir}/../devsvr/configuration/setup.properties" file="${basedir}/templates/devsvr/configuration/setup.properties" overwrite="true"/>
		<replace file="${basedir}/../devsvr/configuration/setup.properties" token="[MANAGER]" value="${server.hostname}" />
		<replace file="${basedir}/../devsvr/configuration/setup.properties" token="[MGR_PORT]" value="${server.device.port}" />
		<replace file="${basedir}/../devsvr/configuration/setup.properties" token="[AGENT_PORT]" value="${agent.port}" />
		<replace file="${basedir}/../devsvr/configuration/setup.properties" token="[TSNMTYPE]" value="manager" />
		<replace file="${basedir}/../devsvr/configuration/setup.properties" token="[INSTALL_LOCATION]" value="${basedir}/.." />
		<createDevicePwd fileName="${basedir}/../devsvr/configuration/setup.properties" token="[HOST_AUTHENTICATION_PASSWORD]" password="${server.install.password}"/> 

		<echo>"Updating the properties file: ${basedir}/../devsvr/configuration/tsnmdbparms.properties</echo>
		<copy tofile="${basedir}/../devsvr/configuration/tsnmdbparms.properties" file="${basedir}/templates/devsvr/configuration/tsnmdbparms.properties" overwrite="true"/>
		<replace file="${basedir}/../devsvr/configuration/tsnmdbparms.properties" token="@jdbc_url@" value="jdbc:${db.type}://${db.hostname}:${db.port}/${db.schema}" />
		<replace file="${basedir}/../devsvr/configuration/tsnmdbparms.properties" token="@jdbc_driver@" value="${db.driver}" />
		<replace file="${basedir}/../devsvr/configuration/tsnmdbparms.properties" token="@schema@" value="${db.schema}" />
		<replace file="${basedir}/../devsvr/configuration/tsnmdbparms.properties" token="@db_user@" value="${db.username}" />
		<createDevicePwd fileName="${basedir}/../devsvr/configuration/tsnmdbparms.properties" token="@db_pwd@" password="${db.password}"/> 		
	</target>

	<target name="updateDeviceServerLaunchScript" depends="" >
		<echo>"Updating the file: ${basedir}/devsvr/devsvr${extension}</echo>
		<copy tofile="${basedir}/../devsvr/devsvr.${extension}" file="${basedir}/templates/devsvr/devsvr.${extension}" overwrite="true"/>
		<replace file="${basedir}/../devsvr/devsvr.${extension}" token="@base_dir@" value="${basedir}" />
		<replace file="${basedir}/../devsvr/devsvr.${extension}" token="@java_home@" value="${java.home}" />
		<replace file="${basedir}/../devsvr/devsvr.${extension}" token="@max_heap@" value="${server.data.heap}" />
		<replace file="${basedir}/../devsvr/devsvr.${extension}" token="@server_port@" value="${server.device.port}" />

		<echo>"Updating permissions"</echo>
		<chmod perm="ugo+x" file="${basedir}/../devsvr/devsvr.${extension}" />
	</target>
</project>
