#!/bin/bash
ip_last=$1
project_name=$2
branch_name=$3
project_type=$4
public_ip=$5
set timeout 1200
ip=192.168.4.$ip_last
echo "参数为：
#init_shell_script: ${init_shell_script}
ip : ${ip}
project_name : ${project_name}
branch_name : ${branch_name}
project_type : ${project_type}
public_ip : ${public_ip}
"

if [ -n "$project_name"  ] && [  -n "$branch_name" ]; then
	expect -c "
		 set timeout 10
	   spawn ssh root@${ip}
		 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\r\"
		 set timeout -1
	   expect \"]#\"
	   send \"exit\r\"
	expect eof;"
else
	expect -c "
		 set timeout 10
	   spawn ssh root@${ip}
		 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\r\"
	     set timeout -1
	   expect \"]#\"
	   send \"exit\r\"
	expect eof;"
fi

