#! /bin/csh

# usage startnightly test1 test2 ...


set dir=`dirname $0`
set bdir=`dirname $dir`
set pdir=`dirname $bdir`
set day=`date | cut -f1 -d" "`

foreach CONF ($*)
  set SSH=ssh
  set SCP=scp
  set DASHN=-n
  set MERCURIAL=yes
  source $dir/confignightly/${CONF}

  echo "Starting $CONF build at `date`"
  if ("${MERCURIAL}" == "yes") then
    $SSH $USR@$MACH $DASHN test "\( -d  $LOC \)"
    if ("$?" != "0") then
      if ("$PURL" != "" || "$BURL" != "") then
      echo "$LOC does not exist! Creating clones using $PURL and $BURL"
      $SSH $USR@$MACH $DASHN "hg clone -q $PURL $LOC; hg clone -q $BURL $LOC/config/BuildSystem"
      endif
    endif
    echo "Cleaning and updating clone at $USR@$MACH $LOC"
    $SSH $USR@$MACH $DASHN "cd $LOC ; hg -q revert -a; hg -q pull -u"
  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
