ucswitchSetup.sh 7.65 KB
# 作者:石晓旭
#!/bin/bash
echo "[`date`] [DEBUG] #############################  ucswitchSetup.sh start  ##########################" >> ${ucswitchSetupLogFile}
#安装git
bGitNotInstall=`rpm -qa | grep git- | wc -l`
if [ ${bGitNotInstall} -eq 0 ];then
	yum -y install git
	if [ $? -eq 0 ];then
		echo "[`date`] [DEBUG] ucswitchSetup.sh install git success" >> ${ucswitchSetupLogFile}
	else
		echo "[`date`] [ERROR] ucswitchSetup.sh Failed to install git" >> ${ucswitchSetupLogFile}
		exit 1	
	fi
else
	echo "[`date`] [DEBUG] ucswitchSetup.sh install git already exits" >> ${ucswitchSetupLogFile}
fi
#下载ucswitch代码
if [ ! -d ${ucswitchDirectory} ];then
	git clone -b "${gitBranch}" "http://${gitUser}:${gitPassword}@${gitUrl}"
	if [ $? -eq 0 ];then
		echo "[`date`] [DEBUG] ucswitchSetup.sh git clone ucswitch success" >> ${ucswitchSetupLogFile}
	else
		echo "[`date`] [ERROR] ucswitchSetup.sh Failed to git clone ucswitch" >> ${ucswitchSetupLogFile}
	fi
else
	echo "[`date`] [DEBUG] ucswitchSetup.sh git clone ucswitch already exits" >> ${ucswitchSetupLogFile}
fi
#安装依赖
cd ${ucswitchDirectory} cd && ./depends_install.sh "${ucswitchDirectory}" "${ucswitchSetupLogFile}" "${dependsUrl}/libs/"
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh depends_install success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to depends_install" >> ${ucswitchSetupLogFile}
fi
#hiredis 打个补丁,否者fs无法识别他安装了。
if [ ! -d "/usr/local/lib/pkgconfig" ];then
	mkdir -p "/usr/local/lib/pkgconfig"
fi
if [ ! -f "/usr/local/lib/pkgconfig/hiredis.pc" ];then
	cp -f ${autoDirectory}/hiredis.pc /usr/local/lib/pkgconfig/hiredis.pc	
fi
echo "/usr/local/lib" > /etc/ld.so.conf.d/hiredis-x86_64.conf
/sbin/ldconfig
#编译代码
cd ${ucswitchDirectory} && ./bootstrap.sh -j
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh bootstrap.sh success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to bootstrap.sh" >> ${ucswitchSetupLogFile}
	exit 1
fi
cd ${ucswitchDirectory} && ./configure.sh "${ucswitchDirectory}" "${ucswitchSetupLogFile}"
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh configure.sh success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to configure.sh" >> ${ucswitchSetupLogFile}
	exit 1
fi
cd ${ucswitchDirectory} && make && make install
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh install ucswitch success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to install ucswitch" >> ${ucswitchSetupLogFile}
	exit 1
fi
#替换配置
if [ ! -d "/usr/local/freeswitch" ];then
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to replace scripts and config" >> ${ucswitchSetupLogFile}
	exit 1
fi
cp -rf "${ucswitchDirectory}/uswitch_patch/scripts" "/usr/local/freeswitch"
if [ $? -ne 0 ];then
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to cp scripts" >> ${ucswitchSetupLogFile}
	exit 1
else
	echo "[`date`] [DEBUG] ucswitchSetup.sh cp scripts" >> ${ucswitchSetupLogFile}
fi
cp -rf "${ucswitchDirectory}/uswitch_patch/conf" "/usr/local/freeswitch"
if [ $? -ne 0 ];then
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to cp conf" >> ${ucswitchSetupLogFile}
	exit 1
else
	echo "[`date`] [DEBUG] ucswitchSetup.sh cp conf" >> ${ucswitchSetupLogFile}
fi
#修改配置
#switchname
sed -i "s%ucswitchName%${ucswitchName}%g" /usr/local/freeswitch/conf/autoload_configs/switch.conf.xml 
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh config switch.xml ucswitchname success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to config switch.xml ucswitchname" >> ${ucswitchSetupLogFile}
	exit 1
fi
sed -i "s%ucswitchIp%${ucswitchIp}%g" /usr/local/freeswitch/conf/vars.xml
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh config vars.xml local_ip_v4 success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to config vars.xml local_ip_v4" >> ${ucswitchSetupLogFile}
	exit 1
fi
sed -i "s%ucswitchDbIp%${ucswitchDbIp}%g" /usr/local/freeswitch/conf/vars.xml
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh config vars.xml database ip success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to config vars.xml database ip" >> ${ucswitchSetupLogFile}
	exit 1
fi
sed -i "s%ucswitchDbPort%${ucswitchDbPort}%g" /usr/local/freeswitch/conf/vars.xml
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh config vars.xml database port success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to config vars.xml database port" >> ${ucswitchSetupLogFile}
	exit 1
fi
sed -i "s%ucswitchRedisPort%${redisPort}%g" /usr/local/freeswitch/conf/vars.xml
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh config vars.xml redis port success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to config vars.xml redis port" >> ${ucswitchSetupLogFile}
	exit 1
fi
sed -i "s%ucswitchRedisIp%${redisServer}%g" /usr/local/freeswitch/conf/vars.xml
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh config vars.xml redis ip success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to config vars.xml redis ip" >> ${ucswitchSetupLogFile}
	exit 1
fi
sed -i "s%ucswitchRedisPort%${redisPort}%g" /usr/local/freeswitch/conf/autoload_configs/uccc_redis.conf.xml
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh config uccc_redis port success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to config uccc_redis port" >> ${ucswitchSetupLogFile}
	exit 1
fi
sed -i "s%ucswitchRedisIp%${redisServer}%g" /usr/local/freeswitch/conf/autoload_configs/uccc_redis.conf.xml
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh config uccc_redis ip success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to config uccc_redis ip" >> ${ucswitchSetupLogFile}
	exit 1
fi
sed -i "s%ucswitchRedisPort%${redisPort}%g" /usr/local/freeswitch/conf/autoload_configs/hiredis.conf.xml
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh config hiredis port success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to config hiredis port" >> ${ucswitchSetupLogFile}
	exit 1
fi
sed -i "s%ucswitchRedisIp%${redisServer}%g" /usr/local/freeswitch/conf/autoload_configs/hiredis.conf.xml
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh config hiredis ip success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to config hiredis ip" >> ${ucswitchSetupLogFile}
	exit 1
fi
sed -i "s%ucswitchCdrUrl%${cdrUrl}%g" /usr/local/freeswitch/conf/autoload_configs/uccc_json_cdr.conf.xml
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh config uccc cdr url  success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to config uccc cdr url" >> ${ucswitchSetupLogFile}
	exit 1
fi
#安装音乐文件。
cd ${autoDirectory}
wget "${dependsUrl}/sounds/sounds.tar.gz"
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh down sounds success" >> ${ucswitchSetupLogFile}
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to down sounds" >> ${ucswitchSetupLogFile}
	exit 1
fi
tar -xzvf ${autoDirectory}/sounds.tar.gz -C /usr/local/freeswitch/
if [ $? -eq 0 ];then
        echo "[`date`] [DEBUG] ucswitchSetup.sh install sounds success" >> ${ucswitchSetupLogFile}
else
        echo "[`date`] [ERROR] ucswitchSetup.sh Failed to install sounds" >> ${ucswitchSetupLogFile}
        exit 1
fi
echo "[`date`] [DEBUG] #############################  ucswitchSetup.sh end  ##########################" >> ${ucswitchSetupLogFile}