setup.sh 9.73 KB
# 文件名:	setup.sh
# 作者 	: 	石晓旭
# 功能  :	对freeswitch服务器进行自动部署。
# 流程 	:	1、获取配置
#		2、安装nfs 客户端。录音存储使用。
#		3、安装tserver
#		4、安装ucswitch
#		5、优化ucswitch
#		6、修改主机名
#		7、修改hosts
#/bin/bash

################################ 公用变量 ##################################
export autoDirectory=`pwd`
export ucswitchDirectory="${autoDirectory}/ucswitch"
export ucswitchSetupLogFile="${autoDirectory}/install.log"

setupConfig="config.ini"
nfsMod="ucswitchNFS"
recordMod="ucswitchRecord"
redisMod="ucswitchRedis"
cdrMod="ucswitchCdr"
dependsMod="ucswitchDepends"
gitMod="ucswitchGit"
coreMod="ucswitchCore"
tserverMod="TServer"
################################ 公用接口 ##################################
iniTmpFieldValue="nil"
function iniGetFieldValue()  
{
	if [ ! -f $1 ] || [ $# -ne 3 ];then  
		echo "[`date`] [ERROR] iniGetFieldValue Param." >> ${ucswitchSetupLogFile}
        	return 1 
    	fi
	echo "[`date`] [DEBUG] iniGetFieldValue $1 $2 $3." >> ${ucswitchSetupLogFile}
	nRet=1	
	bFindBlockBegin=0
	bFindBlockEnd=0
#	cat $1 | while read line
	while read line
	do
		#判断块开始
		if [ "[$2]" == "${line}" ];then
			echo "[`date`] [DEBUG] iniGetFieldValue $1 $2 Begin" >> ${ucswitchSetupLogFile}
			bFindBlockBegin=1
			continue
		fi
		if [ ${bFindBlockBegin} -eq 1 ];then
			#判断块结束,块结束后退出。
			if [[ "${line}" =~ "[" ]] && [[ "${line}" =~ "]" ]];then
				bFindBlockEnd=1
				echo "[`date`] [DEBUG] iniGetFieldValue $1 $2 End" >> ${ucswitchSetupLogFile}
				break
			fi
			#块内获取值
			if [ ${bFindBlockBegin} -eq 1 ] && [ ${bFindBlockEnd} -eq 0 ];then
				field=$(echo $line | awk -F= '{gsub(" |\t","",$1); print $1}')  
            			value=$(echo ${line#*=})
            			#value=$(echo $line | awk -F= '{gsub(" |\t","",$2); print $2}') 
				if [ "${field}" == "$3" ];then
					iniTmpFieldValue=${value}
					echo "[`date`] [DEBUG] iniGetFieldValue $1 $2 $3 exist." >> ${ucswitchSetupLogFile}
					return 0 
				fi
				iniTmpFieldValue="nil"
			fi
		fi
	done <<< "$(cat $1)"
#	done 
	echo "[`date`] [ERROR] iniGetFieldValue $1 $2 $3 not exist." >> ${ucswitchSetupLogFile}
	return 1
}   
################################ 配置变量 ##################################
echo "[`date`] [DEBUG] setup.sh start..." >> ${ucswitchSetupLogFile}
# NFS #i
iniGetFieldValue ${setupConfig} ${nfsMod} "nfsType"
if [ $? -ne 0 ];then
	exit 1
fi
export nfsType=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${nfsMod} "nfsOptions"
if [ $? -ne 0 ];then
	exit 1
fi
export nfsOptions=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${nfsMod} "nfsDevice"
if [ $? -ne 0 ];then
	exit 1
fi
export nfsDevice=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${nfsMod} "nfsServerDirectory"
if [ $? -ne 0 ];then
	exit 1
fi
export nfsServerDirectory=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${nfsMod} "nfsReadSize"
if [ $? -ne 0 ];then
	exit 1
fi
export nfsReadSize=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${nfsMod} "nfsWriteSize"
if [ $? -ne 0 ];then
	exit 1
fi
export nfsWriteSize=${iniTmpFieldValue}
# record #
iniGetFieldValue ${setupConfig} ${recordMod} "recordMemoryPath"
if [ $? -ne 0 ];then
	exit 1
fi
export recordMemoryPath=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${recordMod} "recordDiskPath"
if [ $? -ne 0 ];then
	exit 1
fi
export recordDiskPath=${iniTmpFieldValue}
# redis #
iniGetFieldValue ${setupConfig} ${redisMod} "redisServer"
if [ $? -ne 0 ];then
	exit 1
fi
export redisServer=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${redisMod} "redisPort"
if [ $? -ne 0 ];then
	exit 1
fi
export redisPort=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${redisMod} "redisPassword"
if [ $? -ne 0 ];then
	exit 1
fi
export redisPassword=${iniTmpFieldValue}
# cdrs #
iniGetFieldValue ${setupConfig} ${cdrMod} "cdrUrl"
if [ $? -ne 0 ];then
	exit 1
fi
export cdrUrl=${iniTmpFieldValue}
# depends #
iniGetFieldValue ${setupConfig} ${dependsMod} "DependUrl"
if [ $? -ne 0 ];then
	exit 1
fi
export dependsUrl=${iniTmpFieldValue}
# git #
iniGetFieldValue ${setupConfig} ${gitMod} "gitUser"
if [ $? -ne 0 ];then
	exit 1
fi
export gitUser=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${gitMod} "gitPassword"
if [ $? -ne 0 ];then
	exit 1
fi
export gitPassword=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${gitMod} "gitUrl"
if [ $? -ne 0 ];then
	exit 1
fi
export gitUrl=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${gitMod} "gitBranch"
if [ $? -ne 0 ];then
	exit 1
fi
export gitBranch=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${coreMod} "ucswitchName"
if [ $? -ne 0 ];then
	exit 1
fi
export ucswitchName=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${coreMod} "ucswitchIp"
if [ $? -ne 0 ];then
	exit 1
fi
export ucswitchIp=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${coreMod} "ucswitchDbPort"
if [ $? -ne 0 ];then
	exit 1
fi
export ucswitchDbPort=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${coreMod} "ucswitchDbIp"
if [ $? -ne 0 ];then
	exit 1
fi
export ucswitchDbIp=${iniTmpFieldValue}
#tserver
iniGetFieldValue ${setupConfig} ${tserverMod} "jarUrl"
if [ $? -ne 0 ];then
        exit 1
fi
export jarUrl=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${tserverMod} "jarPath"
if [ $? -ne 0 ];then
        exit 1
fi
export jarPath=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${tserverMod} "jarName"
if [ $? -ne 0 ];then
        exit 1
fi
export jarName=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${tserverMod} "jingle.cc.activemq.url"
if [ $? -ne 0 ];then
        exit 1
fi
export jarQueueUrl=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${tserverMod} "freeswitch.ip"
if [ $? -ne 0 ];then
        exit 1
fi
export jarFsIp=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${tserverMod} "jingle.cc.fs.consumer"
if [ $? -ne 0 ];then
        exit 1
fi
export jarFsConsumer=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${tserverMod} "spring.datasource.url"
if [ $? -ne 0 ];then
        exit 1
fi
export jarDbUrl=${iniTmpFieldValue}
iniGetFieldValue ${setupConfig} ${tserverMod} "spring.redis.host"
if [ $? -ne 0 ];then
        exit 1
fi
export jarRedisHost=${iniTmpFieldValue}


echo "[`date`] [DEBUG] setup.sh jarUrl $jarUrl" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh jarPath $jarPath" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh jarName $jarName" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh jarQueueUrl $jarQueueUrl" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh jarFsIp $jarFsIp" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh jarFsConsumer $jarFsConsumer" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh jarDbUrl $jarDbUrl" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh jarRedisHost $jarRedisHost" >> ${ucswitchSetupLogFile}

echo "[`date`] [DEBUG] setup.sh ucswitchName $ucswitchName" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh ucswitchIp $ucswitchIp" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh ucswitchDbIp $ucswitchDbIp" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh ucswitchDbPort $ucswitchDbPort" >> ${ucswitchSetupLogFile}

echo "[`date`] [DEBUG] setup.sh nfsType $nfsType" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh nfsOptions $nfsOptions" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh nfsReadSize $nfsReadSize" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh nfsWriteSize $nfsWriteSize" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh nfsDevice $nfsDevice" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh nfsServerDirectory $nfsServerDirectory" >> ${ucswitchSetupLogFile}

echo "[`date`] [DEBUG] setup.sh recordMemoryPath $recordMemoryPath" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh recordDiskPath $recordDiskPath" >> ${ucswitchSetupLogFile}

echo "[`date`] [DEBUG] setup.sh redisServer $redisServer" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh redisPort $redisPort" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh redisPassword $redisPassword" >> ${ucswitchSetupLogFile}

echo "[`date`] [DEBUG] setup.sh cdrUrl $cdrUrl" >> ${ucswitchSetupLogFile}

echo "[`date`] [DEBUG] setup.sh dependsUrl $dependsUrl" >> ${ucswitchSetupLogFile}


echo "[`date`] [DEBUG] setup.sh gitUrl $gitUrl" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh gitBranch $gitBranch" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh gitUser $gitUser" >> ${ucswitchSetupLogFile}
echo "[`date`] [DEBUG] setup.sh gitPassword $gitPassword" >> ${ucswitchSetupLogFile}
################################ 安装流程 ##################################
d='
${autoDirectory}/nfsSetup.sh
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] setup.sh nfsClient install and config success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] setup.sh Failed to install nfsClient or config" >> ${ucswitchSetupLogFile}
	exit 1
fi

${autoDirectory}/ucswitchSetup.sh
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] setup.sh ucswitch install and config success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] setup.sh Failed to install ucswitch or config" >> ${ucswitchSetupLogFile}
	exit 1
fi
${autoDirectory}/autoStart.sh
if [ $? -eq 0 ];then
        echo "[`date`] [DEBUG] setup.sh auto start success" >> ${ucswitchSetupLogFile}
else
        echo "[`date`] [ERROR] setup.sh Failed to auto start" >> ${ucswitchSetupLogFile}
        exit 1
fi'
${autoDirectory}/tserverSetup.sh
if [ $? -eq 0 ];then
        echo "[`date`] [DEBUG] setup.sh tserverSetup success" >> ${ucswitchSetupLogFile}
else
        echo "[`date`] [ERROR] setup.sh Failed to tserverSetup" >> ${ucswitchSetupLogFile}
        exit 1
fi
################################ 安装结束 ##################################
echo "[`date`] [DEBUG] setup.sh finished..." >> ${ucswitchSetupLogFile}