ucswitchSetup.sh 4.81 KB
# 作者:石晓旭
#!/bin/bash
echo "[`date`] [DEBUG] #############################  ucswitchSetup.sh start  ##########################" 
#安装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" 
	else
		echo "[`date`] [ERROR] ucswitchSetup.sh Failed to install git" 
		exit 1	
	fi
else
	echo "[`date`] [DEBUG] ucswitchSetup.sh install git already exits" 
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" 
	else
		echo "[`date`] [ERROR] ucswitchSetup.sh Failed to git clone ucswitch" 
	fi
else
	echo "[`date`] [DEBUG] ucswitchSetup.sh git clone ucswitch already exits" 
fi
#安装依赖
cd ${ucswitchDirectory} cd && ./depends_install.sh "${ucswitchDirectory}" "${dependsUrl}/fs/libs/"
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh depends_install success" 
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to depends_install" 
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}/conf/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" 
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to bootstrap.sh" 
	exit 1
fi
cd ${ucswitchDirectory} && ./configure.sh "${ucswitchDirectory}" 
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh configure.sh success" 
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to configure.sh" 
	exit 1
fi
cd ${ucswitchDirectory} && make && make install
if [ $? -eq 0 ];then
	echo "[`date`] [DEBUG] ucswitchSetup.sh install ucswitch success" 
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to install ucswitch" 
	exit 1
fi

#替换配置
cd ${autoDirectory}

if [ ! -d "/usr/local/freeswitch" ];then
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to replace scripts and config" 
	exit 1
fi
if [ ! -f "${autoDirectory}/sounds.tar.gz" ];then
	wget $fsSoundsUrl
	if [ $? -ne 0 ];then
		exit 1
	fi
fi
if [ ! -f "${autoDirectory}/sbin.tar.gz" ];then
	wget $fsSbinUrl
	if [ $? -ne 0 ];then
		exit 1
	fi
fi
if [ ! -f "${autoDirectory}/scripts.tar.gz" ];then
	wget $fsScriptsUrl
	if [ $? -ne 0 ];then
		exit 1
	fi
fi
if [ ! -f "${autoDirectory}/conf.tar.gz" ];then
	wget $fsConfUrl
	if [ $? -ne 0 ];then
		exit 1
	fi
fi

tar -xzvf ${autoDirectory}/sbin.tar.gz -C /
if [ $? -eq 0 ];then
        echo "[`date`] [DEBUG] ucswitchSetup.sh replace sbin success" 
else
        echo "[`date`] [ERROR] ucswitchSetup.sh Failed to replace sbin" 
        exit 1
fi

tar -xzvf ${autoDirectory}/scripts.tar.gz -C /usr/local/freeswitch/
if [ $? -eq 0 ];then
        echo "[`date`] [DEBUG] ucswitchSetup.sh replace scripts success" 
else
        echo "[`date`] [ERROR] ucswitchSetup.sh Failed to replace scripts" 
        exit 1
fi

tar -xzvf ${autoDirectory}/conf.tar.gz -C /usr/local/freeswitch/
if [ $? -eq 0 ];then
        echo "[`date`] [DEBUG] ucswitchSetup.sh replace conf success" 
else
        echo "[`date`] [ERROR] ucswitchSetup.sh Failed to replace conf" 
        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" 
else
        echo "[`date`] [ERROR] ucswitchSetup.sh Failed to install sounds" 
        exit 1
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" 
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to config switch.xml ucswitchname" 
	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" 
else
	echo "[`date`] [ERROR] ucswitchSetup.sh Failed to config vars.xml local_ip_v4" 
	exit 1
fi
# 优化 #
cat /etc/fstab | grep /usr/local/freeswitch/db
if [ $? -ne 0 ];then
	echo "tmpfs  /usr/local/freeswitch/db  tmpfs   size=100m   0 0" >> /etc/fstab
fi
cat /etc/fstab | grep /home/sharedfs/records
if [ $? -ne 0 ];then
	echo "tmpfs  /home/sharedfs/records  tmpfs   size=2048m   0 0" >> /etc/fstab
fi
mkdir -p /home/sharedfs/records
/bin/mount -a
if [ $? -ne 0 ];then
	exit 1
fi
echo "[`date`] [DEBUG] #############################  ucswitchSetup.sh end  ##########################"