#!/usr/bin/bash
# Usage . makeWorker.sh name
# Source this to get the worker name set to its IP address
name=$1
ip=$(az vm list-ip-addresses -g cc -n $name|egrep -o '"ipAddress": ".*"' | cut -f 2 -d ' ' | tr -d \")
export $name=$ip
echo $name=$ip
ssh -o StrictHostKeyChecking=no $ip <cat /var/cc/workers/bin/setupTemplate.sh
sudo bash -c "cd ~cc/.ssh && tar -czf - authorized_keys id_rsa id_rsa.pub" | \
 ssh $ip "sudo su -c 'cd ~/.ssh && tar -xzf -' cd"

