#! /bin/csh
# 
#
set LOC=$PETSC_DIR
set CONF=$1
set SSH=ssh
set SCP=scp
set DASHN=-n
set day=`date | cut -f1 -d" "`
if ( -f ${PETSC_DIR}/bin/maint/confignightly/${CONF} ) then
 
else
  set machines=`grep CONF ${PETSC_DIR}/bin/maint/confignightly/* | grep -i ${CONF} | sed "s?:? ?g" | sed "s?=? ?g" | cut -d" " -f1`
  set arches=`grep CONF ${PETSC_DIR}/bin/maint/confignightly/* | grep -i ${CONF} | sed "s?:? ?g" | sed "s?=? ?g" | cut -d" " -f4`
  if ( ${#machines} == 1 ) then
    set CONF = `basename ${machines[1]}`
  else if ( ${#machines} == 0 ) then
    echo "No machines with this property"
    exit
  else
    set i=1
    while ( $i <= ${#machines} ) 
      echo $i `basename ${machines[$i]}` ${arches[$i]}
      @ i=$i + 1
    end
    set choice=$<
    set CONF = `basename ${machines[$choice]}`    
  endif
endif

source ${PETSC_DIR}/bin/maint/confignightly/${CONF}

echo "****************** Connecting to $USR@$MACH in $LOC  ************************************"
ssh -A -X -t petsc@login.mcs.anl.gov $SSH -t -A -X $USR@$MACH  ${LOC}/bin/maint/runremote $LOC $CONF $USER
echo "**************Ending connection to $USR@$MACH in $LOC  **********************************"

#$SSH barrysmith@localhost ssh barrysmith@localhost $USR@$MACH $DASHN "cd $LOC ; bk pull; $LOC/bin/maint/buildtest $CONF" &

