-
Notifications
You must be signed in to change notification settings - Fork 14
/
hollaex
executable file
·8879 lines (5874 loc) · 298 KB
/
hollaex
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
#!/bin/bash
### DEPRECATION WARNING ###
# function hollaex_ascii_cli_is_deprecated() {
# /bin/cat << EOF
# :tt1 ;tti LCC:1CC1 ,11tffttt :tt; ;tfi.tt1 ,,,
# t@@8 f@@0 ,;ii;. 8@@;L@@f .:i1i:. ;@@@CLCGC;ii; ,iii. t@@L,C@@L,.CCf,0@@;,
# t@@8LLf0@@G,C@@[email protected]@@;L@@t.C80L0@8i:@@8tt; :8@@1G@@1. t@@0@@8: ,8888@@@8G
# t@@8CCC0@@CC@@L G@@fG@@;L@@t,fCCfG@@L:@@@LLi C@@@8, t@@@C8@0: ,@@G.G@@,
# t@@8 L@@G1@@0;;8@@i0@@;L@@fC@@Li0@@f:@@@iii11:i8@G@@C, t@@L :0@@1,@@0 G@@1;
# iGGL tGGf ;LG00Gf: CGG:tGG1:LGGCLCG1:GGG0000fiGGL 1GGf. iCC1 .LGG1CGf :LG0G,
# HollaEx CLI is DEPRECATED!
# From the HollaEx Kit v2.10, HollaEx CLI is officially deprecated and not recommended for use.
# Please visit https://github.com/hollaex/hollaex-kit for more details.
# ---------------------------------
# EOF
# }
# hollaex_ascii_cli_is_deprecated;
############################
SCRIPTPATH="$HOME/.hollaex-cli"
#### HollaEx CLI Settings ####
RUN_WITH_VERIFY=true
LOCAL_DEPLOYMENT_MODE='all'
GENERATE_PASSWORDS=false
function check_docker_compose_is_installed() {
echo "Checking docker-compose availability..."
docker-compose version
# Checking docker compose is installed on this machine.
if [[ $? -ne 0 ]] ; then
echo -e "\n\033[91mError: HollaEx CLI could not detect Docker Compose on this machine. Please install Docker Compose before proceeding.\033[39m\n"
echo "To install the core dependencies, including Docker Compose, you can run: \`bash install.sh\`."
echo -e "Alternatively, you can manually install Docker Compose by following the instructions at: https://docs.docker.com/compose/install/standalone/.\n"
exit 1
fi
}
check_docker_compose_is_installed;
# Docker compose v1 prefixes
DOCKER_COMPOSE_NAME_PREFIX='local_'
DOCKER_COMPOSE_CONTAINER_NUMBER_CONNECTOR="_"
# Docker compose v2+ compatibility prefiexes
if command docker-compose version > /dev/null; then
# export DOCKER_COMPOSE_NAME_PREFIX="server-"
DOCKER_COMPOSE_NAME_PREFIX='local-'
export DOCKER_COMPOSE_CONTAINER_NUMBER_CONNECTOR="-"
fi
INIT_PATH_CHECK=$(pwd)/.hollaex
if [[ ! -f "$INIT_PATH_CHECK" ]] && [[ ! "$HOLLAEX_NETWORK_OPERATION" ]] && [[ ! "$1" == "version" ]]; then
echo -e "\n\033[91mFailed to detect the HollaEx Kit."
echo -e "Every HollaEx commands should be run at the HollaEx Kit path.\033[39m"
echo -e "Please check your current path and try it again.\n"
echo -e "To download the HollaEx Kit, Please run 'git clone https://github.com/hollaex/hollaex-kit.git'.\n"
exit 1;
fi
if [[ "$HOLLAEX_NETWORK_OPERATION" ]] && [[ ! "$HOLLAEX_NETWORK_SETUP" ]]; then
INIT_PATH_CHECK=$(pwd)/.hollaex-network
if [[ ! -f "$INIT_PATH_CHECK" ]]; then
echo -e "\n\033[91mFailed to detect the HollaEx Network Home."
echo -e "Every HollaEx commands should be run at the HollaEx Network Home Patch.\033[39m"
echo -e "Please check your current path and try it again.\n"
exit 1;
fi
fi
if [[ ! "$HOLLAEX_NETWORK_OPERATION" ]]; then
if [[ ! "$1" == "version" ]]; then
source $(pwd)/.hollaex
fi
if [[ "$HOLLAEX_CONFIGMAP_NETWORK_URL" ]]; then
export hollaexAPIURL=$HOLLAEX_CONFIGMAP_NETWORK_URL
elif [[ ! "$HOLLAEX_CONFIGMAP_NETWORK_URL" ]] && [[ "$ENVIRONMENT_HOLLAEX_KIT_NETWORK" == "testnet" ]]; then
export hollaexAPIURL='https://api.testnet.hollaex.network'
else
export hollaexAPIURL='https://api.hollaex.network'
fi
source $SCRIPTPATH/version_range
fi
check_git_conflict() {
local file=$1
if grep -q '<< HEAD' "$file" && grep -q '==' "$file" && grep -q '>>' "$file"; then
echo -e "\nError: Git conflict detected in file: $file"
echo "Please check the file and fix the Git conflict to proceed."
exit 1;
fi
}
check_git_conflict settings/configmap;
check_git_conflict settings/secret;
err_msg() { echo "$@" ;} >&2
err_msg_a() { err_msg "-a option argument required" ;}
err_msg_l() { err_msg "--long option argument required" ;}
function print_usage() {
/bin/cat << EOF
Usage :
hollaex [ server ] [ web ] [ init ] [ prod ] [ import ] [ export ] [ dash ] [ pull ] [ build ] [ dev ] [ toolbox ] [ status ] [ logs ] [ version ] [ discord ] [ bug-report ] (--flags)
General Flags (Except for 'hollaex init', 'hollaex import'):
--path, Manually pointing HollaEx Kit path. Should be always absolute path.
--kube, Set HollaEx CLI to target Kubernetes. Make sure to setup your local kubectl before using it.
--skip, Run command without user's double confirmation.
Options:
import: Import settings files generated by using HollaEx Dashboard (dash.hollaex.com).
--path, Path of file or directory where settings files are stored.
--with_aws_s3 <BUCKET_NAME>, Import settings files from the remote AWS S3 bucket.
export: Export settings files to the target location.
--path, Path of the directory to export settings files.
--with_aws_s3 <BUCKET_NAME>, Export settings files to the remote AWS S3 bucket.
dash: Interaction with HollaEx Dashboard.
--login: Log in with HollaEx Dashboard account.
--logout Log out and remove my bound account.
init: Initialize the HollaEx Kit by setting up the target network, sign up as an admin, and claim a new exchange name.
pull: Pull the exchange data from the HollaEx Dashboard.
prod: Bring up the exchange to production. Including public domain setup and SSL configuraiton.
build: Build the Docker image for running HollaEx Kit, includes user custom configurations.
--version, Specify base HollaEx Core version for build.
server: Run and Manage HollaEx Exchange Server.
--setup: Setup the exchange for the first launch.
--start: Start the exchange which already been configured by 'hollaex setup' command.
--tag, Tag name of the new image to apply.
--ignore_settings, Ignore local settings files changes and not applying it on the server.
--restart: Restart the existing exchange.
--tag, Tag name of the new image to apply.
--ignore_settings, Ignore local settings files changes and not applying it on the server.
--stop: Stop the exchagne which already been running.
--upgrade: Upgrade the exchange to new version.
--version, Version number of HollaEx Core to upgrade.
--user_image_registry, Specify Docker registry and version (tag) for the user HollaEx Core image.
--ignore_compatibility_check, Ignore Kit and Core compatibility check before an upgrade.
--ignore_settings, Ignore local settings files changes and not applying it on the server.
--api_only, Rolling Upgrade API Pods only for Kubernetes.
--terminate: Terminate the existing exchange. THIS COMMAND WILL COMPLETELY REMOVE YOUR EXCHANGE AND CAN'T BE UNDO.
web: Run web server for the exchange.
--setup, Setup the web server for the first launch.
--start, Start the web server
--stop, Stop the web server.
--restart, Restart the web server while applying new changes (If it's available).
--build, Build the web server docker image. This command would not affect the existing web server before restart.
--terminate, Terminate the web server. THIS COMMAND WILL COMPLETELY REMOVE YOUR WEB CLIENT AND CAN'T BE UNDO.
trade: Open my exchange's web trading page.
toolbox: Toolbox for advanced features which could be helpful for your exchange operations.
--backup, Run the full backup with 'pg_dump' for exchange's PostgreSQL database.
--restore, Apply the database dump to the database.
--set_backup_cronjob, Set the Kubernetes Cronjob for periodical database backup.
--flush_redis, Run the full flush of Redis stored data.
--issue_ssl, Issue SSL certificate on local Nginx by using Let's Encrypt.
--renew_ssl, Renew SSL certificate on local Nginx by using Let's Encrypt.
--update_registry_secret, Update existing docker registry secret for Kubernetes.
--set_config, Update constants configured on the exchange database.
--set_security, Override security values at admin panel for the exchange.
--set_activation_code, Set or update activation code for the exchange.
--connect_database, Direct connection to PostgreSQL Database via postgresql-client.
--connect_redis, Direct connection to Redis via redis-client.
--install_cli, Install specific version of HollaEx CLI.
--influxdb_migration, Migrate InfluxDB data to a new InfluxDB.
--reset_hmac_token, Reset the exchange API key (HMAC Token).
--enable_maintenance_mode, Maintenance mode. Giving HTTP 503 for non-whitelisted IPs.
--whitelist-ip, List of whitelist IPs for the maintenance mode. Comma separated, no spaces.
--disable_maintenance_mode, Disabling maintenance mode.
--upgrade-psql-db-version, Upgrade PostgreSQL DB to a specific version.
--change-user-email, Force change exchange user's email address.
--user-id, Target User ID.
--user-email, New User Email Address.
dev: Running an exchange in a dev mode.
--setup, Setup an exchange in a dev mode.
--start, Starting an exchange in a dev mode.
--stop, Stopping an exchange in a dev mode.
--restart, Restarting an exchange in a dev mode.
--terminate, Terminating an exchange in a dev mode.
--database_init, Running a database initialization job for a dev mode exchange.
cloud: Operate the exchange running on the HollaCloud.
--start, Start the stopped exchange exists on the HollaCloud.
--stop, Stop the running exchange on the HollaCloud.
--restart, Restart the running exchange on the HollaCloud.
--upgrade, Upgrade the running exchange on the HollaCloud with the latest version of HollaEx Kit.
--terminate, Terminate the existing exchange on the HollaCloud. THIS COMMAND WILL COMPLETELY REMOVE YOUR EXCHANGE AND CAN'T BE UNDO.
status: Show the exchange server status.
logs: Show overview of logs from the exchange server.
mode: Mode selector between the testnet and mainnet. Only use it for testing purposes.
--testnet, Setting the mode to testnet.
--mainnet, Setitng the mode to mainnet (default).
discord: Open (join) HollaEx Official Discord Channel.
forum: Open Official HollaEx Forum.
xht-market: Open Official HollaEx Exchange's XHT trading market page.
bug-report: Report a bug you found on HollaEx GitHub.
version: Print out current installed version of HollaEx CLI.
EOF
}
function dev_print_usage() {
/bin/cat << EOF
# All 'hollaex dev' commands should be run at HollaEx Core directory.
Usage :
hollaex [ dev ] (--flags)
General Flags :
--skip, Run command without user's double confirmation.
Options:
--command: Run Docker-Compose commands. (up, down, stop, --build)
--database_init: Run database initialization scripts.
EOF
}
function print_network_usage() {
/bin/cat << EOF
# All 'hollaex network' commands should be run at HollaEx Network Home.
Usage :
hollaex network [ setup ] [ start ] [ stop ] [ restart ] [ upgrade ] [ terminate ] [ add_coin / add_trading_pair ] [ change_coin_owner / change_trading_pair_owner ] [ activate_coin / activate_trading_pair ] (--flags)
General Flags :
--skip, Run command without user's double confirmation.
--kube, Set HollaEx CLI to target Kubernetes. Make sure to setup your local kubectl before using it.
EOF
}
if [[ "$1" == "dev" ]]; then
while true; do
[[ $# -eq 0 ]] && break
case $1 in
--command)
shift
case $1 in (-*|"") err_msg_l; print_usage; exit 1; esac
HOLLAEX_DEV_MANUAL_COMMAND=true
LOCAL_COMMAND=$1
echo "Your docker-compose command : $LOCAL_COMMAND."
shift; continue
;;
--server)
HOLLAEX_DEV_TARGET="server"
shift; continue
;;
--web)
HOLLAEX_DEV_TARGET="web"
shift; continue
;;
--setup)
HOLLAEX_DEV_SETUP=true
shift; continue
;;
--start)
HOLLAEX_DEV_START=true
LOCAL_COMMAND=start
shift; continue
;;
--stop)
HOLLAEX_DEV_STOP=true
LOCAL_COMMAND=stop
shift; continue
;;
--restart)
HOLLAEX_DEV_RESTART=true
shift; continue
;;
--terminate)
HOLLAEX_DEV_TERMINATE=true
LOCAL_COMMAND=down
shift; continue
;;
--database_init)
LOCAL_DATABASE_INIT=true
echo 'Local database initialization enabled.'
shift; continue
;;
--test)
LOCAL_CODE_TEST=true
echo 'Local mocha code test mode enabled.'
shift; continue
;;
--skip)
RUN_WITH_VERIFY=false
echo 'Skipping the command confirmation.'
shift; continue
;;
--*)
err_msg "Invalid option: $1"
dev_print_usage;
exit 1;
;;
esac
shift
done
IS_DEVELOP=true
HOLLAEX_CLI_INIT_PATH=$(pwd)
CONFIG_FILE_PATH=$(pwd)/settings/*
TEMPLATE_GENERATE_PATH=$(pwd)/templates
INIT_PATH_CHECK=$(pwd)/.hollaex
for i in ${CONFIG_FILE_PATH[@]}; do
source $i
done;
source $SCRIPTPATH/tools_generator.sh
for i in ${CONFIG_FILE_PATH[@]}; do
if command grep -q "HOLLAEX_SECRET_ACTIVATION_CODE=" $i > /dev/null ; then
export SECRET_FILE_PATH=$i
fi
done
if [[ ! -d "$TEMPLATE_GENERATE_PATH/local" ]]; then
mkdir $TEMPLATE_GENERATE_PATH/local;
fi
if [[ ! -d "$HOLLAEX_CLI_INIT_PATH/nginx" ]]; then
mkdir $HOLLAEX_CLI_INIT_PATH/nginx;
fi
if [[ ! -d "$HOLLAEX_CLI_INIT_PATH/nginx/conf.d" ]]; then
mkdir $HOLLAEX_CLI_INIT_PATH/nginx/conf.d;
fi
# Running database jobs for local db.
if [[ ! "$LOCAL_COMMAND" ]] && [[ "$LOCAL_DATABASE_INIT" == true ]]; then
local_database_init start;
docker-compose -f ${HOLLAEX_CLI_INIT_PATH}/server/docker-compose-prod.yaml restart
exit 0;
fi
# Gives warning if the target has not been specified.
if [[ ! "$HOLLAEX_DEV_TARGET" ]]; then
echo -e "\nWarning: You didn't specify the dev command target!"
echo "You should specify the targer by using '--server' or '--web'."
echo -e "\nAutomatically setting up the target as '--server'...\n"
export HOLLAEX_DEV_TARGET=server
fi
if [[ "$HOLLAEX_DEV_TARGET" == "server" ]]; then
# if [[ "$HOLLAEX_DEV_SETUP" ]]; then
# # hollaex_setup_initialization;
# # fi
# if [[ "$ENVIRONMENT_DOCKER_COMPOSE_GENERATE_YAML_ENABLE" == true ]]; then
# if [[ "$HOLLAEX_DEV_FOR_CORE" ]]; then
# generate_local_docker_compose_for_core_dev;
# else
# generate_local_docker_compose_for_dev;
# fi
# fi
generate_nginx_upstream;
check_docker_compose_is_installed;
# Checking docker-compose is installed on this machine.
# if ! command docker compose version; then
# echo -e "\033[91mHollaEx CLI failed to detect docker-compose installed on this machine. Please install it before running HollaEx CLI.\033[39m"
# exit 1;
# fi
if [[ "$HOLLAEX_DEV_SETUP" ]]; then
CONTINUE_WITH_PRECONFIGURED_VALUES=false
BUILD_HOLLAEX_CORE_VERSION=$HOLLAEX_CONFIGMAP_KIT_VERSION
BUILD_HOLLAEX_CORE_BRANCH=$(git --git-dir $HOLLAEX_CLI_INIT_PATH/.git rev-parse --abbrev-ref HEAD)
BUILD_HOLLAEX_CORE_DATE="$(echo $(date +%y%m%d%H%M))"
BUILD_HOLLAEX_CORE_IMAGE_TAG="$(cat $HOLLAEX_CLI_INIT_PATH/server/package.json | jq -r '.version')-${BUILD_HOLLAEX_CORE_BRANCH}-${BUILD_HOLLAEX_CORE_DATE}"
export ENVIRONMENT_DOCKER_IMAGE_VERSION_OVERRIDE=$BUILD_HOLLAEX_CORE_IMAGE_TAG
override_docker_image_version;
export ENVIRONMENT_USER_HOLLAEX_CORE_IMAGE_VERSION=$ENVIRONMENT_DOCKER_IMAGE_VERSION_OVERRIDE
if ! build_user_hollaex_core; then
exit 1;
fi
hollaex_setup_initialization;
if [[ "$ENVIRONMENT_DOCKER_COMPOSE_GENERATE_YAML_ENABLE" == true ]]; then
if [[ "$HOLLAEX_DEV_FOR_CORE" ]]; then
generate_local_docker_compose_for_core_dev;
else
generate_local_docker_compose_for_dev;
fi
fi
#Generating random values for passwords and update config file to contain it;
update_random_values_to_config;
# Randomly generates backend passwords
if [[ ! "$HOLLAEX_SECRET_REDIS_PASSWORD" ]] || [[ ! "$HOLLAEX_SECRET_PUBSUB_PASSWORD" ]] || [[ ! "$HOLLAEX_SECRET_DB_PASSWORD" ]] ; then
generate_backend_passwords;
fi
for i in ${CONFIG_FILE_PATH[@]}; do
source $i
done;
load_config_variables;
generate_local_env;
# Regenerating docker compose file with the new image tag just defined above.
if [[ "$ENVIRONMENT_DOCKER_COMPOSE_GENERATE_YAML_ENABLE" == true ]]; then
if [[ "$HOLLAEX_DEV_FOR_CORE" ]]; then
generate_local_docker_compose_for_core_dev;
else
generate_local_docker_compose_for_dev;
fi
fi
docker-compose -f ${HOLLAEX_CLI_INIT_PATH}/server/docker-compose-prod.yaml up -d
echo "Installing npm packages for /plugins"
docker exec ${DOCKER_COMPOSE_NAME_PREFIX}${ENVIRONMENT_EXCHANGE_NAME}-server-api_1 bash -c '
cd /app/plugins && \
npm install --loglevel=error && \
for d in ./*/ ; do (cd "$d" && npm install --loglevel=error); done'
hollaex dev --database_init
docker-compose -f ${HOLLAEX_CLI_INIT_PATH}/server/docker-compose-prod.yaml restart
hollaex_setup_finalization;
docker-compose -f ${HOLLAEX_CLI_INIT_PATH}/server/docker-compose-prod.yaml restart
elif [[ "$HOLLAEX_DEV_RESTART" ]]; then
docker-compose -f ${HOLLAEX_CLI_INIT_PATH}/server/docker-compose-prod.yaml stop
docker-compose -f ${HOLLAEX_CLI_INIT_PATH}/server/docker-compose-prod.yaml up -d
if [[ ! "$HOLLAEX_DEV_SETUP" ]]; then
echo "Installing npm packages for /plugins"
docker exec ${DOCKER_COMPOSE_NAME_PREFIX}${ENVIRONMENT_EXCHANGE_NAME}-server-api_1 bash -c '
cd /app/plugins && \
npm install --loglevel=error && \
for d in ./*/ ; do (cd "$d" && npm install --loglevel=error); done'
fi
else
docker-compose -f ${HOLLAEX_CLI_INIT_PATH}/server/docker-compose-prod.yaml $LOCAL_COMMAND
fi
# WEB
elif [[ "$HOLLAEX_DEV_TARGET" == "web" ]]; then
generate_hollaex_web_local_env
cd web
if [[ "$HOLLAEX_DEV_SETUP" ]]; then
npm install
npm run start
elif [[ "$HOLLAEX_DEV_START" ]]; then
npm run start
else
echo -e "\nError: Invalid Command."
echo -e "Supported commands for the web: '--setup', '--start'.\n"
fi
fi
exit 0
elif [[ "$1" == "init" ]]; then
HOLLAEX_CLI_INIT_PATH=$(pwd)
CONFIG_FILE_PATH=$(pwd)/settings/*
TEMPLATE_GENERATE_PATH=$(pwd)/templates
INIT_PATH_CHECK=$(pwd)/.hollaex
TEMP_CONFIG_FILE=$(pwd)/settings/temp
source $SCRIPTPATH/tools_generator.sh
hollaex_setup_existing_settings_values_check;
# if [[ -f "$TEMP_CONFIG_FILE" ]]; then
# source $(pwd)/settings/configmap
# source $(pwd)/settings/temp
# echo -e "\n\033[93mWarning: HollaEx CLI has detected your existing exchange information.\033[39m\n"
# echo "Network: $HOLLAEX_CONFIGMAP_NETWORK_URL"
# echo "Network Exchange ID: $HOLLAEX_CONFIGMAP_ADMIN_NETWORK_ID"
# echo "Exchange Name: $ENVIRONMENT_EXCHANGE_NAME"
# echo "Admin Email: $HOLLAEX_CONFIGMAP_ADMIN_EMAIL"
# echo "Admin Password: $(echo ${HOLLAEX_CONFIGMAP_ADMIN_PASSWORD//?/◼︎}$(echo $HOLLAEX_CONFIGMAP_ADMIN_PASSWORD | grep -o '....$'))"
# echo -e "\nDo you want to continue with the existing information? (Y/n)"
# read answer
# if [[ ! "$answer" = "${answer#[Nn]}" ]]; then
# echo "Proceeding to the initialization wizard..."
# else
# echo "Skipping the initialization wizard..."
# exit 0
# fi
# fi
printf "\n\033[1mSelect the network\033[0m\n\n"
echo -e "Before you continue, You need to \033[1mselect the network\033[0m that you want to use with the exchange."
echo -e "HollaEx Kit by default, will be connected to the official \033[1mmainnet\033[0m HollaEx Network (\033[1mapi.hollaex.network\033[0m)."
echo -e "You can also run HollaEx Kit with official \033[1mtestnet\033[0m HollaEx Network for testing purpose (\033[1mapi.testnet.hollaex.network\033[0m)."
echo -e "If you want to connect to a different custom network, you can type the URL.\n"
# echo -e "Do you want to want to continue with the official HollaEx Network? (Y/n)\n"
# read answer
flag=1
list=(
"1) $(echo -e '\033[1mMainnet\033[0m') HollaEx Network"
"2) Testnet HollaEx Network"
"3) Custom HollaEx Network
"
)
message()
{
echo
printf "%s\n" "${list[@]}"
read -p "Please select the network: " networkOption
echo
}
message
while [[ $flag = '1' ]]
do
{
case $networkOption in
1)
export hollaexAPIURL=https://api.hollaex.network
export networkType="mainnet"
flag=0
;;
2)
export hollaexAPIURL=https://api.testnet.hollaex.network
export networkType="testnet"
flag=0
;;
3)
export networkType="custom"
echo "***************************************************************"
printf "\nPlease type the URL of your custom network including 'http' or 'https'. (Example: https://api.hollaex.network)\n"
read hollaexAPIURL
while true;
do if [[ ! "$hollaexAPIURL" == *"http"* ]]; then
printf "\nPlease confirm that you typed in a correct url, including 'http' or 'https'.\n"
echo "Custom Network API URL: "
read hollaexAPIURL
else
break;
fi
done
flag=0
;;
*)
echo "Error: Invalid Option. Please select it again."
flag=1
message
;;
esac
}
done
# Network URL health check
while true;
do if command curl $hollaexAPIURL/v2/health; then
printf "\n\033[92mSuccessfully reached to the network health page.\033[39m\n"
break;
else
printf "\033[91m\nNetwork health page is not responding.\033[39m\n"
echo "Please try it again after you check the URL."
exit 1;
fi
done
printf "\n"
echo "${hollaexAPIURL} ✔"
printf "\n"
if [[ "$hollaexAPIURL" == *"http://localhost"* ]]; then
export HOLLAEX_INIT_LOCALHOST_MODE_INTERNAL_DOMAIN="http://host.docker.internal"
HOLLAEX_INIT_LOCALHOST_MODE_INTERNAL_PORT=$(echo $hollaexAPIURL | cut -f3 -d ":")
export HOLLAEX_INIT_LOCALHOST_MODE_INTERNAL_PORT=${HOLLAEX_INIT_LOCALHOST_MODE_INTERNAL_PORT:-80}
export HOLLAEX_INIT_LOCALHOST_MODE_INTERNAL_URL="$HOLLAEX_INIT_LOCALHOST_MODE_INTERNAL_DOMAIN:$HOLLAEX_INIT_LOCALHOST_MODE_INTERNAL_PORT"
export hollaexAPIURLEscaped=${HOLLAEX_INIT_LOCALHOST_MODE_INTERNAL_URL//\//\\/}
export HOLLAEX_NETWORK_LOCALHOST_MODE=true
else
export hollaexAPIURLEscaped=${hollaexAPIURL//\//\\/}
fi
if [[ "$RESTORE_FROM_BACKUP" ]]; then
echo "***************************************************************"
printf "\n\033[1mExchange Name\033[0m\n\n"
echo -e "Please type in the name of your new exchange."
printf "\033[2m- Alphanumeric, Dash (-), Underscore Only (_). No space or special character allowed.\033[22m\n"
read hollaexExchangeName
while true;
do if [[ ! "$hollaexExchangeName" =~ ^[A-Za-z0-9_-]+$ ]]; then
printf "\nInvalid Exchange Name. Make sure to input Alphanumeric, Dash (-), Underscore Only (_).\n"
echo "New Exchange Name: "
read hollaexExchangeName
else
break;
fi
done
printf "\n"
echo "$hollaexExchangeName ✔"
printf "\n"
# Update settings files with provided values
for i in ${CONFIG_FILE_PATH[@]}; do
if command grep -q "ENVIRONMENT_EXCHANGE_NAME" $i > /dev/null ; then
CONFIGMAP_FILE_PATH=$i
# sed -i.bak "s/ENVIRONMENT_EXCHANGE_NAME=.*/ENVIRONMENT_EXCHANGE_NAME=hollaex-kit/" $CONFIGMAP_FILE_PATH
sed -i.bak "s/HOLLAEX_CONFIGMAP_API_NAME=.*/HOLLAEX_CONFIGMAP_API_NAME=$hollaexExchangeName/" $CONFIGMAP_FILE_PATH
sed -i.bak "s/HOLLAEX_CONFIGMAP_NETWORK_URL=.*/HOLLAEX_CONFIGMAP_NETWORK_URL=$hollaexAPIURLEscaped/" $CONFIGMAP_FILE_PATH
rm $CONFIGMAP_FILE_PATH.bak
fi
done
echo -e "\n\033[92mSuccessfully set the exchange name $hollaexExchangeName for the restore.\033[39m"
else
if [[ $networkType == "mainnet" ]]; then
echo "***************************************************************"
echo -e "All HollaEx Kit connected to the Mainnet HollaEx Network require to have an account on HollaEx Dashboard.\n"
echo -e "If you already have an account, please proceed to login."
echo -e "For registration, please check out https://dash.hollaex.com."
echo -e "\nDo you have an account on HollaEx Dashboard? (y/N)"
read answer
if [[ "$answer" = "${answer#[Yy]}" ]]; then
echo -e "Please sign up on HollaEx Dashboard through https://dash.hollaex.com/signup.\n"
if [[ "$OSTYPE" == *"darwin"* ]]; then
open https://dash.hollaex.com/signup
else
if ! command xdg-open https://dash.hollaex.com/signup > /dev/null 2>&1; then
echo "Error: Your system does not support xdg-open compatible browser."
echo "Please open HollaEx Dashboard (https://dash.hollaex.com/signup) by yourself, and continue to sign-up."
fi
fi
echo -e "\nOnce the registration and the DIY exchange setup are completed, please press C to continue."
read answer
while true;
do if [[ "$answer" = "${answer#[Cc]}" ]]; then
echo -e "\nOnce the registration is completed, please press C to continue."
read answer
else
break;
fi
done
fi
while true;
do if ! command hollaex login; then
rm -f $(pwd)/.token
else
if ! command hollaex pull --skip; then
exit 1;
fi
break;
fi
done
else
printf "\n\033[1mCreate Admin\033[0m\n\n"
echo -e "Please type your email address and password that you are going to use for your admin account.\n"
echo "Email: "
read hollaexAdminEmail
while true;
do if [[ ! "$hollaexAdminEmail" == *"@"* ]]; then
printf "\nInvalid email address. Please type it again.\n"
echo "Email: "
read hollaexAdminEmail
else
break;
fi
done
echo -e "\nPassword: "
printf "\033[2m-Password must contain at least 8 characters and one digit.\033[22m\n\n"
read -s hollaexAdminPassword
while true;
do if [[ ${#hollaexAdminPassword} -lt 8 || ! "$hollaexAdminPassword" =~ [0-9] ]]; then
printf "\nInvalid password. Please type it again.\n"
printf "\033[2m-Password must contain at least 8 characters and one digit.\033[22m\n\n"
echo "Password: "
read -s hollaexAdminPassword
else
break;
fi
done
printf "\n\033[1mCreate Exchange\033[0m\n\n"
echo -e "Please type in the name of your new exchange."
printf "\033[2m- Alphanumeric, Dash (-), Underscore Only (_). No space or special character allowed.\033[22m\n"
read hollaexExchangeName
while true;
do if [[ ! "$hollaexExchangeName" =~ ^[A-Za-z0-9_-]+$ ]]; then
printf "\nInvalid Exchange Name. Make sure to input Alphanumeric, Dash (-), Underscore Only (_).\n"
echo "New Exchange Name: "
read hollaexExchangeName
else
break;
fi
done
printf "\n"
echo "$hollaexExchangeName ✔"
printf "\n"
HOLLAEX_INIT_REQUEST=$(curl -s -H "Content-Type: application/json" \
-w ";%{http_code}" \
--request POST \
--data "{\"email\": \"${hollaexAdminEmail}\", \"password\": \"${hollaexAdminPassword}\", \"exchange_name\": \"${hollaexExchangeName}\"}" \
$hollaexAPIURL/v2/network/exchange)
# echo $HOLLAEX_INIT_REQUEST
HOLLAEX_INIT_REQUEST_RESPONSE=$(echo $HOLLAEX_INIT_REQUEST | cut -f1 -d ";")
HOLLAEX_INIT_REQUEST_HTTP_CODE=$(echo $HOLLAEX_INIT_REQUEST | cut -f2 -d ";")
# Creating an admin account with exchange
if [[ ! "$HOLLAEX_INIT_REQUEST_HTTP_CODE" == "200" ]]; then
echo $HOLLAEX_INIT_REQUEST_RESPONSE | jq -r '.message'
echo -e "\nError: Failed to create an account on HollaEx Network."
echo "Please review the logs and try it again."
exit 1;
fi
export HOLLAEX_SECRET_API_KEY=$(echo $HOLLAEX_INIT_REQUEST_RESPONSE | jq -r '.token.apiKey')
export HOLLAEX_SECRET_API_SECRET=$(echo $HOLLAEX_INIT_REQUEST_RESPONSE | jq -r '.token.secret')
export HOLLAEX_SECRET_ACTIVATION_CODE=$(echo $HOLLAEX_INIT_REQUEST_RESPONSE | jq -r '.exchange.activation_code')
export HOLLAEX_CONFIGMAP_ADMIN_NETWORK_ID=$(echo $HOLLAEX_INIT_REQUEST_RESPONSE | jq -r '.user.id')
# Update settings files with provided values
for i in ${CONFIG_FILE_PATH[@]}; do
if command grep -q "ENVIRONMENT_EXCHANGE_NAME" $i > /dev/null ; then
CONFIGMAP_FILE_PATH=$i
# sed -i.bak "s/ENVIRONMENT_EXCHANGE_NAME=.*/ENVIRONMENT_EXCHANGE_NAME=hollaex-kit/" $CONFIGMAP_FILE_PATH
sed -i.bak "s/HOLLAEX_CONFIGMAP_API_NAME=.*/HOLLAEX_CONFIGMAP_API_NAME=$hollaexExchangeName/" $CONFIGMAP_FILE_PATH
sed -i.bak "s/HOLLAEX_CONFIGMAP_NETWORK_URL=.*/HOLLAEX_CONFIGMAP_NETWORK_URL=$hollaexAPIURLEscaped/" $CONFIGMAP_FILE_PATH
rm $CONFIGMAP_FILE_PATH.bak
fi
if command grep -q "HOLLAEX_SECRET_ACTIVATION_CODE" $i > /dev/null ; then
SECRET_FILE_PATH=$i
sed -i.bak "s/HOLLAEX_SECRET_ACTIVATION_CODE=.*/HOLLAEX_SECRET_ACTIVATION_CODE=$HOLLAEX_SECRET_ACTIVATION_CODE/" $SECRET_FILE_PATH
sed -i.bak "s/HOLLAEX_SECRET_API_KEY=.*/HOLLAEX_SECRET_API_KEY=$HOLLAEX_SECRET_API_KEY/" $SECRET_FILE_PATH
sed -i.bak "s/HOLLAEX_SECRET_API_SECRET=.*/HOLLAEX_SECRET_API_SECRET=$HOLLAEX_SECRET_API_SECRET/" $SECRET_FILE_PATH
rm $SECRET_FILE_PATH.bak
fi
done
# Store Network ID, Admin email and password to a temporary file
echo "HOLLAEX_CONFIGMAP_ADMIN_NETWORK_ID=$HOLLAEX_CONFIGMAP_ADMIN_NETWORK_ID" > $(pwd)/settings/temp
echo "HOLLAEX_CONFIGMAP_ADMIN_EMAIL=$hollaexAdminEmail" >> $(pwd)/settings/temp
echo "HOLLAEX_CONFIGMAP_ADMIN_PASSWORD=$hollaexAdminPassword" >> $(pwd)/settings/temp
echo -e "\n\033[92mSuccessfully initialized the exchange $hollaexExchangeName and the account $hollaexAdminEmail.\033[39m"
fi
fi
echo "HOLLAEX_CONFIGMAP_NETWORK_URL=$hollaexAPIURL" > $INIT_PATH_CHECK
if [[ ! "$HOLLAEX_IS_SETUP" ]]; then
echo "Please run 'hollaex server --setup' command to set up the exchange."
fi
echo -e "\nHave fun!"
exit 0;
elif [[ "$1" == "server" ]]; then
while true; do
[[ $# -eq 0 ]] && break
case $1 in
--setup)
hollaex setup ${@:2}
break
;;
--start)
hollaex start ${@:2}
break
;;
--stop)
hollaex stop ${@:2}
break
;;
--restart)
hollaex restart ${@:2}
break
;;
--scale)
hollaex scale ${@:2}
break
;;
--upgrade)
hollaex upgrade ${@:2}
break
;;
--build)
hollaex build ${@:2}
break
;;