#! /bin/csh
#
# usage startnightly test1 test2 test3:maint test4:next ...
#
set dir=`dirname $0`
set bdir=`dirname $dir`
set pdir=`dirname $bdir`
set day=`date | cut -f1 -d" "`

foreach TEST ($*)
  source $dir/confignightly/default
  source $dir/confignightly/${TNAME}

  echo "Starting $TEST : $CONF build at `date`"
  if ("${GIT}" == "yes") then
    $SSH $USR@$MACH $DASHN test "\( -d  $LOC \)"
    if ("$?" != "0") then
      if ("$URL" != "") then
      echo "$LOC does not exist! Creating clone using $URL"
      $SSH $USR@$MACH $DASHN "git clone -q $URL $LOC"
      endif
    endif
    echo "Cleaning and updating clone at $USR@$MACH $LOC"
    $SSH $USR@$MACH $DASHN "cd $LOC ; git fetch -q origin; git checkout -f origin/${BRANCH} "
  else
    rsync -e ssh -az --delete  $pdir/ ${USR}@${MACH}:${LOC}
  endif
  echo "Starting: $SSH $USR@$MACH $DASHN $LOC/bin/maint/buildtest $CONF"
  $SSH $USR@$MACH $DASHN "cd $LOC; $LOC/bin/maint/buildtest $CONF" &
  sleep 120 # perhaps ease the nfs load
end
wait
