#!/bin/bash

BIN_DIR=`dirname $0`
BIN_DIR=`cd "$BIN_DIR"; pwd`
DBAPI_HOME=`cd "$BIN_DIR/.."; pwd`

cd $DBAPI_HOME
parentDir=$(dirname $(pwd))

source $DBAPI_HOME/conf/install_config.conf

hosts=(${ips//,/ })

file=$1
shift
if [ -n "$file" ]; then
  # copy single file
  parent_dir=$(dirname "$DBAPI_HOME/$file")
  for host in ${hosts[@]}
  do
    echo "copy $DBAPI_HOME/$file to $host:$parent_dir ..."
    ssh -p $sshPort $host "mkdir -p $parent_dir "
    scp -q -P $sshPort -r $DBAPI_HOME/$file $host:$parent_dir
  done
else
  # copy dir
  for host in ${hosts[@]}
  do
    echo "copy $DBAPI_HOME to $host:$parentDir ..."
    ssh -p $sshPort $host "mkdir -p $parentDir "
    scp -q -P $sshPort -r $DBAPI_HOME $host:$parentDir
  done
fi

echo "success"
