#!/usr/bin/env ruby

`cat $OAR_NODEFILE > nodes`
groups = [1,2,4,8,16,32,64,128]


groups.each do |group|
  `rm -f ../config/sophia#{group}.yml`
end
machines = []

File.open("nodes").each do |line|
  if line =~ /([\w|\-|\d]+).sophia.grid5000.fr/ 
    if not machines.member?($1)
      machines << $1
    end
  else
    puts line
  end
end

groups.each do |group|
  File.open("../config/sophia#{group}.yml",'w') do |file|	
    file.puts "---"
    (0...group).each do |unit|
      file.puts "#{machines[unit]}:"
      file.puts "  installgrm: true"
      file.puts "  installlrm: true"
      file.puts "  grm: #{machines.first}"
      file.puts "  path: /tmp/ig/ "
      file.puts "  java: /home/grenoble/agoldman/fabsn/jdk1.6.0_10/\n\n"
    end
  end
end

