-
Notifications
You must be signed in to change notification settings - Fork 18
/
functions
6541 lines (4183 loc) · 185 KB
/
functions
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
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env bash
### ############################################################################
### openspace42 synthia bootstrap framework.
### [https://github.com/openspace42/synthia].
### v0.4.0.
dna_version="v0.3.14"
### ############################################################################
### 1 | synthia global functions
### ############################################################################
synthia-define_vars() {
### define default variables.
### 1 | synthia global variables.
### ########################################################################
export proj_name="aenigma" ## legacy fix
export project_name="aenigma"
export author_name="openspace42"
export git_host="https://github.com"
### ########################################################################
### 2 | synthia project_specific variales.
### ########################################################################
#### backup / restore.
#### #######################################################################
#### set this to 'disabled' to disable local backups and only upload to S3
#### [useful if your project handles large amounts of data for example].
#### S3 must be set up by the user or else backups will not work at all.
#### this is only the default, which will be suggested to the user during
#### install, and it can be overridden.
export backup_locally_mode_default="enabled"
#### set this to 'disabled' to disable restore test during S3 backup.
#### this is only the default, which will be suggested to the user during
#### install, and it can be overridden.
export backup_test_restore_mode_default="enabled"
#### set this to 'n' if your project stores no data on end users' machines
#### that could go lost during a re-install or update.
export backup_prompt_during_install="y"
#### #######################################################################
### ########################################################################
### 3 | define dna variables.
dna-define_vars
### 4 | define any additional custom variables.
### ########################################################################
#### set the paths to the cluster / nodes conf dirs.
export conf_cluster_dir="${conf_dir}/cluster"
export conf_cluster_nodes_dir="${conf_cluster_dir}/nodes"
export conf_xmpp_dir="${conf_dir}/xmpp"
#### set the path to the domains_db file.
export domains_db_path="${conf_xmpp_dir}/domains_db"
#### set the paths to the nodes_db files.
export nodes_db_ipv4_path="${conf_cluster_nodes_dir}/nodes_db_ipv4"
export nodes_db_ipv6_path="${conf_cluster_nodes_dir}/nodes_db_ipv6"
export nodes_db_numbered_path="${conf_cluster_nodes_dir}/nodes_db_numbered"
export nodes_db_online_path="${tmp_project_dir}/nodes_db_online"
export nodes_db_initial_path="${tmp_project_dir}/nodes_db_initial"
#### hardcode package versions for installation.
export hardcoded_package_version_ejabberd="19.05"
export hardcoded_package_version_ejabberd_extended="19.05-0"
export hardcoded_package_version_ejabberd_fallback="19.05"
export hardcoded_package_version_ejabberd_fallback_extended="19.05-0"
export hardcoded_package_version_conversejs="v5.0.1"
### ########################################################################
### 5 | define final variables that depend on custom ones.
### ########################################################################
#### set default backup paths.
#### [absolute, mark whether existing or generated].
declare -gA backup_paths_default_array=(
[/var/www/upload]="existing"
[/pgdump]="generated"
)
### ########################################################################
}
#### bootstrap functions.
#### ###########################################################################
synthia-define_formatting() {
r=$'\e[1;31m'
g=$'\e[1;32m'
l=$'\e[1;34m'
m=$'\e[1;35m'
y=$'\e[1;33m'
o=$'\e[38;5;208m'
c=$'\e[1;36m'
n=$'\e[1;39m'
x=$'\e[0m'
b=$'\033[1m'
}
synthia-check_root() {
if [[ $EUID -ne 0 ]]
then
echo "${r-}${b-}This script must be run as root.${x-}"
echo
echo "${b-}Exiting...${x-}"
echo
exit 1
fi
}
synthia-download_dna() {
clone_host="https://github.com"
clone_author="openspace42"
clone_name="dna"
clone_base_dir="/root/${clone_author}"
clone_dir="${clone_base_dir}/${clone_name}"
mkdir -p "${clone_base_dir}"
if [ "${custom_dna_version-null}" = "l" ]
then
export dna_selected_vers="v0.0.1-custom-local"
echo "${r-}${b-}Sourcing | ${n-}local version${r-} | of | ${n-}dna${r-} | respecting any local alteration performed as per | ${n-}-d l${r-} |.${x-}"
echo "${dna_selected_vers}" > "./version_installed"
else
if [ -d "${clone_dir}" ]
then
rm -r "${clone_dir:?}"
fi
( cd "${clone_base_dir}" && git clone "${clone_host}/${clone_author}/${clone_name}" && echo && cd "${clone_name}"
. ./functions/snippets
git config advice.detachedHead false
### Define latest version
export dna_latest_vers_final="$(semtag getfinal)"
export dna_latest_vers_tagged="$(semtag getlast)"
export dna_latest_vers_bl_edge="$(semtag getcurrent)"
if [ "${custom_dna_version-null}" = "b" ]
then
export dna_selected_vers="${dna_latest_vers_bl_edge}"
echo "${r-}${b-}Installing | ${n-}bleeding-edge version${r-} | of | ${n-}dna${r-} | up to latest git commit as per | ${n-}-d b${r-} |.${x-}"
echo
git fetch
git reset --hard origin/master
elif [[ "${custom_dna_version-null}" == *"v"* ]]
then
export dna_selected_vers="${custom_dna_version}"
echo "${c-}${b-}Installing | ${n-}version ${dna_selected_vers}${c-} | of | ${n-}dna${c-} | as per | ${n-}-d ${dna_selected_vers}${c-} |.${x-}"
echo
git checkout "tags/${dna_selected_vers}"
elif [ "${custom_dna_version-null}" = "t" ]
then
export dna_selected_vers="${dna_latest_vers_tagged}"
echo "${o-}${b-}Installing | ${n-}latest-tagged version [${dna_selected_vers}]${o-} | of | ${n-}dna${o-} | [independently of its stability type] as per | ${n-}-d t${o-} |.${x-}"
echo
git checkout "tags/${dna_latest_vers_tagged}"
elif [ "${custom_dna_version-null}" = "f" ]
then
export dna_selected_vers="${dna_latest_vers_final}"
echo "${y-}${b-}Installing | ${n-}latest-final version [${dna_selected_vers}]${y-} | of | ${n-}dna${y-} | as per | ${n-}-d f${y-} |.${x-}"
echo
git checkout "tags/${dna_latest_vers_final}"
else
export dna_selected_vers="${dna_version}"
echo "${b-}Installing | ${g-}version [${dna_selected_vers}]${n-} | of | ${g-}dna${n-} |.${x-}"
echo
git checkout "tags/${dna_version}"
fi
echo "${dna_selected_vers}" > "./version_installed"
)
fi
}
synthia-source_dna() {
for f in /root/openspace42/dna/functions/*
do
. $f
done
}
#### ###########################################################################
#### backup_restore_functions
synthia-backup() {
### evaluate arguments.
### ########################################################################
while getopts ":lsri" arguments
do
case $arguments in
l) export backup_locally_only="y"
;;
s) export backup_s3_only="y"
;;
r) export backup_last_before_restore="y"
;;
i) export backup_skip_install_complete_check="y"
;;
\?) dna-echo -e "Invalid option | ${n-}-${OPTARG}${r-} | for function | ${n-}${FUNCNAME[0]}${r-} |."
dna-exit
;;
esac
done
OPTIND=1
if [ -n "${backup_last_before_restore-}" ]
then
if [ -n "${backup_s3_only-}" ]
then
dna-echo -e "Option | ${n-}backup_s3_only [-s]${r-} | is incompatible with option | ${n-}backup_last_before_restore [-r]${r-} |."
dna-exit
fi
export backup_locally_only="y"
fi
### ########################################################################
dna-backup_check_set_lockfile
if ! dna-backup
then
dna-echo -e "backup function exited with errors."
dna-echo -m "continuing anyway to perform post-backup operations if any and exit backup function gracefully."
synthia-backup_post_operations
fi
dna-backup_cleanup
}
#### ###########################################################################
### ############################################################################
### 2 | synthia project-specific functions.
### ############################################################################
#### backup / restore.
#### ###########################################################################
synthia-backup_pre_operations() {
### perform pre-backup operations.
dna-echo_operation -h "performing pre-backup operations"
### ########################################################################
### ########################################################################
dna-echo_operation -t
}
synthia-backup_post_operations() {
dna-echo_operation -h "performing post-backup operations"
### perform post-backup operations.
### ########################################################################
### ########################################################################
dna-echo_operation -t
}
synthia-calculate_backup_size() {
### ########################################################################
### calculate backup_paths size.
dna-calculate_backup_paths_size
### ########################################################################
### calculate any additional custom size.
### ########################################################################
#### calculate postgresql database size.
dna-get_hostname
patroni_ejabberd_db_size="$(PGPASSWORD="${patroni_postgres_password}" psql -h "${hostname}" -p "5432" -U "postgres" -t -c "select pg_database_size('ejabberd') / 1024 / 1024;" | xargs)"
### ########################################################################
### add it up.
backup_total_size_estimate="$((${backup_paths_size_estimate} + ${patroni_ejabberd_db_size}))"
### ########################################################################
}
synthia-backup_generate_additional_paths() {
### generate backups for any additional custom item by populating their
### respective backup_paths.
dna-echo_operation -h "backing up any additional custom backup_path"
### ########################################################################
### create paths
dna-backup_generate_additional_paths_dirs
### ########################################################################
### perform backups of every item individually
### ########################################################################
#### postgresql dump.
pg_dump --dbname="postgresql://ejabberd:${patroni_ejabberd_password}@${public_ipv4}:5432/ejabberd" > "${tmp_project_backup_dir}/pgdump/ejabberd.pgsql"
### ########################################################################
dna-echo_operation -t
}
synthia-backup_locally() {
dna-echo_operation -h "backing up locally"
### generate backups for any additional custom item
synthia-backup_generate_additional_paths
### backup backup paths locally.
dna-backup_locally_data_backup_paths
### backup any additional custom item.
### ########################################################################
### ########################################################################
dna-echo_operation -t
}
synthia-restore() {
### evaluate arguments.
### ########################################################################
while getopts ":lsri" arguments
do
case $arguments in
l) export backup_locally_only="y"
;;
\?) dna-echo -e "Invalid option | ${n-}-${OPTARG}${r-} | for function | ${n-}${FUNCNAME[0]}${r-} |."
dna-exit
;;
esac
done
OPTIND=1
### ########################################################################
if ! dna-backup
then
dna-echo -e "restore function exited with errors."
fi
}
restore_loop() {
echo "${b-}1] Now restoring aenigma config directory...${x-}"
echo
rsync -aAXx --delete $restore_file_path/conf/ $conf_dir/
echo "${b-}2] Now restoring ejabberd database...${x-}"
echo
if (( $(ps -ef | grep -v grep | grep ejabberd | wc -l) > 0 ))
then
echo "${g-}${b-}ejabberd is already running. Continuing...${x-}"
echo
else
echo "${r-}${b-}ejabberd NOT running. Starting it now...${x-}"
echo
echo "${b-}Now starting ejabberd ...${x-}"
/usr/sbin/service ejabberd start
echo
dna-wait -s "8" -d "Now allowing ejabberd to start up correctly..."
/usr/sbin/ejabberdctl
echo
sleep 1
fi
if (( $(ps -ef | grep -v grep | grep ejabberd | wc -l) > 0 ))
then
cd $restore_file_path/data/
cp ./ejabberd-mnesia-backup /var/lib/ejabberd/
/usr/sbin/ejabberdctl restore ejabberd-mnesia-backup
rm /var/lib/ejabberd/ejabberd-mnesia-backup
echo "${b-}Successfully restored ejabberd database...${x-}"
echo
dna-wait -s "8" -d "Now allowing ejabberd sync the database..."
else
echo "${r-}${b-}ERROR: ejabberd STILL NOT running. Unable to restore database from backup.${x-}"
echo
dna-exit
fi
echo "${b-}Now restoring ejabberd directories...${x-}"
echo
echo "${b-}Now stopping ejabberd for directory restore...${x-}"
echo
/usr/sbin/service ejabberd stop
dna-wait -s "8" -d "Now allowing ejabberd to shut down correctly..."
echo "${b-}3] Now syncing ejabberd directories...${x-}"
echo
rsync -aAXx --delete $restore_file_path/data/etc-ejabberd/ /opt/ejabberd/
rsync -aAXx --delete $restore_file_path/data/var-lib-ejabberd/ /var/lib/ejabberd/
aenigma-set_permissions
echo "${b-}Now starting ejabberd...${x-}"
/usr/sbin/service ejabberd start
echo
dna-wait -s "8" -d "Now allowing ejabberd to start up correctly..."
/usr/sbin/ejabberdctl status
echo
sleep 1
if (( $(ps -ef | grep -v grep | grep ejabberd | wc -l) > 0 ))
then
echo "${g-}${b-}Restore complete!${x-}"
echo
echo "${b-}Now please verify your aenigma instance is running correctly and has everything you except it to.${x-}"
echo
read -p "${b-}Has your previous instance of aenigma been restored correctly? (Y/n): ${x-}" -n 1 -r
echo
if [[ ! $REPLY =~ ^[Nn]$ ]]
then
echo "${g-}${b-}Ok, all done!${x-}"
echo
if [ -f $conf_dir/blocks3backups ]
then
rm $conf_dir/blocks3backups
echo "${b-}Removing S3 backups lock since your restore has been successful.${x-}"
echo
echo "${r-}${b-}This machine will now pick up where the old one left off and start backing up again to S3 and will overwrite all previous data stored on S3.${x-}"
echo
echo "${b-}If you've changed your mind and are NOT yet sure this restore was completely successful, simply:${x-}"
echo
echo "${b-} | touch $conf_dir/blocks3backups |"
echo
echo "${b-}And remember to remove it as soon as you're done verifying this restored instance to then resume backups to S3!${x-}"
echo
echo "${g-}${b-}All done for now.${x-}"
echo
fi
else
echo
echo "${b-}Sorry about that, please collect all evidence you can find so and simply file an issue report at:${x-}"
echo
echo "${b-} | ${git_host}/${author_name}/${project_name}/issues |${x-}"
echo
echo "${b-}Thank you in advance!${x-}"
echo
fi
else
echo "${r-}${b-}ERROR: ejabberd not running after restore. Please check ejabberd directories.${x-}"
echo
echo "${b-}Please collect all evidence you can find so and simply file an issue report at:${x-}"
echo
echo "${b-} | https://github.com/openspace42/aenigma/issues |${x-}"
echo
echo "${b-}Thank you in advance!${x-}"
echo
echo "${b-}Exiting...${x-}"
echo
exit
fi
if [ -d "$restores_dir/local/" ]
then
rm -r "$restores_dir/local/"
fi
if [ -d "/root/${project_name}-restore/" ]
then
rm -r "/root/${project_name}-restore/"
fi
if [ -d "$tmpdir" ]
then
rm -r "${tmpdir:?}"
fi
if [ $bootstrapmode = "on" ]
then
echo "${b-}Now that we're finished with the initial restore, it's time to re-run the install script and get this machine up and running with your old instance's files and settings${x-}"
echo
echo "${b-}Running install script now.${x-}"
echo
echo "${r-}${b-}Should you exit the install script during its runtime, you can re-run it manually with:${x-}"
echo
echo "${b-} | bash $sourcedir/install.sh | ${x-}"
cd
bash $sourcedir/install.sh
fi
}
#### ###########################################################################
aenigma-display_logo() {
### add delay for previous outputs.
sleep 1
### determine terminal window size.
columns_number="$(tput cols)"
rows_number="$(tput lines)"
### check that the terminal window is large enough to display the logo.
if [ "${columns_number}" -ge "93" ] && [ "${rows_number}" -ge "24" ]
then
### determine terminal window horizontal center.
columns_median="$(echo $((columns_number / 2)))"
### the aenigma logo is 45 pixels and therefore 90 columns wide.
base_column="$(echo $((columns_median - 45)))"
### determine terminal window vertical center.
rows_median="$(echo $((rows_number / 2)))"
### the aenigma logo is 17 rows tall.
base_row="$(echo $((rows_median - 9)))"
### determine bottom padding.
bottom_padding="$(echo $((base_row - 2)))"
### set colors.
b=$'\e[38;5;16m'
w=$'\e[38;5;15m'
l=$'\e[38;5;33m'
x=$'\e[0m'
z=$'\e[8m'
### set white base for all lines.
set p02{01..45} && array="$@" && for item in $array; do eval $item='$w'; done && unset array item
set p03{01..45} && array="$@" && for item in $array; do eval $item='$w'; done && unset array item
set p04{01..45} && array="$@" && for item in $array; do eval $item='$w'; done && unset array item
set p05{01..45} && array="$@" && for item in $array; do eval $item='$w'; done && unset array item
set p06{01..45} && array="$@" && for item in $array; do eval $item='$w'; done && unset array item
set p07{01..45} && array="$@" && for item in $array; do eval $item='$w'; done && unset array item
set p08{01..45} && array="$@" && for item in $array; do eval $item='$w'; done && unset array item
set p09{01..45} && array="$@" && for item in $array; do eval $item='$w'; done && unset array item
set p10{01..45} && array="$@" && for item in $array; do eval $item='$w'; done && unset array item
set p11{01..45} && array="$@" && for item in $array; do eval $item='$w'; done && unset array item
set p12{01..45} && array="$@" && for item in $array; do eval $item='$w'; done && unset array item
set p13{01..45} && array="$@" && for item in $array; do eval $item='$w'; done && unset array item
set p14{01..45} && array="$@" && for item in $array; do eval $item='$w'; done && unset array item
set p15{01..45} && array="$@" && for item in $array; do eval $item='$w'; done && unset array item
set p16{01..45} && array="$@" && for item in $array; do eval $item='$w'; done && unset array item
set p17{01..45} && array="$@" && for item in $array; do eval $item='$w'; done && unset array item
### line 03.
eval p0319='$b'
### line 06.
eval p06{03..09}='$l'
eval p06{11..17}='$b'
eval p0619='$b'
eval p06{21..27}='$b'
eval p06{29..35}='$b'
eval p06{38..43}='$b'
### lines {07..08}.
eval p{07..08}{06..09}='$l'
eval p{07..08}11='$b'
eval p{07..08}17='$b'
eval p{07..08}19='$b'
eval p{07..08}21='$b'
eval p{07..08}27='$b'
eval p{07..08}29='$b'
eval p{07..08}32='$b'
eval p{07..08}35='$b'
eval p{07..08}43='$b'
### line 09.
eval p09{03..09}='$l'
eval p0911='$b'
eval p0917='$b'
eval p0919='$b'
eval p0921='$b'
eval p0927='$b'
eval p0929='$b'
eval p0932='$b'
eval p0935='$b'
eval p09{37..43}='$b'
### lines {10..11}.
eval p{10..11}{03..06}='$l'
eval p{10..11}11='$b'
eval p{10..11}17='$b'
eval p{10..11}19='$b'
eval p{10..11}21='$b'
eval p{10..11}27='$b'
eval p{10..11}29='$b'
eval p{10..11}32='$b'
eval p{10..11}35='$b'
eval p{10..11}37='$b'
eval p{10..11}43='$b'
### line 12.
eval p12{03..09}='$l'
eval p1211='$b'
eval p1217='$b'
eval p1219='$b'
eval p12{21..27}='$b'
eval p1229='$b'
eval p1232='$b'
eval p1235='$b'
eval p12{37..43}='$b'
### lines {13..14}.
eval p{13..14}27='$b'
### line 15.
eval p15{22..27}='$b'
### set borders.
set p01{01..45} && array="$@" && for item in $array; do eval $item='$b'; done && unset array item
set p17{01..45} && array="$@" && for item in $array; do eval $item='$b'; done && unset array item
eval p{01..17}01='$b'
eval p{01..17}45='$b'
### clear.
clear
### print top padding.
yes '' | sed ${base_row}q
### print.
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p01{01..45}██ | tr -d ' ')"
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p02{01..45}██ | tr -d ' ')"
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p03{01..45}██ | tr -d ' ')"
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p04{01..45}██ | tr -d ' ')"
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p05{01..45}██ | tr -d ' ')"
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p06{01..45}██ | tr -d ' ')"
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p07{01..45}██ | tr -d ' ')"
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p08{01..45}██ | tr -d ' ')"
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p09{01..45}██ | tr -d ' ')"
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p10{01..45}██ | tr -d ' ')"
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p11{01..45}██ | tr -d ' ')"
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p12{01..45}██ | tr -d ' ')"
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p13{01..45}██ | tr -d ' ')"
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p14{01..45}██ | tr -d ' ')"
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p15{01..45}██ | tr -d ' ')"
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p16{01..45}██ | tr -d ' ')"
echo "$(eval $(echo printf '" %0.s"' {1..$base_column}))${x}$(echo $p17{01..45}██ | tr -d ' ')"
### reset formatting.
echo ${x}
unset b w l x z
synthia-define_formatting
### print bottom padding.
yes '' | sed ${bottom_padding}q
### add delay.
sleep 2
### clear.
clear
fi
}
aenigma-xmpp_intro() {
dna-echo -m "First of all, a little introduction on how XMPP actually works"
dna-echo -m "XMPP works very much like email. You can have a domain [amsterdamhacklab.xyz] and receive email for that domain on a server located at mx01.amsterdamhacklab.xyz, by using the appropriate DNS configuration, and also have other servers [webserver, mapserver, etc...] on other subdomains."
dna-echo -m "In that case, a DNS MX record tells sending servers to direct mail intended for amsterdamhacklab.xyz to mx01.amsterdamhacklab.xyz."
dna-echo -m "In the same way, the XMPP server for amsterdamhacklab.xyz can be located at ae01.amsterdamhacklab.xyz and a DNS SRV record tells any sending servers that XMPP for that domain [i.e. a message directed to [email protected]] is handled by the server located at ae01.amsterdamhacklab.xyz."
dna-press_to_continue
dna-echo -m "$project_name fully embraces this opportunity."
dna-echo -m "The domain for which you're setting up your new $project_name server can definitely be a domain connected to a bigger project, that already points to other servers, and for which XMPP is just another service."
dna-echo -m "This will give you working @amsterdamhacklab.xyz JIDs [XMPP account addresses], but the $project_name server will reside at ae01.amsterdamhacklab.xyz, as in the following example:"
dna-echo -m "${o-}Domain:${n-} ${y-}amsterdamhacklab.xyz.${n-}"
dna-echo -m "${o-}Website:${n-} ${y-}amsterdamhacklab.xyz${n-} / ${y-}www.amsterdamhacklab.xyz${n-} [hosted by another server]."
dna-echo -m "${o-}Your JID format:${n-} ${y-}[email protected].${n-}"
dna-echo -m "${o-}XMPP server:${n-} ${y-}xmpp.amsterdamhacklab.xyz${n-}"
dna-press_to_continue
## add cluster info here.
dna-echo -m "Now that you know how XMPP works, let's get your brand new $project_name server up and running!"
}
aenigma-set_secondary_node_hostname() {
### set hostname according to the node_number from the newly received
### config.
echo "ae${node_number}.${domain}" > "/etc/hostname"
hostname="$(cat /etc/hostname)"
hostname -F "/etc/hostname"
}
aenigma-provision_nginx() {
dna-get_hostname
### stop sslh to avoid any conflicts with a brand new nginx installation.
if systemctl is-active --quiet sslh
then
dna-echo_operation -h "stopping SSLH"
service sslh stop
dna-echo_operation -t
fi
### install nginx and configure ejabberd admin panel reverse proxy site.
### here we use the distro provided nginx as the nginx.org repo does not
### have nginx-common required for libnginx-mod-http-perl.
dna-install_dependencies -p "nginx-common nginx libnginx-mod-http-perl"
### increase names_hash_bucket_size to 128 in nginx config as the .onion
### hostname is really long should it be later provisioned.
dna-nginx_increase_names_hash_bucket_size_128
### remove default nginx stuff.
if [ -d "/etc/nginx/sites-enabled/" ]
then
rm -rf "/etc/nginx/sites-enabled"
fi
if [ -f "/etc/nginx/conf.d/default.conf" ]
then
rm "/etc/nginx/conf.d/default.conf"
fi
### install perl and upload module.
### https://github.com/weiss/ngx_http_upload.
mkdir -p "/usr/local/lib/perl"
wget -O "/usr/local/lib/perl/upload.pm" "https://git.io/fNZgL"
sed -i "s|my \$uri_prefix_components = 0;|my \$uri_prefix_components = 1;|g" "/usr/local/lib/perl/upload.pm"
nginx_version="$(nginx -v)"
echo
dna-get_distro_name
### if this is debian manually load perl module. ## vestigial
# if [ "${distro_name}" = "debian" ]
# then
# if ! grep -q "ngx_http_perl_module.so" "/etc/nginx/nginx.conf"
# then
# sed -i "/^events {/i load_module modules\/ngx_http_perl_module.so;\n" "/etc/nginx/nginx.conf"
# fi
# fi
if ! grep -q "/usr/local/lib/perl" "/etc/nginx/nginx.conf"
then
sed -i "/^http {$/a\ \n perl_modules /usr/local/lib/perl;\n perl_require upload.pm;" "/etc/nginx/nginx.conf"
fi
### create web locations and populate them.
mkdir -p "/var/www/${project_name}/"
chown -R "www-data:www-data" "/var/www/${project_name}/"
mkdir -p "/var/www/upload"
chown -R "www-data:www-data" "/var/www/upload/"
cp "${source_dir}/conf/web/global/index.html" "/var/www/${project_name}/"
### create and configure the $domain website.
cp "${source_dir}/conf/nginx/domain" "/etc/nginx/conf.d/${domain}.conf"
sed -i "s/hostname.xyz/${hostname}/g" "/etc/nginx/conf.d/${domain}.conf"
sed -i "s/domain.xyz/${domain}/g" "/etc/nginx/conf.d/${domain}.conf"
### delete default_server setting in $domain nginx conf file in case .onion
### nginx conf is present and already has default_server setting itslef.
if [ -f "/etc/nginx/conf.d/onion.conf" ]
then
if grep -q "default_server" "/etc/nginx/conf.d/onion.conf"
then
sed -i "s|443 default_server ssl|443 ssl|g" "/etc/nginx/conf.d/${domain}.conf"
fi
fi
if [ ! "${cluster_mode-null}" = "secondary" ]
then
### generate a random external_secret for the nginx ejabberd uploads.
if [ -z "${nginx_ejabberd_uploads_external_secret-}" ]
then
dna-echo -m "Generating password for the postgresql/patroni postgres user"
nginx_ejabberd_uploads_external_secret="$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 24 | head -n 1)"
dna-set_option -o "nginx_ejabberd_uploads_external_secret" -p "xmpp" -s "${nginx_ejabberd_uploads_external_secret}"
fi
fi
sed -i "s|it-is-secret|${nginx_ejabberd_uploads_external_secret}|g" "/usr/local/lib/perl/upload.pm"
### create and configure the websites for any and every $additional_domain.
if [ ! "${additional_domains-null}" = "none" ]
then
additional_domains_array=(${additional_domains})
for additional_domain in "${additional_domains_array[@]}"
do
cp "${source_dir}/conf/nginx/additional_domain" "/etc/nginx/conf.d/${additional_domain}.conf"
sed -i "s/additional_domain-var/${additional_domain}/g" "/etc/nginx/conf.d/${additional_domain}.conf"
sed -i "s/hostname.xyz/${hostname}/g" "/etc/nginx/conf.d/${additional_domain}.conf"
sed -i "s/domain.xyz/${domain}/g" "/etc/nginx/conf.d/${additional_domain}.conf"
done
fi
### start sslh back up if it's already installed.
dna-echo_operation -h "starting SSLH back up"
if which sslh &> /dev/null
then