forked from apiman/apiman-deployer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeployer_local.sh
executable file
·501 lines (447 loc) · 24.5 KB
/
deployer_local.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
#!/bin/sh
#
# Instructions to install locally Apiman Manager, Apiman Gateway, ElasticSearch and Keycloak Server
#
#
# Set versions of Apiman & ElasticSearch, wildfly and directory to install the components
#
read -p "Directory to install the components (default: home directory): " INSTALL_DIRECTORY
INSTALL_DIRECTORY=${INSTALL_DIRECTORY:-~}
echo "Components will be installed here : $INSTALL_DIRECTORY"
read -p "Please enter the version of Apiman to be installed (default: 1.2.5.Final): " APIMAN_VERSION
APIMAN_VERSION=${APIMAN_VERSION:-1.2.5.Final}
echo $APIMAN_VERSION
read -p "Please enter the version of ElasticSearch to be installed (default: 1.7.2): " ELASTIC_VERSION
ELASTIC_VERSION=${ELASTIC_VERSION:-1.7.2}
echo $ELASTIC_VERSION
read -p "Version of WildFly (default: 10.0.0.Final):" WILDFLY_VERSION
WILDFLY_VERSION=${WILDFLY_VERSION:-10.0.0.Final}
echo $WILDFLY_VERSION
echo ""
echo "Next steps ..."
unamestr=`uname`
COMPONENT=""
while [[ "$COMPONENT" != "5" ]]; do
echo "###############################################################"
echo "# Welcome to the apiman deployer. Use this utility to deploy #"
echo "# a single apiman component onto a local system. #"
echo "# The utility will loop until you select EXIT. #"
echo "# #"
echo "# NOTE: this script deploys apiman version $APIMAN_VERSION #"
echo "###############################################################"
echo ""
echo ""
echo "Currently supported components:"
echo " 0. All in one (Manager, h2, Gateway, Elasticsearch & Keycloak)"
echo " 1. Elasticsearch (for metrics)"
echo " 2. Keycloak Authentication Server"
echo " 3. apiman: API Gateway"
echo " 4. apiman: API Manager"
echo " 5. Exit"
read -p "Which component would you like to deploy? " COMPONENT
if [ "$COMPONENT" = "0" ]
then
echo "###############################################################"
echo "# Installing Apiman All in One ... #"
echo "###############################################################"
echo ""
if [ -d "$INSTALL_DIRECTORY/apiman-all-$APIMAN_VERSION" ]; then
rm -rf $INSTALL_DIRECTORY/apiman-all-$APIMAN_VERSION
fi
mkdir -p $INSTALL_DIRECTORY/apiman-all-$APIMAN_VERSION
cd $INSTALL_DIRECTORY/apiman-all-$APIMAN_VERSION
curl http://downloads.jboss.org/wildfly/${WILDFLY_VERSION}/wildfly-${WILDFLY_VERSION}.zip -o wildfly-${WILDFLY_VERSION}.zip
curl http://downloads.jboss.org/apiman/$APIMAN_VERSION/apiman-distro-wildfly9-$APIMAN_VERSION-overlay.zip -o apiman-distro-wildfly9-$APIMAN_VERSION-overlay.zip
unzip wildfly-${WILDFLY_VERSION}.zip
unzip -o apiman-distro-wildfly9-$APIMAN_VERSION-overlay.zip -d wildfly-${WILDFLY_VERSION}
cd wildfly-${WILDFLY_VERSION}
#
# Use default binding offset which is '0'
#
if [[ "$unamestr" == 'Linux' ]]; then
sed -i "s/jboss.socket.binding.port-offset:0/jboss.socket.binding.port-offset:0/g" standalone/configuration/standalone-apiman.xml
elif [[ "$unamestr" == 'Darwin' ]]; then
sed -i '' "s/jboss.socket.binding.port-offset:0/jboss.socket.binding.port-offset:0/g" standalone/configuration/standalone-apiman.xml
fi
echo "######################################################################"
echo "# Installation complete. You can now start up apiman #"
echo "# with the following commands: #"
echo "# #"
echo " cd $INSTALL_DIRECTORY/apiman-all-$APIMAN_VERSION/wildfly-${WILDFLY_VERSION}"
echo " ./bin/standalone.sh -b 0.0.0.0 -c standalone-apiman.xml"
echo "# #"
echo "# Apiman Manager : http://localhost:8080/apimanui #"
echo "# Keycloak UI : http://localhost:8080/auth/admin/master/console #"
echo "# User : admin and password : admin123! #"
echo "# #"
echo "######################################################################"
fi
if [ "$COMPONENT" = "1" ]
then
echo "###############################################################"
echo "# Installing Elasticsearch $ELASTIC_VERSION for apiman... #"
echo "###############################################################"
if [ -d "$INSTALL_DIRECTORY/apiman-elasticsearch-$ELASTIC_VERSION" ]; then
rm -rf $INSTALL_DIRECTORY/apiman-elasticsearch-$ELASTIC_VERSION
fi
mkdir -p $INSTALL_DIRECTORY/apiman-elasticsearch-$ELASTIC_VERSION
cd $INSTALL_DIRECTORY/apiman-elasticsearch-$ELASTIC_VERSION
curl https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-$ELASTIC_VERSION.zip -o elasticsearch-$ELASTIC_VERSION.zip
unzip elasticsearch-$ELASTIC_VERSION.zip
cd elasticsearch-$ELASTIC_VERSION
./bin/plugin -i elasticsearch/marvel/latest
echo 'marvel.agent.enabled: false' >> ./config/elasticsearch.yml
sed -i "s/#cluster.name: elasticsearch/cluster.name: apiman/g" config/elasticsearch.yml
echo "####################################################################"
echo "# Installation complete. You can now start up Elasticsearch #"
echo "# with the following command: #"
echo "# #"
echo " $INSTALL_DIRECTORY/apiman-elasticsearch-$ELASTIC_VERSION/elasticsearch-$ELASTIC_VERSION/bin/elasticsearch"
echo "# #"
echo "# or add the -d option to start Elasticsearch in the background. #"
echo "# #"
echo "# Please note: SSL and Authentication have *not* been enabled. #"
echo "# We recommend you enable these feature in elasticsearch if the #"
echo "# network between apiman and Elasticsearch is not secure. #"
echo "####################################################################"
echo ""
fi
if [ "x$COMPONENT" = "x2" ]
then
echo "###############################################################"
echo "# Installing Keycloak for apiman... #"
echo "###############################################################"
echo ""
if [ -d "$INSTALL_DIRECTORY/apiman-keycloak-$APIMAN_VERSION" ]; then
rm -rf $INSTALL_DIRECTORY/apiman-keycloak-$APIMAN_VERSION
fi
mkdir -p $INSTALL_DIRECTORY/apiman-keycloak-$APIMAN_VERSION
cd $INSTALL_DIRECTORY/apiman-keycloak-$APIMAN_VERSION
curl http://downloads.jboss.org/wildfly/${WILDFLY_VERSION}/wildfly-${WILDFLY_VERSION}.zip -o wildfly-${WILDFLY_VERSION}.zip
curl http://downloads.jboss.org/apiman/$APIMAN_VERSION/apiman-distro-wildfly9-$APIMAN_VERSION-overlay.zip -o apiman-distro-wildfly9-$APIMAN_VERSION-overlay.zip
unzip wildfly-${WILDFLY_VERSION}.zip
unzip -o apiman-distro-wildfly9-$APIMAN_VERSION-overlay.zip -d wildfly-${WILDFLY_VERSION}
cd wildfly-${WILDFLY_VERSION}
rm -f standalone/deployments/apiman*
#
# Change the binding port offset to avoid conflicts
#
# Apiman Manager offset: 0 (-> 8080, 8443)
# Apiman Gateway offset: 100 (-> 8180, 8543)
# Apiman Keycloak Server offset: 200 (-> 8280, 8643)
#
if [[ "$unamestr" == 'Linux' ]]; then
sed -i "s/jboss.socket.binding.port-offset:0/jboss.socket.binding.port-offset:200/g" standalone/configuration/standalone-apiman.xml
elif [[ "$unamestr" == 'Darwin' ]]; then
sed -i '' "s/jboss.socket.binding.port-offset:0/jboss.socket.binding.port-offset:200/g" standalone/configuration/standalone-apiman.xml
fi
echo "####################################################################"
echo "# Installation complete. You can now start up Keycloak for apiman #"
echo "# with the following commands: #"
echo "# #"
echo " cd ~/apiman-keycloak-$APIMAN_VERSION/wildfly-9.0.2.Final"
echo " ./bin/standalone.sh -b 0.0.0.0 -c standalone-apiman.xml"
echo "# #"
echo "####################################################################"
fi
if [ "x$COMPONENT" = "x3" ]
then
echo "###############################################################"
echo "# Installing apiman : API Gateway... #"
echo "###############################################################"
echo ""
#
# Step 0: Configure Gateway Public Endpoint
#
echo "You need to let us know the public endpoint for the API"
echo "Gateway. The public endpoint is the URL that an API client"
echo "would use to connect to the API Gateway. An example is:"
echo " https://localhost:8543/apiman-gateway/"
echo ""
read -p "Public Endpoint (default: https://localhost:8543/apiman-gateway/) : " GATEWAY_PUBLIC_ENDPOINT
GATEWAY_PUBLIC_ENDPOINT=${GATEWAY_PUBLIC_ENDPOINT:-https://localhost:8543/apiman-gateway}
#
# Step 1: Setup URL to access Keycloak Security Server (by default it runs inside the Apiman Manager - https://localhostg:8443/auth)
#
echo ""
echo ""
echo "Now you need to tell us where your Keycloak authentication"
echo "server is located. This should be in the form of a URL."
echo "An example might be:"
echo " https://localhost:8443/auth"
echo ""
read -p "Keycloak URL (default https://localhost:8443/auth for local usage): " KEYCLOAK_URL
KEYCLOAK_URL=${KEYCLOAK_URL:-https://localhost:8443/auth}
KEYCLOAK_URL_ESC="$(echo $KEYCLOAK_URL | sed 's/[\/]/\\\//g')"
echo "Keycloak URL : $KEYCLOAK_URL; escaped : $KEYCLOAK_URL_ESC"
#
# Step 2: Setup URL to access ElasticSearch Server - https://localhost:9200/
#
echo ""
echo ""
echo "Finally, please clue us in on the location of your Elasticsearch"
echo "instance. Please include the port - Elasticsearch typically"
echo "listens on port 9200."
echo "An example might be:"
echo " http://localhost:9200"
echo ""
read -p "Elastic URL (default: http://localhost:9200): " ELASTIC_URL
ELASTIC_URL=${ELASTIC_URL:-http://localhost:9200}
if [[ "$unamestr" == 'Linux' ]]; then
ES_PROTOCOL=`echo $ELASTIC_URL | sed -r 's/(https?).*/\1/g'`
ES_HOST=`echo $ELASTIC_URL | sed -r 's/https?:\/\/([^\:^\/]+)\:?[0-9]*\/?.*/\1/g'`
ES_PORT=`echo $ELASTIC_URL | sed -r 's/https?\:\/\/[^\:]+\:?([0-9]+)?.*/\1/g'`
elif [[ "$unamestr" == 'Darwin' ]]; then
ES_PROTOCOL=`echo $ELASTIC_URL | sed -E 's/(https?).*/\1/g'`
ES_HOST=`echo $ELASTIC_URL | sed -E 's/https?:\/\/([^\:^\/]+)\:?[0-9]*\/?.*/\1/g'`
ES_PORT=`echo $ELASTIC_URL | sed -E 's/https?\:\/\/[^\:]+\:?([0-9]+)?.*/\1/g'`
fi
echo ""
echo "Thanks! Will use the following elasticsearch info:"
echo "---------------------------------------------------------"
echo " protocol: $ES_PROTOCOL"
echo " host: $ES_HOST"
echo " port: $ES_PORT"
echo "---------------------------------------------------------"
echo ""
echo ""
#
# Step 3: Download and unzip Wildfly, Apiman
#
if [ -d "$INSTALL_DIRECTORY/apiman-gateway-$APIMAN_VERSION" ]; then
rm -rf $INSTALL_DIRECTORY/apiman-gateway-$APIMAN_VERSION
fi
mkdir $INSTALL_DIRECTORY/apiman-gateway-$APIMAN_VERSION
cd $INSTALL_DIRECTORY/apiman-gateway-$APIMAN_VERSION
curl http://downloads.jboss.org/wildfly/${WILDFLY_VERSION}/wildfly-${WILDFLY_VERSION}.zip -o wildfly-${WILDFLY_VERSION}.zip
curl http://downloads.jboss.org/apiman/$APIMAN_VERSION/apiman-distro-wildfly9-$APIMAN_VERSION-overlay.zip -o apiman-distro-wildfly9-$APIMAN_VERSION-overlay.zip
unzip wildfly-${WILDFLY_VERSION}.zip
unzip -o apiman-distro-wildfly9-$APIMAN_VERSION-overlay.zip -d wildfly-${WILDFLY_VERSION}
cd wildfly-${WILDFLY_VERSION}
#
# Step 4: Remove WAR files not required
#
rm -f standalone/deployments/apiman-ds.xml
rm -f standalone/deployments/apiman-es.war
rm -f standalone/deployments/apiman.war
rm -f standalone/deployments/apimanui.war
#
# Step 5. Disabling the keycloak Server as we will use an external
#
# <subsystem xmlns="urn:jboss:domain:keycloak-server:1.1">
# <web-context>auth</web-context>
# </subsystem>
if [[ "$unamestr" == 'Linux' ]]; then
sed -i "s/<kc\:auth-server-url>\/auth<\/kc\:auth-server-url>/<kc\:auth-server-url>$KEYCLOAK_URL_ESC<\/kc\:auth-server-url>/g" standalone/configuration/standalone-apiman.xml
elif [[ "$unamestr" == 'Darwin' ]]; then
sed -i '' "s/\(<auth-server-url>\).*\(<\/auth-server-url\)/\1$KEYCLOAK_URL_ESC\2/" standalone/configuration/standalone-apiman.xml
fi
#
# Step 6. Configure External ElasticSearch Server
#
sed -i '' "s/apiman.es.protocol=.*$/apiman.es.protocol=$ES_PROTOCOL/g" standalone/configuration/apiman.properties
sed -i '' "s/apiman.es.host=.*$/apiman.es.host=$ES_HOST/g" standalone/configuration/apiman.properties
sed -i '' "s/apiman.es.port=.*$/apiman.es.port=$ES_PORT/g" standalone/configuration/apiman.properties
#
# Step 7. Comment the apiman-manager parameters
#
if [[ "$unamestr" == 'Linux' ]]; then
sed -i "s/^apiman-manager/#apiman-manager/g" standalone/configuration/apiman.properties
elif [[ "$unamestr" == 'Darwin' ]]; then
sed -i '' "s/^apiman-manager/#apiman-manager/g" standalone/configuration/apiman.properties
fi
#
# Step 8. Add the public endpoint of the gateway
#
echo "" >> standalone/configuration/apiman.properties
echo "# The public endpoint for accessing the API Gateway" >> standalone/configuration/apiman.properties
echo "apiman-gateway.public-endpoint=$GATEWAY_PUBLIC_ENDPOINT" >> standalone/configuration/apiman.properties
#
# Step 9: Change the binding port offset to avoid conflicts
#
# Apiman Manager offset: 0 (-> 8080, 8443)
# Apiman Gateway offset: 100 (-> 8180, 8543)
# Apiman Keycloak Server offset: 200 (-> 8280, 8643)
#
if [[ "$unamestr" == 'Linux' ]]; then
sed -i "s/jboss.socket.binding.port-offset:0/jboss.socket.binding.port-offset:100/g" standalone/configuration/standalone-apiman.xml
elif [[ "$unamestr" == 'Darwin' ]]; then
sed -i '' "s/jboss.socket.binding.port-offset:0/jboss.socket.binding.port-offset:100/g" standalone/configuration/standalone-apiman.xml
fi
echo "####################################################################"
echo "# Installation complete. You can now start up apiman : API Gateway #"
echo "# with the following commands: #"
echo "# #"
echo " cd ~/apiman-gateway-$APIMAN_VERSION/wildfly-9.0.2.Final"
echo " ./bin/standalone.sh -b 0.0.0.0 -c standalone-apiman.xml"
echo "# #"
echo "####################################################################"
fi
if [ "$COMPONENT" = "4" ]
then
#
# Step 0: Configure URL of Keycloak
#
echo "###############################################################"
echo "# Installing apiman : API Manager... #"
echo "###############################################################"
echo ""
echo ""
echo "Now you need to tell us where your Keycloak authentication"
echo "server is located. This should be in the form of a URL."
echo "An example might be:"
echo " https://localhost:8443/auth"
echo ""
read -p "Keycloak URL (default https://localhost:8443/auth for local usage): " KEYCLOAK_URL
KEYCLOAK_URL=${KEYCLOAK_URL:-https://localhost:8443/auth}
KEYCLOAK_URL_ESC="$(echo $KEYCLOAK_URL | sed 's/[\/]/\\\//g')"
echo "Keycloak URL : $KEYCLOAK_URL; escaped : $KEYCLOAK_URL_ESC"
#
# Step 1 : Configure Database (h2, MySQL, PostGresQL)
#
echo ""
echo ""
echo "We'll help you connect to your database. Please provide us"
echo "with the database connection information we'll need:"
echo ""
echo "Database Type:"
echo " 1. mysql"
echo " 2. postresql"
echo " 3. h2 (default)"
read -p "Choose: " DATABASE_TYPE
DATABASE_TYPE=${DATABASE_TYPE:-3}
echo "Database selected : $DATABASE_TYPE !!"
if [ "$DATABASE_TYPE" = "1" ] || [ "$DATABASE_TYPE" = "2" ]
then
read -p "DB host/ip: " DATABASE_HOST
read -p "DB port: " DATABASE_PORT
read -p "DB username: " DATABASE_USER
read -p "DB password: " -s DATABASE_PASSWORD
echo ""
read -p " again: " -s DATABASE_PASSWORD_REPEAT
if [ "x$DATABASE_PASSWORD" = "x$DATABASE_PASSWORD_REPEAT" ]
then
echo "OK great, thanks."
else
echo "Passwords don't match! Exiting..."
exit 1
fi
fi
#
# Step 2 : Configure ElasticSearch connection
#
echo ""
echo ""
echo "Finally, please clue us in on the location of your Elasticsearch"
echo "instance. Please include the port - Elasticsearch typically"
echo "listens on port 9200."
echo "An example might be:"
echo " http://localhost:9200"
echo ""
read -p "Elastic URL (default: http://localhost:9200): " ELASTIC_URL
ELASTIC_URL=${ELASTIC_URL:-http://localhost:9200}
if [[ "$unamestr" == 'Linux' ]]; then
ES_PROTOCOL=`echo $ELASTIC_URL | sed -r 's/(https?).*/\1/g'`
ES_HOST=`echo $ELASTIC_URL | sed -r 's/https?:\/\/([^\:^\/]+)\:?[0-9]*\/?.*/\1/g'`
ES_PORT=`echo $ELASTIC_URL | sed -r 's/https?\:\/\/[^\:]+\:?([0-9]+)?.*/\1/g'`
elif [[ "$unamestr" == 'Darwin' ]]; then
ES_PROTOCOL=`echo $ELASTIC_URL | sed -E 's/(https?).*/\1/g'`
ES_HOST=`echo $ELASTIC_URL | sed -E 's/https?:\/\/([^\:^\/]+)\:?[0-9]*\/?.*/\1/g'`
ES_PORT=`echo $ELASTIC_URL | sed -E 's/https?\:\/\/[^\:]+\:?([0-9]+)?.*/\1/g'`
fi
echo ""
echo "Thanks! Will use the following elasticsearch info:"
echo "---------------------------------------------------------"
echo " protocol: $ES_PROTOCOL"
echo " host: $ES_HOST"
echo " port: $ES_PORT"
echo "---------------------------------------------------------"
echo ""
echo ""
#
# Step 3. Download and unzip Wildfly, Apiman
#
if [ -d "$INSTALL_DIRECTORY/apiman-manager-$APIMAN_VERSION" ]; then
rm -rf $INSTALL_DIRECTORY/apiman-manager-$APIMAN_VERSION
fi
mkdir $INSTALL_DIRECTORY/apiman-manager-$APIMAN_VERSION
cd $INSTALL_DIRECTORY/apiman-manager-$APIMAN_VERSION
curl http://downloads.jboss.org/wildfly/${WILDFLY_VERSION}/wildfly-${WILDFLY_VERSION}.zip -o wildfly-${WILDFLY_VERSION}.zip
curl http://downloads.jboss.org/apiman/$APIMAN_VERSION/apiman-distro-wildfly9-$APIMAN_VERSION-overlay.zip -o apiman-distro-wildfly9-$APIMAN_VERSION-overlay.zip
unzip wildfly-${WILDFLY_VERSION}.zip
unzip -o apiman-distro-wildfly9-$APIMAN_VERSION-overlay.zip -d wildfly-${WILDFLY_VERSION}
cd wildfly-${WILDFLY_VERSION}
#
# Step 4. Remove the gateway war files
#
rm standalone/deployments/apiman-es.war
rm standalone/deployments/apiman-gateway-api.war
rm standalone/deployments/apiman-gateway.war
#
# Step 5. Comment the apiman-gateway parameters
#
if [[ "$unamestr" == 'Linux' ]]; then
sed -i "s/^apiman-gateway/#apiman-gateway/g" standalone/configuration/apiman.properties
elif [[ "$unamestr" == 'Darwin' ]]; then
sed -i '' "s/^apiman-gateway/#apiman-gateway/g" standalone/configuration/apiman.properties
fi
#
# Step 6. Configure External ElasticSearch Server
#
sed -i '' "s/apiman.es.protocol=.*$/apiman.es.protocol=$ES_PROTOCOL/g" standalone/configuration/apiman.properties
sed -i '' "s/apiman.es.host=.*$/apiman.es.host=$ES_HOST/g" standalone/configuration/apiman.properties
sed -i '' "s/apiman.es.port=.*$/apiman.es.port=$ES_PORT/g" standalone/configuration/apiman.properties
#
# Step 7. Setup the Database parameters (MySQL, PostgreSQL)
#
if [ "x$DATABASE_TYPE" = "x1" ]
then
HIBERNATE_DIALECT=org.hibernate.dialect.MySQL5Dialect
curl https://repo1.maven.org/maven2/mysql/mysql-connector-java/5.1.33/mysql-connector-java-5.1.33.jar -o ~/apiman-manager-$APIMAN_VERSION/wildfly-9.0.2.Final/standalone/deployments/mysql-connector-java-5.1.33-bin.jar
cp ~/apiman-manager-$APIMAN_VERSION/wildfly-9.0.2.Final/apiman/sample-configs/apiman-ds_mysql.xml ~/apiman-manager-$APIMAN_VERSION/wildfly-9.0.2.Final/standalone/deployments/apiman-ds.xml
sed -i "s/MYSQLSERVER/$DATABASE_HOST/g" ~/apiman-manager-$APIMAN_VERSION/wildfly-9.0.2.Final/standalone/deployments/apiman-ds.xml
sed -i "s/3306/$DATABASE_PORT/g" ~/apiman-manager-$APIMAN_VERSION/wildfly-9.0.2.Final/standalone/deployments/apiman-ds.xml
sed -i "s/^apiman.hibernate.dialect=.*$/apiman.hibernate.dialect=$HIBERNATE_DIALECT/g" ~/apiman-manager-$APIMAN_VERSION/wildfly-9.0.2.Final/standalone/configuration/apiman.properties
sed -i "s/DBUSER/$DATABASE_USER/g" ~/apiman-manager-$APIMAN_VERSION/wildfly-9.0.2.Final/standalone/deployments/apiman-ds.xml
sed -i "s/DBPASS/$DATABASE_PASSWORD/g" ~/apiman-manager-$APIMAN_VERSION/wildfly-9.0.2.Final/standalone/deployments/apiman-ds.xml
elif [ "x$DATABASE_TYPE" = "x2" ]
then
HIBERNATE_DIALECT=org.hibernate.dialect.PostgreSQLDialect
curl https://repo1.maven.org/maven2/org/postgresql/postgresql/9.3-1102-jdbc41/postgresql-9.3-1102-jdbc41.jar -o ~/apiman-manager-$APIMAN_VERSION/wildfly-9.0.2.Final/standalone/deployments/postgresql-9.3-1102.jdbc41.jar
cp ~/apiman-manager-$APIMAN_VERSION/wildfly-9.0.2.Final/apiman/sample-configs/apiman-ds_postgresql.xml ~/apiman-manager-$APIMAN_VERSION/wildfly-9.0.2.Final/standalone/deployments/apiman-ds.xml
sed -i "s/POSTGRESQLSERVER/$DATABASE_HOST/g" ~/apiman-manager-$APIMAN_VERSION/wildfly-9.0.2.Final/standalone/deployments/apiman-ds.xml
sed -i "s/5432/$DATABASE_PORT/g" ~/apiman-manager-$APIMAN_VERSION/wildfly-9.0.2.Final/standalone/deployments/apiman-ds.xml
sed -i "s/^apiman.hibernate.dialect=.*$/apiman.hibernate.dialect=$HIBERNATE_DIALECT/g" ~/apiman-manager-$APIMAN_VERSION/wildfly-9.0.2.Final/standalone/configuration/apiman.properties
sed -i "s/DBUSER/$DATABASE_USER/g" ~/apiman-manager-$APIMAN_VERSION/wildfly-9.0.2.Final/standalone/deployments/apiman-ds.xml
sed -i "s/DBPASS/$DATABASE_PASSWORD/g" ~/apiman-manager-$APIMAN_VERSION/wildfly-9.0.2.Final/standalone/deployments/apiman-ds.xml
fi
#
# Step 8. Change the binding port offset to avoid conflicts
#
# Apiman Manager offset: 0 (-> 8080, 8443)
# Apiman Gateway offset: 100 (-> 8180, 8543)
# Apiman Keycloak Server offset: 200 (-> 8280, 8643)
#
if [[ "$unamestr" == 'Linux' ]]; then
sed -i "s/jboss.socket.binding.port-offset:0/jboss.socket.binding.port-offset:0/g" standalone/configuration/standalone-apiman.xml
elif [[ "$unamestr" == 'Darwin' ]]; then
sed -i '' "s/jboss.socket.binding.port-offset:0/jboss.socket.binding.port-offset:0/g" standalone/configuration/standalone-apiman.xml
fi
#
# Step 9. Use External Keycloak Server. Can also be used for local access with this address https://localhost:8443/auth
#
if [[ "$unamestr" == 'Linux' ]]; then
sed -i "s/<kc\:auth-server-url>\/auth<\/kc\:auth-server-url>/<kc\:auth-server-url>$KEYCLOAK_URL_ESC<\/kc\:auth-server-url>/g" standalone/configuration/standalone-apiman.xml
elif [[ "$unamestr" == 'Darwin' ]]; then
sed -i '' "s/\(<auth-server-url>\).*\(<\/auth-server-url\)/\1$KEYCLOAK_URL_ESC\2/" standalone/configuration/standalone-apiman.xml
fi
echo "#######################################git@github.com:apiman/apiman-deployer.git#############################"
echo "# Installation complete. You can now start up apiman : API Manager #"
echo "# with the following commands: #"
echo "# #"
echo " cd $INSTALL_DIRECTORY/apiman-manager-$APIMAN_VERSION/wildfly-${WILDFLY_VERSION}"
echo " ./bin/standalone.sh -b 0.0.0.0 -c standalone-apiman.xml"
echo "# #"
echo "####################################################################"
fi
done