#!/bin/sh

BASEDIR=$(cd $(dirname "${BASH_SOURCE[0]}")/.. && pwd)
SSH_KEY=${BASEDIR}/$(ls ${BASEDIR} | egrep '.pem$' | head -n 1)

if [ $# -ne 2 ]; then
  echo "Copy file to all hosts"
  echo "Usage: $0 <source> <target>"
  exit 1
fi

for host in $(cat ${BASEDIR}/hosts | grep -v "^#" | awk '{print $1}')
do
  if ifconfig | grep inet | grep "${host}" >/dev/null ; then
    # skip current host
    continue
  fi

  #scp -i ${SSH_KEY} -r $1 ${host}:$2
  scp -r $1 ${host}:$2
done
