-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-build.sh
More file actions
executable file
·574 lines (506 loc) · 28.5 KB
/
pre-build.sh
File metadata and controls
executable file
·574 lines (506 loc) · 28.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
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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
#!/bin/bash
#
# Variables
#
# text
Cyan='\033[0;36m'
Yellow='\033[1;33m'
Red='\033[0;31m'
Orange='\033[0;33m'
Green='\033[0;32m'
BOLDGREEN='\033[1m'
BOLDRED='\033[1m'
NC='\033[0;0m'
EOL='\n'
SPACER='\n\n'
INDENT=' '
BOLD='\033[1m'
HAIR='\033[0m'
PWD=$(pwd)
projectID='base'
portNumber=''
octet=''
maintainLocalConfigs='false'
noInteraction='false'
function run_pre_build {
if [[ $noInteraction == 'false' ]]; then
printf "${SPACER}"
# check to maintain local settings files
if [[ -f "${PWD}/_config/docker/.docker.env" || -f "${PWD}/_config/drupal/settings.php" || -f "${PWD}/_config/drupal/services.yml" || -f "${PWD}/_config/ckan/portal.ini" || -f "${PWD}/_config/ckan/registry.ini" || -f "${PWD}/.env" || -f "${PWD}/_config/django/settings.py" || -f "${PWD}/docker/config/nginx/conf/.env.conf" ]]; then
read -r -p $'\n\n\033[0;31m Do you wish to maintain your local configuration files? (if No, backups will still be kept once in the backup/local_configs directory) [y/N]:\033[0;0m ' response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
maintainLocalConfigs='true'
else
maintainLocalConfigs='false'
fi
fi
printf "${SPACER}"
fi
if [[ "$(stat -L -c '%a' /var/run/docker.sock)" != "666" ]]; then
printf "${Cyan}${INDENT}Setting correct permissions for docker socket. Maybe prompt for admin password...${NC}${EOL}"
sudo chmod 666 /var/run/docker.sock
fi
# creat backup directory
if [[ ! -d "${PWD}/backup" ]]; then
mkdir ${PWD}/backup
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Create ${BOLDGREEN}${PWD}/backup${HAIR}${Green} directory: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Create ${BOLDRED}${PWD}/backup${HAIR}${Red} directory: FAIL${NC}${EOL}"
fi
else
printf "${Yellow}${INDENT}backup directory already exists: SKIPPING${NC}${EOL}"
fi
# create global backup directory
if [[ ! -d "/opt/tbs/docker/backup" ]]; then
printf "${Cyan}${INDENT}Creating global backup directy. Maybe prompt for admin password...${NC}${EOL}"
sudo mkdir -p /opt/tbs/docker/backup
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Create ${BOLDGREEN}/opt/tbs/docker/backup${HAIR}${Green} directory: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Create ${BOLDRED}/opt/tbs/docker/backup${HAIR}${Red} directory: FAIL${NC}${EOL}"
fi
if [[ ! -r "/opt/tbs/docker/backup" ]]; then
printf "${Cyan}${INDENT}Modify global backup directy permissions. Maybe prompt for admin password...${NC}${EOL}"
sudo chmod 777 -R /opt/tbs/docker/backup
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Set ${BOLDGREEN}/opt/tbs/docker/backup${HAIR}${Green} permissions to 777: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Set ${BOLDRED}/opt/tbs/docker/backup${HAIR}${Red} permissions to 777: FAIL${NC}${EOL}"
fi
fi
else
if [[ ! -r "/opt/tbs/docker/backup" ]]; then
printf "${Cyan}${INDENT}Modify global backup directy permissions. Maybe prompt for admin password...${NC}${EOL}"
sudo chmod 777 -R /opt/tbs/docker/backup
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Set ${BOLDGREEN}/opt/tbs/docker/backup${HAIR}${Green} permissions to 777: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Set ${BOLDRED}/opt/tbs/docker/backup${HAIR}${Red} permissions to 777: FAIL${NC}${EOL}"
fi
fi
printf "${Yellow}${INDENT}/opt/tbs/docker/backup directory already exists: SKIPPING${NC}${EOL}"
fi
# creat local config backup sub-directory
if [[ ! -d "${PWD}/backup/local_configs" ]]; then
mkdir ${PWD}/backup/local_configs
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Create ${BOLDGREEN}${PWD}/backup/local_configs${HAIR}${Green} directory: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Create ${BOLDRED}${PWD}/backup/local_configs${HAIR}${Red} directory: FAIL${NC}${EOL}"
fi
else
printf "${Yellow}${INDENT}${PWD}/backup/local_configs directory already exists: SKIPPING${NC}${EOL}"
fi
# creat postgres directory
if [[ ! -d "${PWD}/postgres" ]]; then
mkdir ${PWD}/postgres
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Create ${BOLDGREEN}${PWD}/postgres${HAIR}${Green} directory: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Create ${BOLDRED}${PWD}/postgres${HAIR}${Red} directory: FAIL${NC}${EOL}"
fi
else
printf "${Yellow}${INDENT}${PWD}/postgres directory already exists: SKIPPING${NC}${EOL}"
fi
# creat solr directory
if [[ ! -d "${PWD}/solr" ]]; then
mkdir ${PWD}/solr
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Create ${BOLDGREEN}${PWD}/solr${HAIR}${Green} directory: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Create ${BOLDRED}${PWD}/solr${HAIR}${Red} directory: FAIL${NC}${EOL}"
fi
else
printf "${Yellow}${INDENT}${PWD}/solr directory already exists: SKIPPING${NC}${EOL}"
fi
# creat redis directory
if [[ ! -d "${PWD}/redis" ]]; then
mkdir ${PWD}/redis
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Create ${BOLDGREEN}${PWD}/redis${HAIR}${Green} directory: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Create ${BOLDRED}${PWD}/redis${HAIR}${Red} directory: FAIL${NC}${EOL}"
fi
else
printf "${Yellow}${INDENT}${PWD}/redis directory already exists: SKIPPING${NC}${EOL}"
fi
# creat nginx directory
if [[ ! -d "${PWD}/nginx" ]]; then
mkdir ${PWD}/nginx
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Create ${BOLDGREEN}${PWD}/nginx${HAIR}${Green} directory: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Create ${BOLDRED}${PWD}/nginx${HAIR}${Red} directory: FAIL${NC}${EOL}"
fi
else
printf "${Yellow}${INDENT}${PWD}/nginx directory already exists: SKIPPING${NC}${EOL}"
fi
# create _config directories
if [[ ! -d "${PWD}/_config" ]]; then
mkdir ${PWD}/_config
fi
if [[ ! -d "${PWD}/_config/ckan" ]]; then
mkdir ${PWD}/_config/ckan
fi
if [[ ! -d "${PWD}/_config/django" ]]; then
mkdir ${PWD}/_config/django
fi
if [[ ! -d "${PWD}/_config/docker" ]]; then
mkdir ${PWD}/_config/docker
fi
if [[ ! -d "${PWD}/_config/drupal" ]]; then
mkdir ${PWD}/_config/drupal
fi
# copy .docker.env example to .docker.env
if [[ -f "${PWD}/_config/docker/.docker.env" ]]; then
cp ${PWD}/_config/docker/.docker.env ${PWD}/backup/local_configs/.docker.env
fi
if [[ $maintainLocalConfigs == "false" ]]; then
cp ${PWD}/_config_examples/docker/.docker.env ${PWD}/_config/docker/.docker.env
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Copy ${BOLDGREEN}${PWD}/_config_examples/docker/.docker.env${HAIR}${Green} to ${BOLDGREEN}${PWD}/_config/docker/.docker.env${HAIR}${Green}: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Copy ${BOLDRED}${PWD}/_config_examples/docker/.docker.env${HAIR}${Red} to ${BOLDRED}${PWD}/_config/docker/.docker.env${HAIR}${Red}: FAIL${NC}${EOL}"
fi
else
printf "${Yellow}${INDENT}Copy ${PWD}/_config_examples/docker/.docker.env to ${PWD}/_config/docker/.docker.env (maintain local settings set to true): SKIPPING${NC}${EOL}"
fi
# copy settings.php example to settings.php
if [[ -f "${PWD}/_config/drupal/settings.php" ]]; then
cp ${PWD}/_config/drupal/settings.php ${PWD}/backup/local_configs/settings.php
fi
if [[ -f "${PWD}/_config/drupal/blog_settings.php" ]]; then
cp ${PWD}/_config/drupal/blog_settings.php ${PWD}/backup/local_configs/blog_settings.php
fi
if [[ -f "${PWD}/_config/drupal/guides_settings.php" ]]; then
cp ${PWD}/_config/drupal/guides_settings.php ${PWD}/backup/local_configs/guides_settings.php
fi
if [[ -f "${PWD}/_config/drupal/sites.php" ]]; then
cp ${PWD}/_config/drupal/sites.php ${PWD}/backup/local_configs/sites.php
fi
if [[ $maintainLocalConfigs == "false" ]]; then
cp ${PWD}/_config_examples/drupal/settings.php ${PWD}/_config/drupal/settings.php
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Copy ${BOLDGREEN}${PWD}/_config_examples/drupal/settings.php${HAIR}${Green} to ${BOLDGREEN}${PWD}/_config/drupal/settings.php${HAIR}${Green}: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Copy ${BOLDRED}${PWD}/_config_examples/drupal/settings.php${HAIR}${Red} to ${BOLDRED}${PWD}/_config/drupal/settings.php${HAIR}${Red}: FAIL${NC}${EOL}"
fi
cp ${PWD}/_config_examples/drupal/blog_settings.php ${PWD}/_config/drupal/blog_settings.php
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Copy ${BOLDGREEN}${PWD}/_config_examples/drupal/blog_settings.php${HAIR}${Green} to ${BOLDGREEN}${PWD}/_config/drupal/blog_settings.php${HAIR}${Green}: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Copy ${BOLDRED}${PWD}/_config_examples/drupal/blog_settings.php${HAIR}${Red} to ${BOLDRED}${PWD}/_config/drupal/blog_settings.php${HAIR}${Red}: FAIL${NC}${EOL}"
fi
cp ${PWD}/_config_examples/drupal/guides_settings.php ${PWD}/_config/drupal/guides_settings.php
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Copy ${BOLDGREEN}${PWD}/_config_examples/drupal/guides_settings.php${HAIR}${Green} to ${BOLDGREEN}${PWD}/_config/drupal/guides_settings.php${HAIR}${Green}: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Copy ${BOLDRED}${PWD}/_config_examples/drupal/guides_settings.php${HAIR}${Red} to ${BOLDRED}${PWD}/_config/drupal/guides_settings.php${HAIR}${Red}: FAIL${NC}${EOL}"
fi
cp ${PWD}/_config_examples/drupal/sites.php ${PWD}/_config/drupal/sites.php
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Copy ${BOLDGREEN}${PWD}/_config_examples/drupal/sites.php${HAIR}${Green} to ${BOLDGREEN}${PWD}/_config/drupal/sites.php${HAIR}${Green}: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Copy ${BOLDRED}${PWD}/_config_examples/drupal/sites.php${HAIR}${Red} to ${BOLDRED}${PWD}/_config/drupal/sites.php${HAIR}${Red}: FAIL${NC}${EOL}"
fi
else
printf "${Yellow}${INDENT}Copy ${PWD}/_config_examples/drupal/settings.php to ${PWD}/_config/drupal/settings.php (maintain local settings set to true): SKIPPING${NC}${EOL}"
printf "${Yellow}${INDENT}Copy ${PWD}/_config_examples/drupal/blog_settings.php to ${PWD}/_config/drupal/blog_settings.php (maintain local settings set to true): SKIPPING${NC}${EOL}"
printf "${Yellow}${INDENT}Copy ${PWD}/_config_examples/drupal/guides_settings.php to ${PWD}/_config/drupal/guides_settings.php (maintain local settings set to true): SKIPPING${NC}${EOL}"
printf "${Yellow}${INDENT}Copy ${PWD}/_config_examples/drupal/sites.php to ${PWD}/_config/drupal/sites.php (maintain local settings set to true): SKIPPING${NC}${EOL}"
fi
# copy services.yml example to services.yml
if [[ -f "${PWD}/_config/drupal/services.yml" ]]; then
cp ${PWD}/_config/drupal/services.yml ${PWD}/backup/local_configs/services.yml
fi
if [[ $maintainLocalConfigs == "false" ]]; then
cp ${PWD}/_config_examples/drupal/services.yml ${PWD}/_config/drupal/services.yml
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Copy ${BOLDGREEN}${PWD}/_config_examples/drupal/services.yml${HAIR}${Green} to ${BOLDGREEN}${PWD}/_config/drupal/services.yml${HAIR}${Green}: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Copy ${BOLDRED}${PWD}/_config_examples/drupal/services.yml${HAIR}${Red} to ${BOLDRED}${PWD}/_config/drupal/services.yml${HAIR}${Red}: FAIL${NC}${EOL}"
fi
else
printf "${Yellow}${INDENT}Copy ${PWD}/_config_examples/drupal/services.yml to ${PWD}/_config/drupal/services.yml (maintain local settings set to true): SKIPPING${NC}${EOL}"
fi
# copy portal.ini example to portal.ini
if [[ -f "${PWD}/_config/ckan/portal.ini" ]]; then
cp ${PWD}/_config/ckan/portal.ini ${PWD}/backup/local_configs/portal.ini
fi
if [[ $maintainLocalConfigs == "false" ]]; then
cp ${PWD}/_config_examples/ckan/portal.ini ${PWD}/_config/ckan/portal.ini
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Copy ${BOLDGREEN}${PWD}/_config_examples/ckan/portal.ini${HAIR}${Green} to ${BOLDGREEN}${PWD}/_config/ckan/portal.ini${HAIR}${Green}: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Copy ${BOLDRED}${PWD}/_config_examples/ckan/portal.ini${HAIR}${Red} to ${BOLDRED}${PWD}/_config/ckan/portal.ini${HAIR}${Red}: FAIL${NC}${EOL}"
fi
else
printf "${Yellow}${INDENT}Copy ${PWD}/_config_examples/ckan/portal.ini to ${PWD}/_config/ckan/portal.ini (maintain local settings set to true): SKIPPING${NC}${EOL}"
fi
# copy portal.ini example to portal.ini
if [[ -f "${PWD}/_config/ckan/portal-test.ini" ]]; then
cp ${PWD}/_config/ckan/portal-test.ini ${PWD}/backup/local_configs/portal-test.ini
fi
if [[ $maintainLocalConfigs == "false" ]]; then
cp ${PWD}/_config_examples/ckan/portal-test.ini ${PWD}/_config/ckan/portal-test.ini
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Copy ${BOLDGREEN}${PWD}/_config_examples/ckan/portal-test.ini${HAIR}${Green} to ${BOLDGREEN}${PWD}/_config/ckan/portal-test.ini${HAIR}${Green}: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Copy ${BOLDRED}${PWD}/_config_examples/ckan/portal-test.ini${HAIR}${Red} to ${BOLDRED}${PWD}/_config/ckan/portal-test.ini${HAIR}${Red}: FAIL${NC}${EOL}"
fi
else
printf "${Yellow}${INDENT}Copy ${PWD}/_config_examples/ckan/portal-test.ini to ${PWD}/_config/ckan/portal-test.ini (maintain local settings set to true): SKIPPING${NC}${EOL}"
fi
# copy registry.ini example to registry.ini
if [[ -f "${PWD}/_config/ckan/registry.ini" ]]; then
cp ${PWD}/_config/ckan/registry.ini ${PWD}/backup/local_configs/registry.ini
fi
if [[ $maintainLocalConfigs == "false" ]]; then
cp ${PWD}/_config_examples/ckan/registry.ini ${PWD}/_config/ckan/registry.ini
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Copy ${BOLDGREEN}${PWD}/_config_examples/ckan/registry.ini${HAIR}${Green} to ${BOLDGREEN}${PWD}/_config/ckan/registry.ini${HAIR}${Green}: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Copy ${BOLDRED}${PWD}/_config_examples/ckan/registry.ini${HAIR}${Red} to ${BOLDRED}${PWD}/_config/ckan/registry.ini${HAIR}${Red}: FAIL${NC}${EOL}"
fi
else
printf "${Yellow}${INDENT}Copy ${PWD}/_config_examples/ckan/registry.ini to ${PWD}/_config/ckan/registry.ini (maintain local settings set to true): SKIPPING${NC}${EOL}"
fi
# copy registry.ini example to registry.ini
if [[ -f "${PWD}/_config/ckan/registry-test.ini" ]]; then
cp ${PWD}/_config/ckan/registry-test.ini ${PWD}/backup/local_configs/registry-test.ini
fi
if [[ $maintainLocalConfigs == "false" ]]; then
cp ${PWD}/_config_examples/ckan/registry-test.ini ${PWD}/_config/ckan/registry-test.ini
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Copy ${BOLDGREEN}${PWD}/_config_examples/ckan/registry-test.ini${HAIR}${Green} to ${BOLDGREEN}${PWD}/_config/ckan/registry-test.ini${HAIR}${Green}: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Copy ${BOLDRED}${PWD}/_config_examples/ckan/registry-test.ini${HAIR}${Red} to ${BOLDRED}${PWD}/_config/ckan/registry-test.ini${HAIR}${Red}: FAIL${NC}${EOL}"
fi
else
printf "${Yellow}${INDENT}Copy ${PWD}/_config_examples/ckan/registry-test.ini to ${PWD}/_config/ckan/registry-test.ini (maintain local settings set to true): SKIPPING${NC}${EOL}"
fi
# copy settings.py example to settings.py
if [[ -f "${PWD}/_config/django/settings.py" ]]; then
cp ${PWD}/_config/django/settings.py ${PWD}/backup/local_configs/settings.py
fi
if [[ $maintainLocalConfigs == "false" ]]; then
cp ${PWD}/_config_examples/django/settings.py ${PWD}/_config/django/settings.py
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Copy ${BOLDGREEN}${PWD}/_config_examples/django/settings.py${HAIR}${Green} to ${BOLDGREEN}${PWD}/_config/django/settings.py${HAIR}${Green}: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Copy ${BOLDRED}${PWD}/_config_examples/django/settings.py${HAIR}${Red} to ${BOLDRED}${PWD}/_config/django/settings.py${HAIR}${Red}: FAIL${NC}${EOL}"
fi
else
printf "${Yellow}${INDENT}Copy ${PWD}/_config_examples/django/settings.py to ${PWD}/_config/django/settings.py (maintain local settings set to true): SKIPPING${NC}${EOL}"
fi
# create project environment file
if [[ -f "${PWD}/.env" ]]; then
cp ${PWD}/.env ${PWD}/backup/local_configs/.env
fi
if [[ $maintainLocalConfigs == "false" ]]; then
hasGeneratedPorts="false"
hasGeneratedOctets="false"
if [[ -f "${PWD}/.env" ]]; then
source ${PWD}/.env
hasGeneratedPorts="true"
hasGeneratedOctets="true"
portNumber=${PORT}
octet=${OCTET}
touch ${PWD}/.env && echo -e "PROJECT_ID=$projectID\nUSER_ID=$(id -u)\nGROUP_ID=$(id -g)\nPORT=${PORT}\nDBPORT=${DBPORT}\nOCTET=${OCTET}\n" > ${PWD}/.env
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Create ${BOLDGREEN}${PWD}/.env${HAIR}${Green} file with Project ID of ${BOLDGREEN}$projectID${HAIR}${Green}: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Create ${BOLDRED}${PWD}/.env${HAIR}${Red} file with Project ID of ${BOLDRED}$projectID${HAIR}${Red}: FAIL${NC}${EOL}"
fi
else
hasGeneratedPorts="false"
hasGeneratedOctets="false"
touch ${PWD}/.env && echo -e "PROJECT_ID=$projectID\nUSER_ID=$(id -u)\nGROUP_ID=$(id -g)\n" > ${PWD}/.env
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Create ${BOLDGREEN}${PWD}/.env${HAIR}${Green} file with Project ID of ${BOLDGREEN}$projectID${HAIR}${Green}: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Create ${BOLDRED}${PWD}/.env${HAIR}${Red} file with Project ID of ${BOLDRED}$projectID${HAIR}${Red}: FAIL${NC}${EOL}"
fi
fi
# rent from pool
if [[ -f "${PWD}/.env" ]]; then
# rent port numbers from pool
if [[ ! -d "$HOME/.docker-og.pools/ports" ]]; then
mkdir -p ~/.docker-og.pools/ports
touch ~/.docker-og.pools/ports/{57000..57999}.port
fi
if [[ $hasGeneratedPorts == "false" ]]; then
portNumber=""
# rent port for proxy
portNumber=$(ls ~/.docker-og.pools/ports | head -1 | sed -e "s/\.port$//")
echo -e "PORT=${portNumber}\n" >> ${PWD}/.env
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Rent port number ${portNumber} for proxy: OK${NC}${EOL}"
rm $(ls ~/.docker-og.pools/ports/* | head -1)
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Remove port number ${portNumber} from pool: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Remove port number ${portNumber} from pool: FAIL${NC}${EOL}"
fi
else
printf "${Red}${INDENT}Rent port number for proxy: FAIL${NC}${EOL}"
fi
# END -- rent port for proxy -- END
# rent port for postgres
portNumber=$(ls ~/.docker-og.pools/ports | head -1 | sed -e "s/\.port$//")
echo -e "DBPORT=${portNumber}\n" >> ${PWD}/.env
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Rent port number ${portNumber} for postgres: OK${NC}${EOL}"
rm $(ls ~/.docker-og.pools/ports/* | head -1)
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Remove port number ${portNumber} from pool: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Remove port number ${portNumber} from pool: FAIL${NC}${EOL}"
fi
else
printf "${Red}${INDENT}Rent port number for postgres: FAIL${NC}${EOL}"
fi
# END -- rent port for postgres -- END
fi
# END -- rent port numbers from pool -- END
# rent ip octet from pool
if [[ ! -d "$HOME/.docker-og.pools/octets" ]]; then
mkdir -p ~/.docker-og.pools/octets
touch ~/.docker-og.pools/octets/{1..254}.octet
fi
if [[ $hasGeneratedOctets == "false" ]]; then
octet=""
# rent ip octet for docker network
octet=$(ls ~/.docker-og.pools/octets | head -1 | sed -e "s/\.octet$//")
echo -e "OCTET=${octet}\n" >> ${PWD}/.env
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Rent ip octet ${octet} for docker network: OK${NC}${EOL}"
rm $(ls ~/.docker-og.pools/octets/* | head -1)
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Remove ip octet${octet} from pool: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Remove ip octet ${octet} from pool: FAIL${NC}${EOL}"
fi
else
printf "${Red}${INDENT}Rent ip octet for docker network: FAIL${NC}${EOL}"
fi
# END -- rent ip octet for docker network -- END
fi
# END -- rent ip octet from pool -- END
fi
# END -- rent from pool -- END
else
printf "${Yellow}${INDENT}Create ${PWD}/.env file with Project ID of $projectID (maintain local settings set to true): SKIPPING${NC}${EOL}"
fi
# create nginx project environment file
if [[ -f "${PWD}/docker/config/nginx/conf/.env.conf" ]]; then
cp ${PWD}/docker/config/nginx/conf/.env.conf ${PWD}/backup/local_configs/.env.conf
fi
if [[ $maintainLocalConfigs == "false" ]]; then
touch ${PWD}/docker/config/nginx/conf/.env.conf && echo -e "set \$projectID \"$projectID\";\nset \$octet $octet;\n" > ${PWD}/docker/config/nginx/conf/.env.conf
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Create ${BOLDGREEN}${PWD}/docker/config/nginx/conf/.env.conf${HAIR}${Green} file with Project ID of ${BOLDGREEN}$projectID${HAIR}${Green} and IP Octect ${BOLDGREEN}$octet${HAIR}${Green}: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Create ${BOLDRED}${PWD}/docker/config/nginx/conf/.env.conf${HAIR}${Red} file with Project ID of ${BOLDRED}$projectID${HAIR}${Red} and IP Octect ${BOLDRED}$octet${HAIR}${Red}: FAIL${NC}${EOL}"
fi
else
printf "${Yellow}${INDENT}Create ${PWD}/docker/config/nginx/conf/.env.conf file with Project ID of $projectID and IP Octect $octet (maintain local settings set to true): SKIPPING${NC}${EOL}"
fi
# create nginx rendered upstream servers file
if [[ -f "${PWD}/docker/config/nginx/conf/.upstream_servers.conf" ]]; then
cp ${PWD}/docker/config/nginx/conf/.upstream_servers.conf ${PWD}/backup/local_configs/.upstream_servers.conf
fi
if [[ $maintainLocalConfigs == "false" ]]; then
touch ${PWD}/docker/config/nginx/conf/.upstream_servers.conf && cat ${PWD}/docker/config/nginx/conf/upstream_servers.conf | sed -e "s/\$octet/$octet/g" > ${PWD}/docker/config/nginx/conf/.upstream_servers.conf
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Create ${BOLDGREEN}${PWD}/docker/config/nginx/conf/.upstream_servers.conf${HAIR}${Green} file with IP Octect ${BOLDGREEN}$octet${HAIR}${Green}: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Create ${BOLDRED}${PWD}/docker/config/nginx/conf/.upstream_servers.conf${HAIR}${Red} file with IP Octect ${BOLDRED}$octet${HAIR}${Red}: FAIL${NC}${EOL}"
fi
else
printf "${Yellow}${INDENT}Create ${PWD}/docker/config/nginx/conf/.upstream_servers.conf file with IP Octect $octet (maintain local settings set to true): SKIPPING${NC}${EOL}"
fi
# create hosts file
if [[ $noInteraction == "false" ]]; then
printf "${Cyan}${INDENT}Generating host file ${ITALIC}${BOLD}/etc/hosts.d/og.conf${HAIR}${Cyan}. Maybe prompt for admin password...${NC}${EOL}"
if [[ -d "/etc/hosts.d" ]]; then
if [[ -f "/etc/hosts.d/default.conf" ]]; then
sudo find /etc/hosts.d -type f | sudo cat $(grep .conf) | sudo tee /etc/hosts >/dev/null
else
sudo cp /etc/hosts /etc/hosts.d/default.conf
sudo chmod a+r /etc/hosts.d/default.conf
sudo find /etc/hosts.d -type f | sudo cat $(grep .conf) | sudo tee /etc/hosts >/dev/null
fi
else
sudo mkdir /etc/hosts.d
sudo chmod a+r /etc/hosts.d
sudo chmod a+x /etc/hosts.d
sudo cp /etc/hosts /etc/hosts.d/default.conf
sudo chmod a+r /etc/hosts.d/default.conf
sudo find /etc/hosts.d -type f | sudo cat $(grep .conf) | sudo tee /etc/hosts >/dev/null
fi
if [[ -d "/etc/hosts.d" ]]; then
if [[ -f "/etc/hosts.d/og.conf" ]]; then
sudo rm -rf /etc/hosts.d/og.conf
fi
sudo touch /etc/hosts.d/og.conf
if [[ $? -eq 0 ]]; then
printf "${Green}${INDENT}Generate host file /etc/hosts.dog.conf: OK${NC}${EOL}"
else
printf "${Red}${INDENT}Generate host file /etc/hosts.d/og.conf: FAIL${NC}${EOL}"
fi
sudo chmod a+r /etc/hosts.d/og.conf
echo "" | sudo tee -a /etc/hosts.d/og.conf >/dev/null
echo "# Hosts generated by the OG CLI for use with Docker" | sudo tee -a /etc/hosts.d/og.conf >/dev/null
echo "127.0.0.1 open.local" | sudo tee -a /etc/hosts.d/og.conf >/dev/null
echo "127.0.0.1 ouvert.local" | sudo tee -a /etc/hosts.d/og.conf >/dev/null
echo "127.0.0.1 blog.open.local" | sudo tee -a /etc/hosts.d/og.conf >/dev/null
echo "127.0.0.1 guides.open.local" | sudo tee -a /etc/hosts.d/og.conf >/dev/null
echo "127.0.0.1 registry.open.local" | sudo tee -a /etc/hosts.d/og.conf >/dev/null
echo "127.0.0.1 registre.ouvert.local" | sudo tee -a /etc/hosts.d/og.conf >/dev/null
echo "127.0.0.1 portal.open.local" | sudo tee -a /etc/hosts.d/og.conf >/dev/null
echo "127.0.0.1 solr.open.local" | sudo tee -a /etc/hosts.d/og.conf >/dev/null
echo "127.0.0.1 search.open.local" | sudo tee -a /etc/hosts.d/og.conf >/dev/null
echo "# End of OG CLI hosts" | sudo tee -a /etc/hosts.d/og.conf >/dev/null
echo "" | sudo tee -a /etc/hosts.d/og.conf >/dev/null
sudo find /etc/hosts.d -type f | sudo cat $(grep .conf) | sudo tee /etc/hosts >/dev/null
fi
fi
chmod +x ${PWD}/install.sh
chmod +x ${PWD}/docker/install/*.sh
chmod +x ${PWD}/docker/install/ckan/*.sh
chmod +x ${PWD}/docker/install/django/*.sh
chmod +x ${PWD}/docker/install/drupal/*.sh
printf "${Green}${INDENT}${BOLDGREEN}DONE PRE-BUILD!${HAIR}${NC}${SPACER}"
}
if [[ $1 ]]; then
if [[ "$(pgrep docker | head -1)" ]]; then
if [[ $2 && $2 == "no-interaction" ]]; then
noInteraction='true'
fi
if [[ $noInteraction == "false" ]]; then
INDENT=$INDENT$INDENT
read -r -p $'\n\n\033[0;31m Are you sure you want to run the\033[1m pre build script?\033[0m\033[0;31m [y/N]:\033[0;0m ' response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
projectID=$1
run_pre_build
else
printf "${SPACER}${Yellow}${INDENT}Exiting pre build script...${NC}${SPACER}"
fi
else
if [[ $3 ]]; then
PWD=$3
fi
INDENT=$INDENT
BOLDGREEN=${HAIR}${Green}
BOLDRED=${HAIR}${Red}
projectID=$1
run_pre_build
fi
else
printf "${SPACER}${Yellow}${INDENT}Docker service is not running.${NC}${SPACER}"
fi
else
printf "${SPACER}${Yellow}${INDENT}No Project ID supplied. Please provide a Project ID such as: ./pre-build.sh local${NC}${SPACER}"
fi