-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathdeploy-boot.sh
282 lines (268 loc) · 13.1 KB
/
deploy-boot.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
#!/bin/bash
#/*
# * Copyright 2017 ~ 2025 the original author or authors. <Wanglsir@gmail.com, 983708408@qq.com>
# *
# * Licensed under the Apache License, Version 2.0 (the "License");
# * you may not use this file except in compliance with the License.
# * You may obtain a copy of the License at
# *
# * http://www.apache.org/licenses/LICENSE-2.0
# *
# * Unless required by applicable law or agreed to in writing, software
# * distributed under the License is distributed on an "AS IS" BASIS,
# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# * See the License for the specific language governing permissions and
# * limitations under the License.
# */
# @see: http://www.huati365.com/answer/j6BxQYLqYVeWe4k
if [[ "$(echo groups)" == "root" ]]; then
logErr "Please execute the scripts as a user with root privileges !"; exit -1
fi
# Global definition.
export currDir=$(cd "`dirname $0`"/ ; pwd)
# Basic deploy environment variables.
[ -z "$workspaceDir" ] && export workspaceDir="${HOME}/.deploy-workspace" && mkdir -p $workspaceDir
[ -z "$deployDebug" ] && export deployDebug="false"
[ -z "$scriptsBaseUrl" ] && export scriptsBaseUrl="https://raw.githubusercontent.com/wl4g/dopaas/master/script/deploy"
[ -z "$scriptsBaseUrlBackup1" ] && export scriptsBaseUrlBackup1="https://gitee.com/wl4g/dopaas/raw/master/script/deploy"
# Detecting network environment.
function detectingNetwork() {
echo "Detecting networking to fetch best resources allocating ..."
export isChinaLANNetwork="$(cat $workspaceDir/.isChinaLANNetwork 2>/dev/null)" # Load last configuration first.
if [ -z "$isChinaLANNetwork" ]; then # Primary checker url1
#ipArea=$(curl --connect-timeout 10 -m 20 -sSL "http://ip.taobao.com/outGetIpInfo?ip=113.109.55.66&accessKey=alibaba-inc" 2>/dev/null)
ipArea=$(curl --connect-timeout 10 -m 20 -sSL "http://ip.taobao.com/outGetIpInfo?ip=myip&accessKey=alibaba-inc" 2>/dev/null)
export isChinaLANNetwork=$([[ "$ipArea" =~ "中国" || "$ipArea" =~ "朝鲜" ]] && echo Y || echo "")
fi
if [ -z "$isChinaLANNetwork" ]; then # Fallback checker url2
echo "Try checking the network again with http://cip.cc ..."
ipArea=$(curl --connect-timeout 10 -m 20 -sSL "http://cip.cc" 2>/dev/null)
export isChinaLANNetwork=$([[ "$ipArea" =~ "中国" || "$ipArea" =~ "朝鲜" ]] && echo Y || echo "")
fi
if [ -z "$isChinaLANNetwork" ]; then # Fallback checker url3
echo "Try checking the network again with http://ipinfo.io ..."
ipArea=$(curl --connect-timeout 10 -m 20 -sSL "http://ipinfo.io" 2>/dev/null)
export isChinaLANNetwork=$([[ "$ipArea" =~ "\"country\": \"CN\"" ]] && echo Y || echo "")
fi
if [ -z "$isChinaLANNetwork" ]; then # Fallback checker url4
echo "Try checking the network again with https://api.myip.com ..."
ipArea=$(curl --connect-timeout 10 -m 20 -sSL "https://api.myip.com" 2>/dev/null)
export isChinaLANNetwork=$([[ "$ipArea" =~ "China" ]] && echo Y || echo "")
fi
[ "$isChinaLANNetwork" != "Y" ] && export isChinaLANNetwork="N"
echo "$isChinaLANNetwork" > "$workspaceDir/.isChinaLANNetwork"
# Choose best fast-resources intelligently.
if [ "$isChinaLANNetwork" == "Y" ]; then
export scriptsBaseUrl="$scriptsBaseUrlBackup1"
fi
}
# Download deployer dependencies scripts.
function downloadDeployerDependencies() {
if [ "$deployDebug" == "false" ]; then # Debug mode does not need to download depend scripts.
cd $currDir
#\rm -rf $(ls deploy-*.sh 2>/dev/null|grep -v $0) # Cleanup scripts.
echo "Downloading deployer scripts dependencies on '$scriptsBaseUrl' ..."
curl -sLk --connect-timeout 10 -m 20 -O "$scriptsBaseUrl/deploy-i18n-zh_CN.sh"; [ $? -ne 0 ] && exit -1
curl -sLk --connect-timeout 10 -m 20 -O "$scriptsBaseUrl/deploy-i18n-en_US.sh"; [ $? -ne 0 ] && exit -1
curl -sLk --connect-timeout 10 -m 20 -O "$scriptsBaseUrl/deploy-env.sh"; [ $? -ne 0 ] && exit -1
curl -sLk --connect-timeout 10 -m 20 -O "$scriptsBaseUrl/deploy-base.sh"; [ $? -ne 0 ] && exit -1
curl -sLk --connect-timeout 10 -m 20 -O "$scriptsBaseUrl/deploy-common.sh"; [ $? -ne 0 ] && exit -1
curl -sLk --connect-timeout 10 -m 20 -O "$scriptsBaseUrl/deploy-host.csv.tpl"; [ $? -ne 0 ] && exit -1
curl -sLk --connect-timeout 10 -m 20 -O "$scriptsBaseUrl/deploy-docker.sh"; [ $? -ne 0 ] && exit -1
curl -sLk --connect-timeout 10 -m 20 -O "$scriptsBaseUrl/install-nginx.sh"; [ $? -ne 0 ] && exit -1
curl -sLk --connect-timeout 10 -m 20 -O "$scriptsBaseUrl/undeploy-host.sh"; [ $? -ne 0 ] && exit -1
curl -sLk --connect-timeout 10 -m 20 -O "$scriptsBaseUrl/dopaas-ctl.sh"; [ $? -ne 0 ] && exit -1
chmod 750 $currDir/*-*.sh
fi
}
# Check package local repo. (if necessary)
function checkPkgLocalRepo() {
local osType=$(getOsTypeAndCheck)
local notFoundPkgTip=""
# jdk
if [ ! -f "$(echo $localJdk8DownloadUrl|sed 's/file://g')" ]; then
notFoundPkgTip="${notFoundPkgTip}\n\nNot found local pkg local pkg '$localJdk8DownloadUrl', \n please manual download from: 'https://download.java.net/openjdk/jdk8u41/ri/openjdk-8u41-b04-linux-x64-14_jan_2020.tar.gz'"
fi
# sshpass
if [[ "$osType" == "centos6_x64" && ! -f "$(echo $localSshpassForCentos6x64|sed 's/file://g')" ]]; then
notFoundPkgTip="${notFoundPkgTip}\n\nNot found local pkg '$localSshpassForCentos6x64', \n please manual download from: '$sshpassForCentos6x64'"
fi
if [[ "$osType" == "centos7_x64" && ! -f "$(echo $localSshpassForCentos7x64|sed 's/file://g')" ]]; then
notFoundPkgTip="${notFoundPkgTip}\n\nNot found local pkg '$localSshpassForCentos7x64', \n please manual download from: '$sshpassForCentos7x64'"
fi
if [[ "$osType" == "centos8_x64" && ! -f "$(echo $localSshpassForCentos8x64|sed 's/file://g')" ]]; then
notFoundPkgTip="${notFoundPkgTip}\n\nNot found local pkg '$localSshpassForCentos8x64', \n please manual download from: '$sshpassForCentos8x64'"
fi
if [[ "$osType" == "ubuntu_x64" && ! -f "$(echo $localSshpassForUbuntu20x64|sed 's/file://g')" ]]; then
notFoundPkgTip="${notFoundPkgTip}\n\nNot found local pkg '$localSshpassForUbuntu20x64', \n please manual download from: '$sshpassForUbuntu20x64'"
fi
# git
if [[ "$osType" == "centos6_x64" && ! -f "$(echo $localGitDownloadUrlForCentos6x64|sed 's/file://g')" ]]; then
notFoundPkgTip="${notFoundPkgTip}\n\nNot found local pkg '$localGitDownloadUrlForCentos6x64', \n please manual download from: '$gitDownloadUrlForCentos6x64'"
fi
if [[ "$osType" == "centos7_x64" && ! -f "$(echo $localGitDownloadUrlForCentos7x64|sed 's/file://g')" ]]; then
notFoundPkgTip="${notFoundPkgTip}\n\nNot found local pkg '$localGitDownloadUrlForCentos7x64', \n please manual download from: '$gitDownloadUrlForCentos7x64'"
fi
if [[ "$osType" == "centos8_x64" && ! -f "$(echo $localGitDownloadUrlForCentos8x64|sed 's/file://g')" ]]; then
notFoundPkgTip="${notFoundPkgTip}\n\nNot found local pkg '$localGitDownloadUrlForCentos8x64', \n please manual download from: '$gitDownloadUrlForCentos8x64'"
fi
if [[ "$osType" == "ubuntu_x64" && ! -f "$(echo $localGitDownloadUrlForUbuntu20x64|sed 's/file://g')" ]]; then
notFoundPkgTip="${notFoundPkgTip}\n\nNot found local pkg '$localGitDownloadUrlForUbuntu20x64', \n please manual download from: '$gitDownloadUrlForUbuntu20x64'"
fi
# maven
if [[ ! -f "$(echo $localApacheMvnDownloadTarUrl|sed 's/file://g')" ]]; then
notFoundPkgTip="${notFoundPkgTip}\n\nNot found local pkg '$localApacheMvnDownloadTarUrl', \n please manual download from: '$secondaryApacheMvnDownloadTarUrl'"
fi
# zookeeper
if [[ ! -f "$(echo $localZkDownloadUrl|sed 's/file://g')" ]]; then
notFoundPkgTip="${notFoundPkgTip}\n\nNot found local pkg '$localZkDownloadUrl', \n please manual download from: '$zkDownloadUrl'"
fi
# nginx
if [[ "$osType" == "centos6_x64" && ! -f "$(echo $localNgxDownloadUrlForCentos6x64|sed 's/file://g')" ]]; then
notFoundPkgTip="${notFoundPkgTip}\n\nNot found local pkg '$localNgxDownloadUrlForCentos6x64', \n please manual download from: '$nginxDownloadUrlForCentos6x64'"
fi
if [[ "$osType" == "centos7_x64" && ! -f "$(echo $localNgxDownloadUrlForCentos7x64|sed 's/file://g')" ]]; then
notFoundPkgTip="${notFoundPkgTip}\n\nNot found local pkg '$localNgxDownloadUrlForCentos7x64', \n please manual download from: '$nginxDownloadUrlForCentos7x64'"
fi
if [[ "$osType" == "centos8_x64" && ! -f "$(echo $localNgxDownloadUrlForCentos8x64|sed 's/file://g')" ]]; then
notFoundPkgTip="${notFoundPkgTip}\n\nNot found local pkg '$localNgxDownloadUrlForCentos8x64', \n please manual download from: '$nginxDownloadUrlForCentos8x64'"
fi
if [[ "$osType" == "ubuntu_x64" && ! -f "$(echo $localNgxDownloadUrlForUbuntu20x64|sed 's/file://g')" ]]; then
notFoundPkgTip="${notFoundPkgTip}\n\nNot found local pkg '$localNgxDownloadUrlForUbuntu20x64', \n please manual download from: '$nginxDownloadUrlForUbuntu20x64'"
fi
# nodejs
if [[ ! -f "$(echo $localNodejsDownloadTarUrl|sed 's/file://g')" ]]; then
notFoundPkgTip="${notFoundPkgTip}\n\nNot found local pkg '$localNodejsDownloadTarUrl', \n please manual download from: '$nodejsDownloadTarUrl'"
fi
echo -e "$notFoundPkgTip"
}
# Execution of environment configuration.
function execWithConfirmingEnvironment() {
# Import common scripts(i18n).
. $currDir/deploy-common.sh && loadi18n
# Check supporting OS.
if [ "$(getOsTypeAndCheck)" == "_" ]; then
echo "Unsupported current OS, only CentOS 6/CentOS 7/CentOS 8/Ubuntu is supported for the time being!"; exit -1
fi
# Option1: Choose deploy network mode.
echo ""
while true
do
echo -e "$confirmDeployerNetworkModeEnvVarMsg"
read -t 300 -p """
$confirmDeployerNetworkModeEnvVarTip1Msg
$confirmDeployerNetworkModeEnvVarTip2Msg
$confirmDeployerNetworkModeEnvVarTip3Msg """ confirm
if [[ "$confirm" == "1" ]]; then
deployNetworkMode="extranet"
break
elif [ "$confirm" == "2" ]; then
deployNetworkMode="intranet"
local result=$(checkPkgLocalRepo)
if [ -n "$result" ]; then
log "$confirmDeployerNetworkModeEnvVarTip4Msg"
echo "$result"; exit -1
else
break
fi
elif [ "$confirm" == "" ]; then
deployNetworkMode="extranet"
break
else
continue
fi
done
echo "$confirmDeployerNetworkModeEnvVarTip5Msg '$deployNetworkMode'"
# Option2: Confim dependent services env configuration. (eg: jdbc/redis/...)
echo ""
while true
do
echo -e """$confirmServicesRuntimeConfigEnvVarMsg
$globalExportedEnvStr"""
read -t 300 -p """
$confirmServicesRuntimeConfigEnvVarTip1Msg
$confirmServicesRuntimeConfigEnvVarTip2Msg
$confirmServicesRuntimeConfigEnvVarTip3Msg """ confirm
if [[ "$confirm" == "n" ]]; then
log "$confirmServicesRuntimeConfigEnvVarTip4Msg '$currDir/deploy-boot.sh'"; exit -1
elif [ "$confirm" == "y" ]; then
break
else
continue
fi
done
# Option3: Choose deployment mode.
echo ""
while true
do
read -t 300 -p """$choosingDeployModeMsg
$choosingDeployModeTip1Msg
$choosingDeployModeTip2Msg
$choosingDeployModeTip3Msg """ depMode
if [[ "$depMode" == "" || "$depMode" == "1" ]]; then
export deployMode="host"
break
elif [ "$depMode" == "2" ]; then
export deployMode="docker"
log "$choosingDeployModeTip4Msg"
exit -1
else
continue
fi
done
log "$choosingDeployModeTip5Msg '$deployMode'"
# Option4: Choose runtime mode.
echo ""
while true
do
read -t 300 -p """$choosingRuntimeModeMsg
$choosingRuntimeModeTip1Msg
$choosingRuntimeModeTip2Msg
$choosingRuntimeModeTip3Msg """ rtMode
if [[ "$rtMode" == "" || "$rtMode" == "1" ]]; then
export runtimeMode="standalone"
break
elif [ "$rtMode" == "2" ]; then
export runtimeMode="cluster"
if [ ! -f "$currDir/deploy-host.csv" ]; then
log "Please create '$currDir/deploy-host.csv' from '$currDir/deploy-host.csv.tpl', and then reexecute '.$currDir/deploy-boot.sh' again !"
exit -1
else
break
fi
else
continue
fi
done
log "$choosingRuntimeModeTip4Msg '$runtimeMode'"
# Call deployer.
if [ "$deployMode" == "host" ]; then
bash $currDir/deploy-host.sh
elif [ "$deployMode" == "docker" ]; then
bash $currDir/deploy-docker.sh
else
log "Unknown deploy mode of '$deployMode' !"; exit -1
fi
}
# ----- Main call. -----
function main() {
[ -n "$(command -v clear)" ] && clear # e.g centos8+ not clear
echo -e ""
echo -e "「 Welcome to DoPaaS Deployer (Boot) 」"
echo -e " \033[32m ___ ___ ___\033[0m"
echo -e " \033[32m| . \ ___ | . \ ___ ___ / __>\033[0m"
echo -e " \033[32m| | |/ . \| _/<_> |<_> |\__ \\\\\033[0m"
echo -e " \033[32m|___/\___/|_| <___|<___|<___/\033[0m"
echo -e ""
echo -e " Wiki: https://github.com/wl4g/dopaas/blob/master/README.md"
echo -e " Wiki(CN): https://gitee.com/wl4g/dopaas/blob/master/README_CN.md"
echo -e " Authors: <Wanglsir@gmail.com, 983708408@qq.com>"
echo -e " Version: 2.0.0"
echo -e " Time: $(date '+%Y-%m-%d %H:%M:%S')"
detectingNetwork
downloadDeployerDependencies
execWithConfirmingEnvironment
#cd $currDir && \rm -rf $(ls deploy-*.sh 2>/dev/null|grep -v "deploy-boot.sh"|grep -v "undeploy-host.sh") # Cleanup scripts.
exit 0
}
main