################################################
#INPUT ARGS
#-l NODEFILE: list of p2p peer nodes
#-s BOOTFILE: list of servers
#-suffix <suffix>: suffix used in config filename
#-failed <failed list>; list of nodes which are down
#################################################


NODEFILE=""
BOOTFILE=""
SUFFIX=""
FAILED=""
while [ $# -ge 1 ]; 
do
   case $1 in

     -l)   shift ; NODEFILE="$1";;
     -s)   shift ; BOOTFILE="$1";;
     -suffix) shift; SUFFIX="$1";;	
     -failed) shift; FAILED="$1";;
   esac

   shift
done 

TARGETDIR="~/p2p_gaurav"
EXECTBLE="${TARGETDIR}/p2pmain"

#read bootstrap server list file

if [ -z $BOOTFILE ];then
   echo "No server"
else

exec 3<&0
exec 0<$BOOTFILE

read line
echo $line
log_file="${TARGETDIR}/bootstrap${SUFFIX}.log"
config_file="${TARGETDIR}/bootconfig${SUFFIX}.cfg"
ssh  -i planet_rsa -fX columbia_salman@${line} "${EXECTBLE} ${config_file} ${log_file} > /dev/null"  < /dev/null 

fi

#read site-list file
if [ -z $NODEFILE ];then
   exit 1;
else
exec 3<&0
exec 0<$NODEFILE

while read line
do
  if [ ! -z $FAILED];then
   grep $line $FAILED
   retval=$?;
   if [ $retval == 0 ];then
	echo "ignore $line"
	continue;
   fi
  fi

   echo $line
   log_file="${TARGETDIR}/${line}${SUFFIX}.log"
   config_file="${TARGETDIR}/${line}${SUFFIX}.cfg"
   ssh  -i planet_rsa -fX columbia_salman@${line} "${EXECTBLE} ${config_file} ${log_file} > /dev/null"  < /dev/null 
done

fi



