-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.sh
377 lines (345 loc) · 10.7 KB
/
main.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
#默认参数配置
remotedir=/midware/ipop-admin
remoteips_dev=(10.203.109.135)
remoteips_qa=(10.203.109.159 10.203.109.160)
remoteips_prod_ipop=(10.203.72.74 10.203.72.75)
remoteips_prod_sboard=(10.203.72.76 10.203.72.77)
remotebakfile=bak
remotereadyfile=ready
remoteuser=root
locshell=shell-dev.sh
remoteshell=shell.sh
locshelldir=D:/SGM/IPOP-server/
locfile=IPOP-server-0.0.1-SNAPSHOT.war
remotefile=IPOP-server-0.0.1-SNAPSHOT.war
locfiledir=D:/SGM/IPOP-server/target/
branch=BRANCH_DEV_1.0.0
app=ipop
env=dev
main(){
while true
do
selectapp
cd $locshelldir
echo ""
#echo -e "\e[1;32m (cd $locshelldir)\e[0m\n"
while true
do
selectenv
#git checkout $branch
echo ""
while true
do
selectipToDeploy
break
done
echo -en "\n是否还需要部署其他环境?: y/n:"
read v
if [ -z $v ]; then
echo -e "\e[1;32m不部署其他环境\e[0m"
break
fi
if [ $v == "y" ]||[ $v == "1" ]; then
continue;
else
echo -e "\e[1;32m不部署其他环境\e[0m"
fi
break
done
echo -en "\n是否还需要部署其他应用?: y/n:"
read v
if [ -z $v ]; then
echo -e "\e[1;32m不部署其他应用\e[0m"
sleep 0.5
echo -en "\n................................................................................................\e[1;32mexit"
sout 1 1
exit
fi
if [ $v == "y" ]||[ $v == "1" ]; then
continue;
else
echo -e "\e[1;32m不部署其他应用\e[0m"
sleep 0.5
echo -en "\n................................................................................................\e[1;32mexit"
sout 1 1
exit
fi
done
}
sout(){
i=$1
while true
do
echo -en "\e[1;32m."
sleep $2
i=$[i-1];
if [ $i -lt 0 ]; then
break
fi
done
}
selectipToDeploy(){
for i in ${remoteips[@]}
do
remoteip=$i
echo -en "\e[1;32m..................................... 正在部署:$remoteip ....................................\e[0m"
deploy
done
}
selectenv(){
while true
do
echo -n "输入部署环境(1-->dev 2-->qa 3-->prod ):"
read v
if [ -z $v ]; then
#locshell=shell-dev.sh
#branch=BRANCH_DEV_1.0.0
env=dev
remoteips=${remoteips_dev[@]}
echo -e "\e[1;32m========================================== 部署环境:$env ==========================================\e[0m"
else
if [ $v == "1" ]; then
#locshell=shell-dev.sh
#branch=BRANCH_DEV_1.0.0
env=dev
remoteips=${remoteips_dev[@]}
echo -e "\e[1;32m========================================== 部署环境:$env ==========================================\e[0m"
break;
fi
if [ $v == "2" ]; then
#locshell=shell-qa.sh
#branch=BRANCH_QA_1.0.0
env=qa
remoteips=${remoteips_qa[@]}
echo -e "\e[1;32m========================================== 部署环境:$env ==========================================\e[0m"
break;
fi
if [ $v == "3" ]; then
#locshell=shell-prod.sh
#branch=master
env=prod
remoteips=${remoteips_prod_ipop[@]}
if [ $app == "sboard" ]; then
remoteips=${remoteips_prod_sboard[@]}
fi
echo -e "\e[1;32m========================================== 部署环境:$env ==========================================\e[0m"
break;
fi
echo -e "\e[1;31m不要瞎写\e[0m"
continue
fi
break
done
}
selectapp(){
while true
do
echo -n "输入部署的应用(1-->ipop 2-->mportal 3-->sform 4-->sboard):"
read v
if [ -z $v ]; then
app=ipop
locfile=IPOP-server-0.0.1-SNAPSHOT.war
locfiledir=D:/SGM/IPOP-server/target/
locshelldir=D:/SGM/IPOP-server/
remotedir=/midware/ipop-admin
remotefile=IPOP-server-0.0.1-SNAPSHOT.war
echo -e "\e[1;32m########################################## 默认部署应用$app #######################################\e[0m"
else
case "$v" in
"1")
app=ipop
locfile=IPOP-server-0.0.1-SNAPSHOT.war
locfiledir=D:/SGM/IPOP-server/target/
locshelldir=D:/SGM/IPOP-server/
remotedir=/midware/ipop-admin
remotefile=IPOP-server-0.0.1-SNAPSHOT.war
echo -e "\e[1;32m########################################## 部署应用$app #########################################\e[0m"
break
;;
"2")
app=mportal
locfiledir=D:/SGM/mPortal-server/target/
locfile=mportal-server-0.0.1-SNAPSHOT.war
locshelldir=D:/SGM/mPortal-server/
remotedir=/midware/ipop-mportal
remotefile=mportal-server-0.0.1-SNAPSHOT.war
echo -e "\e[1;32m########################################## 部署应用$app #########################################\e[0m"
break
;;
"3")
app=sform
locfiledir=D:/SGM/sForm-server/target/
locfile=dynamic-form-0.0.1-SNAPSHOT.jar
locshelldir=D:/SGM/sForm-server/
remotedir=/midware/ipop-sform
remotefile=dynamic-form-0.0.1-SNAPSHOT.jar
echo -e "\e[1;32m########################################## 部署应用$app #########################################\e[0m"
break
;;
"4")
app=sboard
locfiledir=D:/SGM/sBoard-server/target/
locfile=sboard.war
locshelldir=D:/SGM/sBoard-server/
remotedir=/midware/apache-tomcat-8.5.28/webapps
remotefile=ROOT.war
echo -e "\e[1;32m########################################## 部署应用$app #########################################\e[0m"
break
;;
esac
echo -e "\e[1;31m输入错误,请重新选择\e[0m"
continue
fi
break
echo ""
done
}
deploy(){
echo -en "\n是否全自动部署? y/n:"
read v
if [ -z $v ]; then
echo -e "\e[1;32m手动部署\e[0m"
deployhand
echo -e "\e[1;32m..................................... 部署完毕:$remoteip ....................................\e[0m\n"
return
fi
if [ $v == "y" ]||[ $v == "1" ]; then
echo -e "\e[1;32m自动部署\e[0m"
deployauto
else
echo -e "\e[1;32m手动部署\e[0m"
deployhand
fi
echo ""
echo -e "\e[1;32m..................................... 部署完毕:$remoteip ....................................\e[0m\n"
}
deployauto(){
git pull
mvn clean package -Dmaven.test.skip=true
checkdir $remotedir
checkdir $remotedir/$remotebakfile
checkdir $remotedir/$remotereadyfile
upload $locshelldir $locshell $remoteuser $remoteip $remotedir $remoteshell
upload $locfiledir $locfile $remoteuser $remoteip $remotedir/$remotereadyfile $remotefile
shell $remoteuser $remoteip $remotedir $remoteshell bak $env
shell $remoteuser $remoteip $remotedir $remoteshell stop $env
shell $remoteuser $remoteip $remotedir $remoteshell update $env
shell $remoteuser $remoteip $remotedir $remoteshell start $env
}
deployhand(){
echo -n "是否更新代码? y/n:"
read v
if [ -z $v ]; then
echo -e "\e[1;32m \b不更新代码 \e[0m"
else
if [ $v == "y" ]||[ $v == "1" ]; then
git pull
else
echo -e "\e[1;32m \b不更新代码 \e[0m"
fi
fi
echo -n "是否打包? y/n:"
read v
if [ -z $v ]; then
echo -e "\e[1;32m \b不打包 \e[0m"
else
if [ $v == "y" ]||[ $v == "1" ]; then
mvn clean package -Dmaven.test.skip=true
else
echo -e "\e[1;32m \b不打包 \e[0m"
fi
fi
echo -n "是否确认目录? y/n:"
read v
if [ -z $v ]; then
echo -e "\e[1;32m \b不确认目录 \e[0m"
else
if [ $v == "y" ]||[ $v == "1" ]; then
checkdir $remotedir
checkdir $remotedir/$remotebakfile
checkdir $remotedir/$remotereadyfile
else
echo -e "\e[1;32m \b不确认目录 \e[0m"
fi
fi
echo -n "是否上传脚本? y/n:"
read v
if [ -z $v ]; then
echo -e "\e[1;32m \b不上传脚本 \e[0m"
else
if [ $v == "y" ]||[ $v == "1" ]; then
upload $locshelldir $locshell $remoteuser $remoteip $remotedir $remoteshell
else
echo -e "\e[1;32m \b不上传脚本 \e[0m"
fi
fi
echo -n "是否上传代码包? y/n:"
read v
if [ -z $v ]; then
echo -e "\e[1;32m \b不上传代码包 \e[0m"
else
if [ $v == "y" ]||[ $v == "1" ]; then
upload $locfiledir $locfile $remoteuser $remoteip $remotedir/$remotereadyfile $remotefile
else
echo -e "\e[1;32m \b不上传代码包 \e[0m"
fi
fi
echo -n "是否备份? y/n:"
read v
if [ -z $v ]; then
echo -e "\e[1;32m \b不备份 \e[0m"
else
if [ $v == "y" ]||[ $v == "1" ]; then
shell $remoteuser $remoteip $remotedir $remoteshell bak $env
else
echo -e "\e[1;32m \b不备份 \e[0m"
fi
fi
echo -n "是否停止服务? y/n: "
read v
if [ -z $v ]; then
echo -e "\e[1;32m \b不停止服务 \e[0m"
else
if [ $v == "y" ]||[ $v == "1" ]; then
shell $remoteuser $remoteip $remotedir $remoteshell stop $env
else
echo -e "\e[1;32m \b不停止服务 \e[0m"
fi
fi
echo -n "是否更新代码? y/n: "
read v
if [ -z $v ]; then
echo -e "\e[1;32m \b不更新代码 \e[0m"
else
if [ $v == "y" ]||[ $v == "1" ]; then
shell $remoteuser $remoteip $remotedir $remoteshell update $env
else
echo -e "\e[1;32m \b不更新代码 \e[0m"
fi
fi
echo -n "是否启动服务? y/n: "
read v
if [ -z $v ]; then
echo -e "\e[1;32m \b不启动服务 \e[0m"
else
if [ $v == "y" ]||[ $v == "1" ]; then
shell $remoteuser $remoteip $remotedir $remoteshell start $env
else
echo -e "\e[1;32m \b不启动服务 \e[0m"
fi
fi
}
checkdir(){
ssh $remoteuser@$remoteip "[ -d $1 ] && echo -e \"\e[1;32mdir:$1 is ok \e[0m\" || mkdir -p $1"
}
upload(){
scp -r $1$2 $3@$4:$5/$6
}
shell(){
ssh $1@$2 "cd $3/; sh ./$4 $5 $6 > nohup.out"
}
case "$1" in
"")
main
;;
esac