#!/bin/bash
ip_last=$1
project_name=$2
branch_name=$3
project_type=$4
public_ip=$5
apollo_idc=$6
pwd_path_0="/home/qa-deploy-utils"
set timeout 1200
ip_host=`sh $pwd_path_0/get-ip.sh $ip_last`
echo "参数为：
#init_shell_script: ${init_shell_script}
ip : ${ip_host}
project_name : ${project_name}
branch_name : ${branch_name}
project_type : ${project_type}
public_ip : ${public_ip}
apollo_idc : ${apollo_idc}
"

if [ -n "$project_name"  ] && [  -n "$branch_name" ]; then
	expect -c "
		 set timeout 10
	   spawn ssh root@${ip_host}
		 expect \"]#\"
		 send \"cd /home/qa-deploy-utils/qa_shell_script\r\"
		 expect \"]#\"
		 send \"sh deploy_project_by_name.sh $project_name $branch_name $public_ip ${ip_host} ${apollo_idc}\r\"
		 set timeout -1
	   expect \"]#\"
	   send \"exit\r\"
	expect eof;"
else
	expect -c "
		 set timeout 10
	   spawn ssh root@${ip_host}
		 expect \"]#\"
		 send \"cd /home/qa-deploy-utils/qa_shell_script\r\"
	   expect \"]#\"
		 send \"sh deploy_project_by_type.sh $project_type $branch_name $public_ip ${ip_host}\r\"
	     set timeout -1
	   expect \"]#\"
	   send \"exit\r\"
	expect eof;"
fi

