This repository was archived by the owner on Jun 25, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinstaller.sh
More file actions
executable file
·463 lines (405 loc) · 11.5 KB
/
installer.sh
File metadata and controls
executable file
·463 lines (405 loc) · 11.5 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
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
#!/bin/bash
# Copyright (c) 2015 Intel Corporation
#
# 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.
#
function usage {
echo "Usage: installer.sh CONFIGURATION_FILE"
echo "No configuration file provided or it does not exist"
exit
}
function check_space_exists {
EXISTS=$(cf spaces | grep -x "${1}\ *" | wc -l)
echo $EXISTS
}
function check_service_exists {
EXISTS=$(echo "$SERVICES_RES" | grep -w ${1} | wc -l)
echo $EXISTS
}
function check_app_exists {
EXISTS=$(cf apps | grep ${1} | wc -l)
echo $EXISTS
}
# ${1} service name in marketplace
# ${2} service plan in marketplace
# ${3} (optional) name for service to be created; my${1} if not provided
function install_service {
if [ -z "$3" ];
then
NAME_FOR_SERVICE="my$1"
else
NAME_FOR_SERVICE="$3"
fi
EXISTS=$(check_service_exists "${NAME_FOR_SERVICE}")
if [ $EXISTS -eq 0 ]
then
echo "Creating service ${NAME_FOR_SERVICE}"
NAME="$1"
PLAN="$2"
echo $NAME $PLAN $NAME_FOR_SERVICE
RETURN=("$(cf create-service ${NAME} "${PLAN}" "${NAME_FOR_SERVICE}")")
check_return
else
echo "Service ${NAME_FOR_SERVICE} already exists"
fi
}
function get_default_domain {
DEFAULT_DOMAIN=($(cf domains | head -n 3 | tail -1))
DOMAIN=${DEFAULT_DOMAIN[0]}
echo ${DOMAIN}
}
function get_backend_endpoint {
DOMAIN=$(get_default_domain)
echo "http://${1}-backend.${DOMAIN}"
}
function get_dashboard_endpoint {
DOMAIN=$(get_default_domain)
echo "https://${1}-dashboard.${DOMAIN}"
}
function provide_backend_endpoint {
ADDRESS=$(get_backend_endpoint ${1})
SOME_SERVICE="{\"host\":\"${ADDRESS}\"}"
EXISTS=$(check_service_exists backend-ups)
if [ $EXISTS -eq 0 ]
then
echo "Creating backend-ups $SOME_SERVICE"
RETURN=("$(cf cups backend-ups -p ${SOME_SERVICE})")
else
echo "Updating backend-ups $SOME_SERVICE"
RETURN=("$(cf uups backend-ups -p ${SOME_SERVICE})")
fi
check_return
}
function provide_dashboard_endpoint {
ADDRESS=$(get_dashboard_endpoint ${1})
DASHBOARD_SERVICE="{\"host\":\"${ADDRESS}\",\"strictSSL\":${DASHBOARD_STRICT_SSL}}"
EXISTS=$(check_service_exists dashboard-endpoint-ups)
if [ $EXISTS -eq 0 ]
then
echo "Creating dashboard-endpoint-ups $DASHBOARD_SERVICE"
RETURN=("$(cf cups dashboard-endpoint-ups -p ${DASHBOARD_SERVICE})")
else
echo "Updating dashboard-endpoint-ups $DASHBOARD_SERVICE"
RETURN=("$(cf uups dashboard-endpoint-ups -p ${DASHBOARD_SERVICE})")
fi
check_return
}
function provide_kafka_configuration {
KAFKA_CONF="{\"topic\":\"metrics\",\"enabled\":true,\"partitions\":1,\"replication\":1,\"timeout_ms\":10000}"
EXISTS=$(check_service_exists kafka-ups)
if [ $EXISTS -eq 0 ]
then
echo "Creating kafka-ups $KAFKA_CONF"
cf cups kafka-ups -p ${KAFKA_CONF}
else
echo "Updating kafka-ups $KAFKA_CONF"
cf uups kafka-ups -p ${KAFKA_CONF}
fi
}
function provide_mail_credentials {
MAIL_SERVICE="{\"sender\":\"${MAIL_SERVICE_SENDER}\"}"
EXISTS=$(check_service_exists mail-ups)
if [ $EXISTS -eq 0 ]
then
echo "Creating mail-ups $MAIL_SERVICE"
RETURN=("$(cf cups mail-ups -p ${MAIL_SERVICE})")
else
echo "Updating mail-ups $MAIL_SERVICE"
RETURN=("$(cf uups mail-ups -p ${MAIL_SERVICE})")
fi
check_return
}
function provide_websocket_credentials {
WEBSOCKET_SERVICE="{\"username\":\"${WEBSOCKET_SERVICE_USERNAME}\",\"password\":\"${WEBSOCKET_SERVICE_PASSWORD}\"}"
EXISTS=$(check_service_exists websocket-ups)
if [ $EXISTS -eq 0 ]
then
echo "Creating websocket-ups $WEBSOCKET_SERVICE"
RETURN=("$(cf cups websocket-ups -p ${WEBSOCKET_SERVICE})")
else
echo "websocket-ups already exists."
fi
check_return
}
function provide_rule_engine_credentials {
RULE_ENGINE_SERVICE="{\"username\":\"${RULE_ENGINE_SERVICE_USERNAME}\",\"password\":\"${RULE_ENGINE_SERVICE_PASSWORD}\"}"
EXISTS=$(check_service_exists rule-engine-credentials-ups)
if [ $EXISTS -eq 0 ]
then
echo "Creating rule-engine-credentials-ups $RULE_ENGINE_SERVICE"
RETURN=("$(cf cups rule-engine-credentials-ups -p ${RULE_ENGINE_SERVICE})")
else
echo "rule-engine-credentials-ups already exists."
fi
check_return
}
function provide_gateway_credentials {
GATEWAY_SERVICE="{\"username\":\"${GATEWAY_SERVICE_USERNAME}\",\"password\":\"${GATEWAY_SERVICE_PASSWORD}\"}"
EXISTS=$(check_service_exists gateway-credentials-ups)
if [ $EXISTS -eq 0 ]
then
echo "Creating gateway-credentials-ups $GATEWAY_SERVICE"
RETURN=("$(cf cups gateway-credentials-ups -p ${GATEWAY_SERVICE})")
else
echo "gateway-credentials-ups already exists"
fi
check_return
}
function provide_dashboard_security_credentials {
PRIVATE_PATH="\"./keys/private.pem\""
PUBLIC_PATH="\"./keys/public.pem\""
SECURITY_CREDENTIALS="{\"private_pem_path\":${PRIVATE_PATH},\"public_pem_path\":${PUBLIC_PATH},\"captcha_test_code\":\"${CAPTCHA_TEST_CODE}\",\"interaction_token_permision_key\":\"${INTERACTION_TOKEN_PERMISSION_KEY}\"}"
EXISTS=$(check_service_exists dashboard-security-ups)
if [ $EXISTS -eq 0 ]
then
echo "Creating dashboard-security-ups $SECURITY_CREDENTIALS"
RETURN=("$(cf cups dashboard-security-ups -p ${SECURITY_CREDENTIALS})")
else
echo "Updating dashboard-security-ups $SECURITY_CREDENTIALS"
RETURN=("$(cf uups dashboard-security-ups -p ${SECURITY_CREDENTIALS})")
fi
check_return
}
function provide_captcha_credentials {
CAPTCHA_CREDENTIALS="{\"siteKey\":\"${CAPTCHA_CREDENTIALS_SITE_KEY}\",\"secretKey\":\"${CAPTCHA_CREDENTIALS_SECRET_KEY}\",\"enabled\":\"${CAPTCHA_ENABLED}\"}"
EXISTS=$(check_service_exists recaptcha-ups)
if [ $EXISTS -eq 0 ]
then
echo "Creating recaptcha-ups $CAPTCHA_CREDENTIALS"
RETURN=("$(cf cups recaptcha-ups -p ${CAPTCHA_CREDENTIALS})")
else
echo "Updating recaptcha-ups $CAPTCHA_CREDENTIALS"
RETURN=("$(cf uups recaptcha-ups -p ${CAPTCHA_CREDENTIALS})")
fi
check_return
}
function deploy_backend {
APP_NAME="${1}-backend"
EXISTS=$(check_app_exists ${APP_NAME})
if [ $EXISTS -eq 1 ]
then
RETURN=("$(cf d ${APP_NAME} -f)")
check_return
fi
if [ "x${DOWNLOAD_SOURCES_FROM_GITHUB}" = "x1" ]
then
git clone ${GITHUB_SPACE}/iotanalytics-backend.git
fi
echo 'Deploying iotanalytics-backend'
DOMAIN=$(get_default_domain)
cd iotanalytics-backend/ &&
gradle clean build &&
cf push ${APP_NAME} -d ${DOMAIN} &&
check_exit_code
cd ..
}
function set_websocket_keys {
mkdir -p security &&
cp ${PUBLIC_PEM_PATH} ./security/public.pem
if [ "$?" -ne "0" ]
then
echo "Public RSA key not found in ${PUBLIC_PEM_PATH}. Unable to deploy Dashboard application."
exit 1
fi
}
function deploy_websocket {
APP_NAME="${1}-websocket"
EXISTS=$(check_app_exists ${APP_NAME})
if [ $EXISTS -eq 1 ]
then
RETURN=("$(cf d ${APP_NAME} -f)")
check_return
fi
if [ "x${DOWNLOAD_SOURCES_FROM_GITHUB}" = "x1" ]
then
git clone ${GITHUB_SPACE}/iotanalytics-websocket-server.git
fi
cd iotanalytics-websocket-server &&
set_websocket_keys &&
DOMAIN=$(get_default_domain)
RETURN=("$(cf push ${APP_NAME} -d ${DOMAIN})")
check_return
cd ..
}
function deploy_rule_engine_app {
APP_NAME="${1}-rule-engine"
EXISTS=$(check_app_exists ${APP_NAME})
if [ $EXISTS -eq 1 ]
then
RETURN=("$(cf d ${APP_NAME} -f)")
check_return
fi
if [ "x${DOWNLOAD_SOURCES_FROM_GITHUB}" = "x1" ]
then
git clone ${GITHUB_SPACE}/iotanalytics-gearpump-rule-engine.git
fi
cd "iotanalytics-gearpump-rule-engine" &&
echo "Deploying rule engine app" &&
./cf-deploy.sh
check_exit_code
cd ..
}
function set_dashboard_keys {
mkdir -p keys &&
cp ${PRIVATE_PEM_PATH} ./public-interface/keys/private.pem
if [ "$?" -ne "0" ]
then
echo "Private RSA key not found in ${PRIVATE_PEM_PATH}. Unable to deploy Dashboard application."
exit 1
fi
cp ${PUBLIC_PEM_PATH} ./public-interface/keys/public.pem
if [ "$?" -ne "0" ]
then
echo "Public RSA key not found in ${PUBLIC_PEM_PATH}. Unable to deploy Dashboard application."
exit 1
fi
}
function deploy_frontend {
APP_NAME="${1}-dashboard"
EXISTS=$(check_app_exists ${APP_NAME})
if [ $EXISTS -eq 1 ]
then
RETURN=("$(cf d ${APP_NAME} -f)")
check_return
fi
if [ "x${DOWNLOAD_SOURCES_FROM_GITHUB}" = "x1" ]
then
git clone ${GITHUB_SPACE}/iotanalytics-dashboard.git
fi
cd iotanalytics-dashboard &&
mkdir -p ./public-interface/keys &&
set_dashboard_keys &&
cd ./public-interface &&
npm -d install #NPM too often fail at the first time
cd .. &&
./cf-deploy.sh
check_exit_code
cd ..
}
function create_space {
EXISTS=$(check_space_exists ${1})
if [ $EXISTS -eq 0 ]
then
echo "Creating space: ${1} ..."
RETURN=("$(cf create-space "${1}")")
check_return
RETURN=("$(cf t -s "${1}")")
check_return
else
echo "Space ${1} already exists"
RETURN=("$(cf t -s "${1}")")
check_return
fetch_services
fi
}
function deploy_services {
install_service postgresql93 free mypostgres &&
install_service zookeeper shared &&
install_service redis28 free myredis &&
install_service hdfs bare &&
install_service kafka shared &&
install_service hbase bare &&
install_service smtp shared &&
install_service kerberos shared kerberos-service &&
if [ "x${DEPLOY_RULE_ENGINE}" = "x1" ]
then
install_service gearpump "1 worker"
fi
provide_backend_endpoint ${1} &&
provide_dashboard_endpoint ${1} &&
provide_kafka_configuration &&
provide_mail_credentials &&
provide_websocket_credentials &&
provide_captcha_credentials &&
provide_rule_engine_credentials &&
provide_gateway_credentials &&
provide_dashboard_security_credentials &&
echo "All services created or updated successfully!"
}
function deploy_apps {
if [ "x${DOWNLOAD_SOURCES_FROM_GITHUB}" = "x1" ]
then
rm -rf temp/
fi
mkdir -p temp &&
cd temp &&
deploy_frontend ${1} &&
deploy_backend ${1}
if [ "x${DEPLOY_RULE_ENGINE}" = "x1" ]
then
deploy_rule_engine_app ${1}
fi
if [ "x${DEPLOY_WEBSOCKET}" = "x1" ]
then
deploy_websocket ${1}
fi
cd ..
rm -rf temp/ || sudo rm -rf temp/
echo "All applications were deployed successfully! :D"
}
function deploy {
create_space ${1} &&
deploy_services ${1} &&
DEPLOY_APPS=${2}
if [ ${DEPLOY_APPS} -eq 1 ]
then
deploy_apps ${1}
fi
}
function destroy {
clear_services
EXISTS=$(check_space_exists ${1})
if [ $EXISTS -eq 1 ]
then
RETURN=("$(cf delete-space -f "$1")")
check_return
else
echo "Space ${1} not found."
fi
}
function check_return {
echo $RETURN
FAILED=$(echo $RETURN | grep "FAILED" | wc -l)
if [ "$FAILED" -eq 1 ]
then
exit 1
fi
}
function check_exit_code {
if [ $? -eq 1 ]
then
exit 1
fi
}
function fetch_services {
SERVICES_RES=$(cf services)
}
function clear_services {
SERVICES_RES=""
}
CONFIGURATION_FILE=${1}
if [ ! -f ${CONFIGURATION_FILE} ]
then
usage
fi
echo "Reading configuration file ${CONFIGURATION_FILE}"
source ${CONFIGURATION_FILE}
if [ "x${CF_SPACE_NAME}" = "x" ]
then
usage
fi
if [ "x${FORCE}" = "x1" ]
then
destroy ${CF_SPACE_NAME}
fi
deploy ${CF_SPACE_NAME} ${DEPLOY_APPS}