-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-a.sh
executable file
·522 lines (468 loc) · 9.26 KB
/
setup-a.sh
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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
#!/bin/bash
# this is a setup scripts for TeamTalk
# author: luoning
# date: 09/05/2014
# setup TeamTalk
REDIS=redis
MYSQL=mariadb
NGINX_PHP=nginx_php
NGINX=nginx
PHP=php
IM_WEB=im_web
IM_SERVER=im_server
IM_DB_PROXY=im_db_proxy
CUR_DIR=
SETUP_PROGRESS=setup.progress
REDIS_SETUP_BEGIN=0
REDIS_SETUP_SUCCESS=0
MYSQL_SETUP_BEGIN=0
MYSQL_SETUP_SUCCESS=0
NGINX_SETUP_BEGIN=0
NGINX_SETUP_SUCCESS=0
PHP_SETUP_BEGIN=0
PHP_SETUP_SUCCESS=0
IM_WEB_SETUP_BEGIN=0
IM_WEB_SETUP_SUCCESS=0
IM_SERVER_SETUP_BEGIN=0
IM_SERVER_SETUP_SUCCESS=0
# Check if user is root
check_user() {
if [ $(id -u) != "0" ]; then
echo "Error: You must be root to run this script, please use root to install im"
exit 1
fi
}
check_os() {
OS_VERSION=$(less /etc/redhat-release)
OS_BIT=$(getconf LONG_BIT)
#echo "$OS_VERSION, $OS_BIT bit..."
if [[ $OS_VERSION =~ "CentOS" ]]; then
if [ $OS_BIT == 64 ]; then
return 0
else
echo "Error: OS must be CentOS 64bit to run this script."
exit 1
fi
else
echo "Error: OS must be CentOS 64bit to run this script."
exit 1
fi
}
print_hello() {
echo "========================================================================="
echo "TeamTalk V1.0 for CentOS Linux Server, Written by Luoning"
echo "========================================================================="
echo "A tool to auto-compile & install TeamTalk on Linux "
echo ""
echo "For more information please visit https://github.com/mogutt/TTAutoDeploy/"
echo "========================================================================="
}
get_cur_dir() {
# Get the fully qualified path to the script
case $0 in
/*)
SCRIPT="$0"
;;
*)
PWD_DIR=$(pwd);
SCRIPT="${PWD_DIR}/$0"
;;
esac
# Resolve the true real path without any sym links.
CHANGED=true
while [ "X$CHANGED" != "X" ]
do
# Change spaces to ":" so the tokens can be parsed.
SAFESCRIPT=`echo $SCRIPT | sed -e 's; ;:;g'`
# Get the real path to this script, resolving any symbolic links
TOKENS=`echo $SAFESCRIPT | sed -e 's;/; ;g'`
REALPATH=
for C in $TOKENS; do
# Change any ":" in the token back to a space.
C=`echo $C | sed -e 's;:; ;g'`
REALPATH="$REALPATH/$C"
# If REALPATH is a sym link, resolve it. Loop for nested links.
while [ -h "$REALPATH" ] ; do
LS="`ls -ld "$REALPATH"`"
LINK="`expr "$LS" : '.*-> \(.*\)$'`"
if expr "$LINK" : '/.*' > /dev/null; then
# LINK is absolute.
REALPATH="$LINK"
else
# LINK is relative.
REALPATH="`dirname "$REALPATH"`""/$LINK"
fi
done
done
if [ "$REALPATH" = "$SCRIPT" ]
then
CHANGED=""
else
SCRIPT="$REALPATH"
fi
done
# Change the current directory to the location of the script
CUR_DIR=$(dirname "${REALPATH}")
}
setup_begin() {
# example: redis start
echo "$1 start" >> $CUR_DIR/$SETUP_PROGRESS
}
setup_success() {
# example: redis success
echo "$1 success" >> $CUR_DIR/$SETUP_PROGRESS
}
get_setup_process() {
if [ -f $CUR_DIR/$SETUP_PROGRESS ]; then
while read line
do
case $line in
"$REDIS start")
REDIS_SETUP_BEGIN=1
;;
"$REDIS success")
REDIS_SETUP_SUCCESS=1
;;
"$MYSQL start")
MYSQL_SETUP_BEGIN=1
;;
"$MYSQL success")
MYSQL_SETUP_SUCCESS=1
;;
"$NGINX start")
NGINX_SETUP_BEGIN=1
;;
"$NGINX success")
NGINX_SETUP_SUCCESS=1
;;
"$PHP start")
PHP_SETUP_BEGIN=1
;;
"$PHP success")
PHP_SETUP_SUCCESS=1
;;
"$IM_WEB start")
IM_WEB_SETUP_BEGIN=1
;;
"$IM_WEB success")
IM_WEB_SETUP_SUCCESS=1
;;
"$IM_SERVER start")
IM_SERVER_SETUP_BEGIN=1
;;
"$IM_SERVER success")
IM_SERVER_SETUP_SUCCESS=1
;;
*)
echo "unknown setup progress: $line "
;;
esac
done < $CUR_DIR/$SETUP_PROGRESS
fi
}
check_redis() {
cd $REDIS
chmod +x setup.sh
./setup.sh check
if [ $? -eq 0 ]; then
cd $CUR_DIR
else
return 1
fi
}
build_redis() {
cd $REDIS
chmod +x setup.sh
setup_begin $REDIS
./setup.sh install
if [ $? -eq 0 ]; then
setup_success $REDIS
cd $CUR_DIR
else
return 1
fi
}
check_mariadb() {
cd $MYSQL
chmod +x setup.sh
./setup.sh check
if [ $? -eq 0 ]; then
cd $CUR_DIR
else
return 1
fi
}
build_mariadb() {
cd $MYSQL
chmod +x setup.sh
setup_begin $MYSQL
./setup.sh install
if [ $? -eq 0 ]; then
setup_success $MYSQL
cd $CUR_DIR
else
return 1
fi
}
check_nginx() {
cd $NGINX_PHP
cd $NGINX
chmod +x setup.sh
./setup.sh check
if [ $? -eq 0 ]; then
cd $CUR_DIR
else
return 1
fi
}
check_php() {
cd $NGINX_PHP
cd $PHP
chmod +x setup.sh
./setup.sh check
if [ $? -eq 0 ]; then
cd $CUR_DIR
else
return 1
fi
}
#modify by amirline
build_nginx() {
cd $NGINX_PHP
cd $NGINX
chmod +x *.sh
./build.sh
cd $CUR_DIR
}
build_php() {
cd $NGINX_PHP
cd $PHP
chmod +x setup.sh
setup_begin $PHP
./setup.sh install
if [ $? -eq 0 ]; then
setup_success $PHP
cd $CUR_DIR
else
return 1
fi
}
check_im_web() {
cd $IM_WEB
chmod +x setup-a.sh
./setup-a.sh check
if [ $? -eq 0 ]; then
cd $CUR_DIR
else
return 1
fi
}
build_im_web() {
cd $IM_WEB
chmod +x setup-a.sh
setup_begin $IM_WEB
./setup-a.sh install
if [ $? -eq 0 ]; then
setup_success $IM_WEB
cd $CUR_DIR
else
return 1
fi
}
check_im_server() {
cd $IM_SERVER
chmod +x setup.sh
./setup.sh check
if [ $? -eq 0 ]; then
cd $CUR_DIR
else
return 1
fi
}
#modify by amirline
build_im_server() {
cd $IM_SERVER
chmod +x setup-a.sh
setup_begin $IM_SERVER
./setup-a.sh install
if [ $? -eq 0 ]; then
setup_success $IM_SERVER
cd $CUR_DIR
else
return 1
fi
}
check_install() {
local MODULE=$1
local MODULE_SETUP_BEGIN=$2
local MODULE_SETUP_SUCCESS=$3
if [ $MODULE_SETUP_BEGIN = 1 ] && [ $MODULE_SETUP_SUCCESS = 1 ]; then
echo "$MODULE has installed, skip check..."
return 2
else
if [ $MODULE_SETUP_BEGIN = 1 ] && [ $MODULE_SETUP_SUCCESS = 0 ]; then
echo "Warning: $MODULE has installed before, but failed by some reason, check/build again?(Y/N)"
while read input
do
if [ $input = "Y" ] || [ $input = "y" ]; then
return 0
elif [ $input = "N" ] || [ $input = "n" ]; then
return 1
else
echo "unknown input, try again please, check/build again?(Y/N)."
continue
fi
done
fi
fi
return 0
}
check_env() {
local MODULE=$1
echo "start to check $MODULE..."
check_$MODULE
if [ $? -eq 0 ]; then
echo "check $MODULE successed."
else
echo "Error: check $MODULE failed, stop install."
exit 1
fi
}
check_module() {
local MODULE=$1
local MODULE_SETUP_BEGIN=$2
local MODULE_SETUP_SUCCESS=$3
check_install $MODULE $MODULE_SETUP_BEGIN $MODULE_SETUP_SUCCESS
RET=$?
if [ $RET -eq 0 ]; then
check_env $MODULE
elif [ $RET -eq 1 ]; then
return 1
fi
return 0
}
check_all() {
get_setup_process
#redis
check_module $REDIS $REDIS_SETUP_BEGIN $REDIS_SETUP_SUCCESS
if [ $? -eq 1 ]; then
exit 1
fi
#mysql
check_module $MYSQL $MYSQL_SETUP_BEGIN $MYSQL_SETUP_SUCCESS
if [ $? -eq 1 ]; then
exit 1
fi
#nginx
check_module $NGINX $NGINX_SETUP_BEGIN $NGINX_SETUP_SUCCESS
if [ $? -eq 1 ]; then
exit 1
fi
#php
check_module $PHP $PHP_SETUP_BEGIN $PHP_SETUP_SUCCESS
if [ $? -eq 1 ]; then
exit 1
fi
#im_web
check_module $IM_WEB $IM_WEB_SETUP_BEGIN $IM_WEB_SETUP_SUCCESS
if [ $? -eq 1 ]; then
exit 1
fi
#im_server
check_module $IM_SERVER $IM_SERVER_SETUP_BEGIN $IM_SERVER_SETUP_SUCCESS
if [ $? -eq 1 ]; then
exit 1
fi
echo "Check TeamTalk successed, and you can install TeamTalk now."
}
clean_yum() {
YUM_PID=/var/run/yum.pid
if [ -f "$YUM_PID" ]; then
set -x
rm -f YUM_PID
killall yum
set +x
fi
}
build_module() {
local MODULE=$1
local MODULE_SETUP_BEGIN=$2
local MODULE_SETUP_SUCCESS=$3
if [ $MODULE_SETUP_BEGIN = 1 ] && [ $MODULE_SETUP_SUCCESS = 1 ]; then
echo "$MODULE has installed, skip build..."
else
echo "start to build $MODULE..."
build_$MODULE
if [ $? -eq 0 ]; then
echo "build $MODULE successed."
else
echo "Error: build $MODULE failed, stop install."
return 1
fi
fi
}
build_all() {
clean_yum
yum -y install yum
if [ $? -eq 0 ]; then
echo "update yum successed."
else
echo "update yum failed."
exit 1
fi
#redis
build_module $REDIS $REDIS_SETUP_BEGIN $REDIS_SETUP_SUCCESS
if [ $? -eq 1 ]; then
exit 1
fi
#mysql
build_module $MYSQL $MYSQL_SETUP_BEGIN $MYSQL_SETUP_SUCCESS
if [ $? -eq 1 ]; then
exit 1
fi
#nginx
build_module $NGINX $NGINX_SETUP_BEGIN $NGINX_SETUP_SUCCESS
if [ $? -eq 1 ]; then
exit 1
fi
#php
build_module $PHP $PHP_SETUP_BEGIN $PHP_SETUP_SUCCESS
if [ $? -eq 1 ]; then
exit 1
fi
#im_web
build_module $IM_WEB $IM_WEB_SETUP_BEGIN $IM_WEB_SETUP_SUCCESS
if [ $? -eq 1 ]; then
exit 1
fi
#im_server
build_module $IM_SERVER $IM_SERVER_SETUP_BEGIN $IM_SERVER_SETUP_SUCCESS
if [ $? -eq 1 ]; then
exit 1
fi
}
print_help() {
echo "Usage: "
echo " $0 check --- check environment"
echo " $0 install --- check & run scripts to install"
}
case $1 in
check)
print_hello
check_user
#check_os
get_cur_dir
#check_all
;;
install)
print_hello
check_user
#check_os
get_cur_dir
#check_all
build_all
;;
*)
print_help
;;
esac