#!/bin/bash
target_ip=$1
pwd_path_0="/home/qa-deploy-utils"
target_db_host=`sh $pwd_path/get-ip.sh $ip_value`
config_files=/home/config_files
script_path=/home/qa-deploy-utils/qa_shell_script
pwd_path="/home/qa-deploy-utils/qa_shell_script"
config_server="$pwd_path/config_server"
project_path=`cat $config_server/get_env_ip.sh`

if [[ $target_ip == "ALL" ]]; then
	for ip_last_num in  $project_path
	do
			IP_host=`sh $pwd_path_0/get-ip.sh $ip_last_num`
			expect -c "
			set timeout 10
			spawn ssh root@${IP_host}
			expect \"]#\"
			send \"umount -l $script_path\\ \r\"
			set timeout -1
			expect \"]#\"
			send \"rm -rf $script_path\r\"
			set timeout -1
			expect \"]#\"
			send \"mkdir -p $script_path\r\"
			set timeout -1
			expect \"]#\"
			send \"mount -t nfs 192.168.4.3:$script_path $script_path\r\"
			set timeout -1
			expect \"]#\"
			send \"umount -l $config_files\\ \r\"
			set timeout -1
			expect \"]#\"
			send \"rm -rf $config_files\r\"
			set timeout -1
			expect \"]#\"
			send \"mkdir $config_files\r\"
			set timeout -1
			expect \"]#\"
			send \"mount -t nfs 192.168.4.3:/home/sub_config_file_dont_rm/${IP_host}/ $config_files\r\"
			set timeout -1
			expect \"]#\"
			send \"exit\r\"
			expect eof;"
		done
else
	target_host=`sh $pwd_path_0/get-ip.sh $target_ip`
	expect -c "
		set timeout 10
		spawn ssh root@${target_host}
		expect \"]#\"
		send \"umount -l /home/qa-deploy-utils/qa_shell_script\r\"
		expect \"]#\"
		send \"mkdir -p /home/qa-deploy-utils/qa_shell_script\r\"
		set timeout -1
		expect \"]#\"
		send \"mount -t nfs 192.168.4.3:/home/qa-deploy-utils/qa_shell_script /home/qa-deploy-utils/qa_shell_script\r\"
		set timeout -1
		expect \"]#\"
		send \"umount -l $config_files\r\"
		set timeout -1
		expect \"]#\"
		send \"rm -rf $config_files\r\"
		set timeout -1
		expect \"]#\"
		send \"mkdir $config_files\r\"
		set timeout -1
		expect \"]#\"
		send \"mount -t nfs 192.168.4.3:/home/sub_config_file_dont_rm/${target_host}/ $config_files\r\"
		set timeout -1
		expect \"]#\"
		send \"exit\r\"
	expect eof;"
fi
