#!/bin/bash
default_image="orbit-parallel"

# Set up pxe links on repository2 for pxe boot

echo "$1" > node

node_x=`cut -f1 -d',' node`

node_y=`cut -f2 -d',' node`

node_id="node"$node_x"-"$node_y

#echo " Node ID is $node_id"

#echo " X coordinate of node is $node_x, Y co-ordinate of node is $node_y"

#echo " my console is `hostname -d | cut -f1 -d'.'` "



sub=`/sbin/ifconfig eth1 | grep 'inet addr' | cut -c21-26`

subnet_ip=$sub$node_x"."$node_y


echo "My subnet number is $subnet_ip"

#echo "The nodes given are $1"

wget -O - "http://pxe:5012/pxe/setBootImage?img=$default_image&node=$node_id&ip=$subnet_ip"

# Reset the selected nodes using cmc service

wget -O - "http://cmc:5012/cmc/on?x=$node_x&y=$node_y"

wget -O - "http://cmc:5012/cmc/reset?x=$node_x&y=$node_y"

sleep 120

# Launch the frisbee server

wget -O - "http://frisbee:5012/frisbee/getAddress?img=$2"  > PORT

port=`cut -c 11-15 PORT`

wget -O - "http://pxe:5012/pxe/clearBootImage?node=$node_id&ip=$subnet_ip"


#sleep 180

export GEXEC_SVRS="$node_id"

export LD_ASSUME_KERNEL="2.4.2"

cd /etc

gexec -n 0 frisbee -p $port -m 224.0.0.2 -i $subnet_ip /dev/hda

wget -O - "http://cmc:5012/cmc/reset?x=$node_x&y=$node_y"
