<!--
	argos-update-ant.xml : ant build script for  
  argos configuration file updates
-->

<project name="argos-update" default="help" basedir=".." >
	
	<!--===============Properties==============-->

  <property file="argos-update.properties"/>
	<property environment="env"/>
	
  <property name="ARGOS_ROOT"      value="${env.ARGOS_ROOT}"/>
  <property name="ARGOS_SERVICE"   value="flybase"/> <!-- env.ARGOS_SERVICE ..."eugenes" -->
  <property name="ARGOS_INSTALL_SCRIPT"
            value="${ARGOS_ROOT}/install/installargos.pl"/>
  <property name="ARGOS_UPDATE_SCRIPT" 
            value="${ARGOS_ROOT}/ROOT/bin/argoscleaner.pl"/>
  <property name="NG_CONF_LOCAL" value="install.conf.local"/>
  <property name="NG_CONF"       value="install.conf"/>

  <property name="conftop"      value="${ARGOS_ROOT}/ROOT"/>
  <property name="confs"        value="${ARGOS_ROOT}/work/argos-conf"/>   

	<!--=================End of Properties=======================-->

  <!-- PRINT HELP -->
  <target name='help' description="Print help">
  	<echo>
Argos package update ant script.
Available commands:
  update  -  Update Argos server from subtasks: clean, basicupdate, reconfig
    clean        -  Remove obsolete files (compared to distribution files)
    basicupdate  -  Update from distribution packages
    reconfigure  -  Edit distribution config files to use local 
        settings from ${NG_CONF_LOCAL}
  list  -  List updated package files at the server
  help  -  Prints this help
  	</echo>
  </target>
  <!--
  	Options:
  		-DARGOS_ROOT="root installation path"	: Specify the root path for installation
  		-DSERVICE="web-service to install"	: Specify the web-service to install. (FLYBASE, EUGENES, DAPHNIA, CENTAURBASE or GMOD) (default=FLYBASE)
  		You may modify other default parameters in ${NG_CONF_LOCAL} file.
  		
  	Example:
  		ant -DARGOS_ROOT=/var/argos install  		
  -->
  
  <target name='update' depends="verifyScripts"
    description="Update Argos packages">
	<antcall target="reconfigure"/>
	<antcall target="basicupdate"/>
	<antcall target="reconfigure"/>
  </target>
  
  <!-- LIST PACKAGE FILES AT THE SERVER -->
  <target name='list' depends="verifyScripts"
    description="List updated files at the server" >
   <exec executable="perl">
  	<arg line=" ${ARGOS_INSTALL_SCRIPT} -list -update"/>
  </exec>
  </target>
 
 	<target name="reconfigure" depends="verifyScripts" 
	  description="Rewrite Argos config files from distribution and local settings">
	  
	  <!-- change overwrite to true when working ; write to new conf -->
    <!--  want to process all files inside conf/ dirs, 
      and possibly others specified in install/reconfigure.conf
        .. change this last to be list of files to update?
        what of gbrowse.conf/ dirs ?? process contents of all ?
    -->
    <copy toDir="${ARGOS_ROOT}" 
      filtering="true"
      verbose="true" 
      overwrite="false"
      preservelastmodified="true" 
      >
      <fileset dir="${ARGOS_ROOT}" includes="**/*" followsymlinks="false" >
      </fileset>

      <mapper type="glob" from="*-distr" to="*-reconf"/> 
      <!-- mapper type="package" from="*.conf" to="TEST-*.conf"/ -->       
      
      <filterset begintoken="@" endtoken="@">
        <filtersfile file="${ARGOS_ROOT}/install/install.conf"/>
        <filtersfile file="${ARGOS_ROOT}/install/install.conf.local"/>
      </filterset>
    </copy> 
    
  </target>
 
	<target name="reconfigureTest" depends="verifyScripts" 
	  description="Rewrite Argos config files from distribution and local settings">
	  
    <copy toDir="${confs}" 
      verbose="true" 
      overwrite="false"
      preservelastmodified="true" 
      >
    
      <fileset dir="${conftop}" followsymlinks="false" >
        <include name="**/conf/*.conf"/>
          <!-- really want to process all files inside conf/ dirs, 
            and possibly others specified in install/reconfigure.conf
              .. change this last to be list of files to update?
          -->
        <type type="file"/> 
          <!-- what of gbrowse.conf/ dirs ?? process contents of all ?-->
      </fileset>

      <!-- mapper type="glob" from="*.conf-dist" to="*.conf-ed.local"/ --> 
      <mapper type="package" from="*.conf" to="TEST-*.conf"/>       
      
      <filterset begintoken="@" endtoken="@">
        <filtersfile file="${ARGOS_ROOT}/install/install.conf"/>
        <filtersfile file="${ARGOS_ROOT}/install/install.conf.local"/>
      </filterset>
      
    </copy> 
    
  </target>
  
  <!-- PERFORM BASIC UPDATE -->
  <target name='basicupdate'  
    description="Update local argos from remote packages">
   	<exec executable="perl">
  		<arg line="${ARGOS_INSTALL_SCRIPT} -root=${ARGOS_ROOT} -v -update"/>
	</exec>	
  </target>
  
  <!-- sep04, add argoscleaner target -->
  <target name="distfiles">
  	<echo>Calling remote servers for package file list</echo>
   	<exec executable="perl" output="argospackdir.list">
  		<arg line="${ARGOS_INSTALL_SCRIPT} -root=${ARGOS_ROOT} -list -all"/>
	  </exec>	
  </target>

  <target name="clean" depends="verifyScripts, distfiles"
    description="Clean remove obsolete files">
  	<echo>
  	  Removing obsolete Argos package files.
  	  Currently this generates shell script to review then execute as
  	    shell% sh argos-clean.sh
  	</echo>
  	<exec executable="perl" output="argos-clean.sh">
  		<arg line="${ARGOS_UPDATE_SCRIPT} -file=argospackdir.list -type=dir -verbose -exclude=${ARGOS_ROOT}/install/rsync.exclude.local -exclude=${ARGOS_ROOT}/install/rsync.exclude"/>
  	</exec>
  </target>

  <!-- VERIFY IF OTHER SCRIPTS PRESENT -->
  <target name='verifyScripts'>
  <condition property="found.Scripts">
    <and>
      <available file="${ARGOS_ROOT}/install/install.conf.local"/>
      <available file="${ARGOS_ROOT}/install/install.conf"/>
      <available file="${ARGOS_INSTALL_SCRIPT}"/>
      <available file="${ARGOS_UPDATE_SCRIPT}"/>
    </and>
  </condition>
  <fail message="ARGOS scripts not found. Please check if all the scripts are present." 
    unless="found.Scripts"/>
  </target>
  
     
</project>
