setup.sh
9.73 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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# 文件名: 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}