setup.sh
6.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# 文件名: setup.sh
# 作者 : 石晓旭
# 功能 : 对freeswitch服务器进行自动部署。
# 流程 : 1、获取配置
# 2、安装nfs 客户端。录音存储使用。
# 3、安装tserver
# 4、安装ucswitch
# 5、优化ucswitch
# 6、修改主机名
# 7、修改hosts
#/bin/bash
################################ 公用变量 ##################################
_SERVER_FAMILY=7 # 7 8 75
_SERVER_HOST=`/sbin/ifconfig | grep 'inet addr' | grep -v '127.0.0.1' | awk -F ' ' {'print $2'} | awk -F ':' {'print $2'}`
read -p "Please select the server family: [$_SERVER_FAMILY] " SERVER_FAMILY
if ! echo $SERVER_FAMILY | egrep -q '^[0-9]+$' ; then
echo "Selecting default: $_SERVER_FAMILY"
SERVER_FAMILY=$_SERVER_FAMILY
fi
read -p "Please select the server host: [$_SERVER_HOST] " SERVER_HOST
echo $SERVER_HOST
if ! echo $SERVER_HOST | egrep -q "." ; then
echo "Selecting default: $_SERVER_HOST"
SERVER_HOST=$_SERVER_HOST
fi
export autoDirectory=`pwd`
export ucswitchDirectory="${autoDirectory}/ucswitch"
setupConfig="${autoDirectory}/conf/config${SERVER_FAMILY}.ini"
nfsMod="ucswitchNFS"
recordMod="ucswitchRecord"
dependsMod="ucswitchDepends"
gitMod="ucswitchGit"
coreMod="ucswitchCore"
tserverMod="TServer"
################################ 公用接口 ##################################
iniTmpFieldValue="nil"
function iniGetFieldValue()
{
if [ ! -f $1 ] || [ $# -ne 3 ];then
echo "[`date`] [ERROR] iniGetFieldValue Param."
return 1
fi
nRet=1
bFindBlockBegin=0
bFindBlockEnd=0
# cat $1 | while read line
while read line
do
#判断块开始
if [ "[$2]" == "${line}" ];then
bFindBlockBegin=1
continue
fi
if [ ${bFindBlockBegin} -eq 1 ];then
#判断块结束,块结束后退出。
if [[ "${line}" =~ "[" ]] && [[ "${line}" =~ "]" ]];then
bFindBlockEnd=1
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}
return 0
fi
fi
fi
done <<< "$(cat $1)"
# done
echo "[`date`] [ERROR] iniGetFieldValue $1 $2 $3 not exist."
return 1
}
################################ 配置变量 ##################################
echo "[`date`] [DEBUG] setup.sh start..."
export ucswitchName=${SERVER_HOST}
export ucswitchIp=${SERVER_HOST}
export jarFsIp=${SERVER_HOST}
export jarFsConsumer="freeswitch='${SERVER_HOST}'"
export hostName="CC${SERVER_FAMILY}-PROD-FS${SERVER_HOST##*.}"
# NFS #
iniGetFieldValue ${setupConfig} ${nfsMod} "nfsServer"
if [ $? -ne 0 ];then
exit 1
fi
export nfsServer=${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}
#tserver
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}
echo "[`date`] [DEBUG] setup.sh nfsServer $nfsServer"
echo "[`date`] [DEBUG] setup.sh jarPath $jarPath"
echo "[`date`] [DEBUG] setup.sh jarName $jarName"
echo "[`date`] [DEBUG] setup.sh jarFsIp $jarFsIp"
echo "[`date`] [DEBUG] setup.sh jarFsConsumer $jarFsConsumer"
echo "[`date`] [DEBUG] setup.sh ucswitchName $ucswitchName"
echo "[`date`] [DEBUG] setup.sh ucswitchIp $ucswitchIp"
echo "[`date`] [DEBUG] setup.sh hostName $hostName"
echo "[`date`] [DEBUG] setup.sh dependsUrl $dependsUrl"
echo "[`date`] [DEBUG] setup.sh gitUrl $gitUrl"
echo "[`date`] [DEBUG] setup.sh gitBranch $gitBranch"
echo "[`date`] [DEBUG] setup.sh gitUser $gitUser"
echo "[`date`] [DEBUG] setup.sh gitPassword $gitPassword"
export fsSoundsUrl="${dependsUrl}/${SERVER_FAMILY}/config/sounds.tar.gz"
export fsConfUrl="${dependsUrl}/${SERVER_FAMILY}/config/conf.tar.gz"
export fsScriptsUrl="${dependsUrl}/${SERVER_FAMILY}/config/scripts.tar.gz"
export fsSbinUrl="${dependsUrl}/${SERVER_FAMILY}/config/sbin.tar.gz"
export tServerUrl="${dependsUrl}/${SERVER_FAMILY}/tserver/cti.tar.gz"
################################ 安装流程 ##################################
yum install -y wget
${autoDirectory}/nfsSetup.sh
if [ $? -eq 0 ];then
echo "[`date`] [DEBUG] setup.sh nfsClient install and config success"
else
echo "[`date`] [ERROR] setup.sh Failed to install nfsClient or config"
exit 1
fi
${autoDirectory}/ucswitchSetup.sh
if [ $? -eq 0 ];then
echo "[`date`] [DEBUG] setup.sh ucswitch install and config success"
else
echo "[`date`] [ERROR] setup.sh Failed to install ucswitch or config"
exit 1
fi
/usr/bin/crontab -u root "${autoDirectory}/conf/cron.conf"
if [ $? -eq 0 ];then
echo "[`date`] [DEBUG] ucswitchSetup.sh config crontab success" >> ${ucswitchSetupLogFile}
else
echo "[`date`] [ERROR] ucswitchSetup.sh Failed to config crontab" >> ${ucswitchSetupLogFile}
exit 1
fi
${autoDirectory}/tserverSetup.sh
if [ $? -eq 0 ];then
echo "[`date`] [DEBUG] setup.sh tserverSetup success "
else
echo "[`date`] [ERROR] setup.sh Failed to tserverSetup "
exit 1
fi
#修改主机名
sed -i "s%HOSTNAME=.*%HOSTNAME=$hostName%g" /etc/sysconfig/network
if [ $? -eq 0 ];then
echo "[`date`] [DEBUG] setup.sh set hostname success "
else
echo "[`date`] [ERROR] setup.sh Failed to set hostname "
exit 1
fi
echo "127.0.0.1 $hostName" > /etc/hosts
echo "::1 $hostName" >> /etc/hosts
/sbin/reboot
################################ 安装结束 ##################################
echo "[`date`] [DEBUG] setup.sh finished... "