-
Notifications
You must be signed in to change notification settings - Fork 2
/
Dockerfile
1146 lines (888 loc) · 28 KB
/
Dockerfile
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
FROM ubuntu:latest
ARG DEBIAN_FRONTEND=noninteractive
ARG TZ="Etc/GMT"
ARG LOCK_APT=${LOCK_APT:-"TRUE"}
ARG ADMIN_USERNAME
ARG ADMIN_PASSWORD
ARG AUTO_SIGNIN
ARG FUN_FRONTEND_REPOSITORY_URL="${FUN_FRONTEND_REPOSITORY_URL:-https://github.com/funttastic/fun-hb-frontend.git}"
ARG FUN_FRONTEND_REPOSITORY_BRANCH="${FUN_FRONTEND_REPOSITORY_BRANCH:-production}"
ARG FUN_FRONTEND_COMMAND
ARG FUN_FRONTEND_PORT
ARG FUN_CLIENT_REPOSITORY_URL="${FUN_CLIENT_REPOSITORY_URL:-https://github.com/funttastic/fun-hb-client.git}"
ARG FUN_CLIENT_REPOSITORY_BRANCH="${FUN_CLIENT_REPOSITORY_BRANCH:-production}"
ARG FUN_CLIENT_COMMAND
ARG FUN_CLIENT_PORT
ARG HB_GATEWAY_REPOSITORY_URL=${HB_GATEWAY_REPOSITORY_URL:-https://github.com/Team-Kujira/gateway.git}
ARG HB_GATEWAY_REPOSITORY_BRANCH=${HB_GATEWAY_REPOSITORY_BRANCH:-production}
ARG HB_GATEWAY_COMMAND
ARG HB_GATEWAY_PORT
ARG HB_CLIENT_REPOSITORY_URL=${HB_CLIENT_REPOSITORY_URL:-https://github.com/Team-Kujira/hummingbot.git}
ARG HB_CLIENT_REPOSITORY_BRANCH=${HB_CLIENT_REPOSITORY_BRANCH:-production}
ARG HB_CLIENT_COMMAND
ARG FILEBROWSER_COMMAND
ARG FILEBROWSER_PORT
EXPOSE $FUN_FRONTEND_PORT
EXPOSE $FILEBROWSER_PORT
WORKDIR /root
RUN :> /root/.bashrc
RUN rm /usr/bin/sh && ln -s /bin/bash /usr/bin/sh
RUN <<-EOF
set -ex
apt-get update
apt-get install --no-install-recommends -y \
git \
gcc \
vim \
less \
tree \
curl \
psmisc \
python3 \
python3-pip \
python3-dev \
libarchive-dev \
libusb-1.0 \
libssl-dev \
pkg-config \
libsecret-1-0 \
openssh-server \
build-essential \
ca-certificates \
postgresql-server-dev-all \
tmux \
jq \
multitail
# gnutls-bin
set +ex
EOF
RUN <<-EOF
set -ex
echo -e "\n" >> ~/.bashrc
# Funttastic Client Frontend environment variables
if [ -z "$FUN_FRONTEND_PORT" ]
then
echo 'export FUN_FRONTEND_PORT=50000' >> ~/.bashrc
else
echo "export FUN_FRONTEND_PORT=$FUN_FRONTEND_PORT" >> ~/.bashrc
fi
if [ -z "$FUN_FRONTEND_COMMAND" ]
then
echo "export FUN_FRONTEND_COMMAND=\"APP=fun-frontend yarn start --host\"" >> ~/.bashrc
else
echo "export FUN_FRONTEND_COMMAND=\"$FUN_FRONTEND_COMMAND\"" >> ~/.bashrc
fi
# FileBrowser environment variables
if [ -z "$FILEBROWSER_PORT" ]
then
echo 'export FILEBROWSER_PORT=50002' >> ~/.bashrc
else
echo "export FILEBROWSER_PORT=$FILEBROWSER_PORT" >> ~/.bashrc
fi
echo 'export VITE_FILEBROWSER_PORT=$FILEBROWSER_PORT' >> ~/.bashrc
if [ -z "$FILEBROWSER_COMMAND" ]
then
echo "export FILEBROWSER_COMMAND=\"APP=filebrowser filebrowser --address=0.0.0.0 -p \$FILEBROWSER_PORT -r ../shared\"" >> ~/.bashrc
else
echo "export FILEBROWSER_COMMAND=\"$FILEBROWSER_COMMAND\"" >> ~/.bashrc
fi
# Funttastic Client server environment variables
if [ -z "$FUN_CLIENT_PORT" ]
then
echo 'export FUN_CLIENT_PORT=50001' >> ~/.bashrc
else
echo "export FUN_CLIENT_PORT=$FUN_CLIENT_PORT" >> ~/.bashrc
fi
if [ -z "$FUN_CLIENT_COMMAND" ]
then
echo "export FUN_CLIENT_COMMAND=\"APP=fun-client python app.py\"" >> ~/.bashrc
else
echo "export FUN_CLIENT_COMMAND=\"$FUN_CLIENT_COMMAND\"" >> ~/.bashrc
fi
# HB Gateway environment variables
if [ -z "$HB_GATEWAY_PORT" ]
then
echo 'export HB_GATEWAY_PORT=15888' >> ~/.bashrc
else
echo "export HB_GATEWAY_PORT=$HB_GATEWAY_PORT" >> ~/.bashrc
fi
if [ -z "$HB_GATEWAY_COMMAND" ]
then
echo "export HB_GATEWAY_COMMAND=\"APP=hb-gateway yarn start\"" >> ~/.bashrc
else
echo "export HB_GATEWAY_COMMAND=\"$HB_GATEWAY_COMMAND\"" >> ~/.bashrc
fi
# HB Client environment variables
if [ -z "$HB_CLIENT_COMMAND" ]
then
echo "export HB_CLIENT_COMMAND=\"APP=hb-client python bin/hummingbot_quickstart.py; exit\"" >> ~/.bashrc
else
echo "export HB_CLIENT_COMMAND=\"$HB_CLIENT_COMMAND\"" >> ~/.bashrc
fi
echo -e "\n" >> ~/.bashrc
set +ex
EOF
RUN <<-EOF
set -ex
unlink /usr/bin/pip
ln -s /usr/bin/python3 /usr/bin/python
ln -s /usr/bin/pip3 /usr/bin/pip
set +ex
EOF
RUN <<-EOF
set -ex
ARCHITECTURE="$(uname -m)"
case $(uname | tr '[:upper:]' '[:lower:]') in
linux*)
OS="Linux"
FILE_EXTENSION="sh"
case $(uname -r | tr '[:upper:]' '[:lower:]') in
*raspi*)
IS_RASPBERRY="TRUE"
;;
*)
IS_RASPBERRY="FALSE"
;;
esac
;;
darwin*)
OS="MacOSX"
FILE_EXTENSION="sh"
;;
msys*)
OS="Windows"
FILE_EXTENSION="exe"
;;
*)
echo "Unrecognized OS"
exit 1
;;
esac
echo "export ARCHITECTURE=$ARCHITECTURE" >> /root/.bashrc
echo "export OS=$OS" >> /root/.bashrc
echo "export FILE_EXTENSION=$FILE_EXTENSION" >> /root/.bashrc
echo "export IS_RASPBERRY=$IS_RASPBERRY" >> /root/.bashrc
if [ "$ARCHITECTURE" == "aarch64" ]
then
echo "export ARCHITECTURE_SUFFIX=\"-$ARCHITECTURE\"" >> /root/.bashrc
MINICONDA_VERSION="Mambaforge-$(uname)-$(uname -m).sh"
MINICONDA_URL="https://github.com/conda-forge/miniforge/releases/latest/download/$MINICONDA_VERSION"
ln -s /root/mambaforge /root/miniconda3
else
MINICONDA_VERSION="Miniconda3-py38_4.10.3-$OS-$ARCHITECTURE.$FILE_EXTENSION"
MINICONDA_URL="https://repo.anaconda.com/miniconda/$MINICONDA_VERSION"
fi
curl -L "$MINICONDA_URL" -o "/root/miniconda.$MINICONDA_EXTENSION"
/bin/bash "/root/miniconda.$MINICONDA_EXTENSION" -b
rm "/root/miniconda.$MINICONDA_EXTENSION"
echo 'export PATH=/root/miniconda3/bin:$PATH' >> /root/.bashrc
source /root/.bashrc
conda update -n base -c conda-forge conda -y
conda clean -tipy
echo "export MINICONDA_VERSION=$MINICONDA_VERSION" >> /root/.bashrc
echo "export MINICONDA_URL=$MINICONDA_URL" >> /root/.bashrc
conda init --all
set +ex
EOF
RUN <<-EOF
set -ex
source /root/.bashrc
# git config --global http.postBuffer 524288000
# git config --global https.postBuffer 524288000
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
nvm install --lts
nvm cache clear
# if [ ! "$ARCHITECTURE" == "aarch64" ]
# then
# npm install --unsafe-perm --only=production -g @celo/[email protected]
# fi
npm install --global yarn
npm cache clean --force
rm -rf /root/.cache
set +ex
EOF
RUN <<-EOF
set -ex
source /root/.bashrc
mkdir -p funttastic/client
cd funttastic/client
# git config --global http.postBuffer 524288000
# git config --global https.postBuffer 524288000
git clone -b $FUN_CLIENT_REPOSITORY_BRANCH $FUN_CLIENT_REPOSITORY_URL .
conda env create -f environment.yml --solver=classic
mkdir -p resources/certificates
cp resources/configuration/production.example.yml resources/configuration/production.yml
cp -a resources/strategies/templates/. resources/strategies
set +ex
EOF
RUN <<-EOF
set -ex
source /root/.bashrc
mkdir -p funttastic/frontend
cd funttastic/frontend
# git config --global http.postBuffer 524288000
# git config --global https.postBuffer 524288000
git clone -b $FUN_FRONTEND_REPOSITORY_BRANCH $FUN_FRONTEND_REPOSITORY_URL .
yarn install
set +ex
EOF
RUN <<-EOF
set -ex
curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash
rm -f get.sh
mkdir -p filebrowser/branding/img
cd filebrowser
filebrowser config init
filebrowser config set --branding.name "Funttastic"
filebrowser config set --branding.theme "dark"
filebrowser config set --branding.files /root/filebrowser/branding
filebrowser config set --port $FILEBROWSER_PORT
filebrowser config set --baseurl /
cp /root/funttastic/frontend/resources/assets/funttastic/logo/logo.svg branding/img/logo.svg
cat <<'CSS' > branding/custom.css
html {
scrollbar-width: none;
}
header {
padding: 0.5em 0 0.5em 0;
}
header img {
display: none;
}
CSS
set +ex
EOF
RUN <<-EOF
set -ex
source /root/.bashrc
# git config --global http.postBuffer 524288000
# git config --global https.postBuffer 524288000
mkdir -p hummingbot/gateway
cd hummingbot/gateway
git clone -b $HB_GATEWAY_REPOSITORY_BRANCH $HB_GATEWAY_REPOSITORY_URL .
mkdir -p \
certs \
db \
conf \
logs \
/var/lib
cp -a src/templates/. conf
yarn
yarn prebuild
yarn build
set +ex
EOF
RUN <<-EOF
set -ex
source /root/.bashrc
mkdir -p hummingbot/client
cd hummingbot/client
# git config --global http.postBuffer 524288000
# git config --global https.postBuffer 524288000
git clone -b $HB_CLIENT_REPOSITORY_BRANCH $HB_CLIENT_REPOSITORY_URL .
MINICONDA_ENVIRONMENT=$(head -1 setup/environment.yml | cut -d' ' -f2)
if [ -z "$MINICONDA_ENVIRONMENT" ]
then
echo "The MINICONDA_ENVIRONMENT environment variable could not be defined."
exit 1
fi
echo "export MINICONDA_ENVIRONMENT=$MINICONDA_ENVIRONMENT" >> /root/.bashrc
conda env create -f setup/environment.yml --solver=classic
conda clean -tipy
rm -rf /root/.cache
echo "source /root/miniconda3/etc/profile.d/conda.sh && conda activate $MINICONDA_ENVIRONMENT" >> /root/.bashrc
/root/miniconda3/envs/$MINICONDA_ENVIRONMENT/bin/python3 setup.py build_ext --inplace -j 8
rm -rf build/
find . -type f -name "*.cpp" -delete
mkdir -p \
certs \
conf/connectors \
conf/strategies \
conf/scripts \
logs \
data \
scripts \
pmm_scripts
set +ex
EOF
RUN <<-EOF
set -ex
rm -rf /root/temp
source /root/.bashrc
conda activate funttastic
ln -rfs funttastic/client/resources/certificates/* hummingbot/gateway/certs
ln -rfs funttastic/client/resources/certificates/* hummingbot/client/certs
sed -i -e "/server:/,/port: [0-9]*/ s/port: [0-9]*/port: $FUN_CLIENT_PORT/" funttastic/client/resources/configuration/production.yml
sed -i -e '/logging:/,/use_telegram:/ s/use_telegram:.*/use_telegram: false/' -e '/telegram:/,/enabled:/ s/enabled:.*/enabled: false/' -e '/telegram:/,/listen_commands:/ s/listen_commands:.*/listen_commands: false/' funttastic/client/resources/configuration/production.yml
sed -i -e '/telegram:/,/enabled:/ s/enabled:.*/enabled: false/' -e '/telegram:/,/listen_commands:/ s/listen_commands:.*/listen_commands: false/' funttastic/client/resources/configuration/common.yml
set +ex
EOF
RUN <<-EOF
set -ex
mkdir -p /root/shared/logs/tmux
ln -s /root/funttastic/client/resources/logs /root/shared/logs/fun-client
ln -s /root/hummingbot/gateway/logs /root/shared/logs/hb-gateway
ln -s /root/hummingbot/client/logs /root/shared/logs/hb-client
mkdir -p /root/shared/scripts
cat <<'SCRIPT' > shared/scripts/functions.sh
#!/bin/bash
start_fun_frontend() {
local session="fun-frontend"
if [ "$(is_session_running "$session")" = "FALSE" ]; then
tmux new-session -d -s "$session" \; pipe-pane -o "cat >> ~/shared/logs/tmux/$session.log"
tmux send-keys -t "$session" "cd /root/funttastic/frontend" C-m
tmux send-keys -t "$session" "$FUN_FRONTEND_COMMAND" C-m
fi
}
start_filebrowser() {
local session="filebrowser"
if [ "$(is_session_running "$session")" = "FALSE" ]; then
tmux new-session -d -s "$session" \; pipe-pane -o "cat >> ~/shared/logs/tmux/$session.log"
tmux send-keys -t "$session" "cd /root/filebrowser" C-m
tmux send-keys -t "$session" "$FILEBROWSER_COMMAND" C-m
fi
}
start_fun_client() {
local password="$1"
local session="fun-client"
if [ "$(is_session_running "$session")" = "FALSE" ]; then
tmux new-session -d -s "$session" \; pipe-pane -o "cat >> ~/shared/logs/tmux/$session.log"
# tmux set-environment -t "$session" PASSWORD "$password"
# tmux send-keys -t "$session" "export PASSWORD=\"$(tmux show-environment PASSWORD | cut -d= -f2)\"" C-m
tmux send-keys -t "$session" "export PASSWORD=\"$password\"" C-m
tmux send-keys -t "$session" "conda activate funttastic" C-m
tmux send-keys -t "$session" "cd /root/funttastic/client" C-m
tmux send-keys -t "$session" "$FUN_CLIENT_COMMAND" C-m
# tmux set-environment -t "$session" -u PASSWORD
fi
}
start_hb_gateway() {
local password="$1"
local session="hb-gateway"
if [ "$(is_session_running "$session")" = "FALSE" ]; then
tmux new-session -d -s "$session" \; pipe-pane -o "cat >> ~/shared/logs/tmux/$session.log"
# tmux set-environment -t "$session" GATEWAY_PASSPHRASE "$password"
# tmux send-keys -t "$session" "export GATEWAY_PASSPHRASE=\"$(tmux show-environment GATEWAY_PASSPHRASE | cut -d= -f2)\"" C-m
tmux send-keys -t "$session" "export GATEWAY_PASSPHRASE=\"$password\"" C-m
tmux send-keys -t "$session" "cd /root/hummingbot/gateway" C-m
tmux send-keys -t "$session" "$HB_GATEWAY_COMMAND" C-m
# tmux set-environment -t "$session" -u GATEWAY_PASSPHRASE
fi
}
start_hb_client() {
local session="hb-client"
if [ "$(is_session_running "$session")" = "FALSE" ]; then
tmux new-session -d -s "$session" \; pipe-pane -o "cat >> ~/shared/logs/tmux/$session.log"
tmux send-keys -t "$session" "conda activate hummingbot" C-m
tmux send-keys -t "$session" "cd /root/hummingbot/client" C-m
tmux send-keys -t "$session" "$HB_CLIENT_COMMAND" C-m
fi
}
keep() {
if [ "$(is_process_running "keep")" = "FALSE" ]; then
APP=keep tail -f /dev/null
fi
}
start_all() {
local username="$1"
local password="$2"
start_fun_frontend
start_filebrowser
start_fun_client "$password"
start_hb_gateway "$password"
start_hb_client
}
start() {
local credentials
local username="${1:-$ADMIN_USERNAME}"
local password="${2:-$ADMIN_PASSWORD}"
args_to_check=("--start_all" "--start_fun_frontend" "--start_filebrowser" "--start_fun_client" "--start_hb_gateway" "--start_hb_client")
for arg in "${args_to_check[@]}"; do
if [[ "$username" == "$arg" ]]; then
username=""
break
fi
done
for arg in "${args_to_check[@]}"; do
if [[ "$password" == "$arg" ]]; then
password=""
break
fi
done
source ~/.bashrc
if [[ -n "$username" && -n "$password" ]]; then
credentials=$(authenticate "$username" "$password")
elif [ -f "/root/.temp_credentials" ]; then
# This condition is only for the first start.
username=$(grep "username" "/root/.temp_credentials" | cut -d'=' -f2)
password=$(grep "password" "/root/.temp_credentials" | cut -d'=' -f2)
credentials=$(authenticate "$username" "$password")
if [ -n "$credentials" ]; then
rm -f /root/.temp_credentials
fi
else
credentials=$(authenticate)
fi
if [ -z "$credentials" ] || echo "$credentials" | grep -iq "error"; then
echo "$credentials" >&2
return 1
else
username=$(extract_from_json "username" "$credentials")
password=$(extract_from_json "password" "$credentials")
fi
if [[ "$*" != *"--start_fun_frontend"* && \
"$*" != *"--start_filebrowser"* && \
"$*" != *"--start_fun_client"* && \
"$*" != *"--start_hb_gateway"* && \
"$*" != *"--start_hb_client"* ]]
then
start_all "$username" "$password"
return
fi
while [[ $# -gt 0 ]]; do
case "$1" in
--start_all)
start_all "$username" "$password"
return
;;
--start_fun_frontend)
start_fun_frontend
return
;;
--start_filebrowser)
start_filebrowser
return
;;
--start_fun_client)
start_fun_client
return
;;
--start_hb_gateway)
start_hb_gateway "$password"
return
;;
--start_hb_client)
start_hb_client
return
;;
*)
esac
shift
done
}
is_session_running() {
local session="$1"
tmux has-session -t "$session" 2>/dev/null
if [ $? -eq 0 ]; then
echo "TRUE"
else
echo "FALSE"
fi
}
is_process_running() {
local app="$1"
local target_pids parent_pids child_pids
target_pids=$(grep -l "\bAPP=$app\b" /proc/*/environ | cut -d/ -f3 || true)
if [ ! -z "$target_pids" ]; then
echo "TRUE"
else
echo "FALSE"
fi
}
kill_processes_and_subprocesses() {
local app="$1"
local target_pids parent_pids child_pids
target_pids=$(grep -l "\bAPP=$app\b" /proc/*/environ | cut -d/ -f3 || true)
if [ ! -z "$target_pids" ]; then
parent_pids=$(echo "$target_pids" | grep -o -E '([0-9]+)' | tr "\n" " ")
for parent_pid in $parent_pids; do
child_pids=$(pstree -p $parent_pid | grep -o -E '([0-9]+)' | tr "\n" " ")
kill -9 $parent_pid 2>/dev/null || true
for child_pid in $child_pids; do
kill -9 $child_pid 2>/dev/null || true
done
done
fi
}
stop_fun_frontend() {
tmux kill-session -t "fun-frontend"
}
stop_filebrowser() {
tmux kill-session -t "filebrowser"
}
stop_fun_client() {
tmux kill-session -t "fun-client"
}
stop_hb_gateway() {
tmux kill-session -t "hb-gateway"
}
stop_hb_client() {
tmux kill-session -t "hb-client"
}
stop_all() {
stop_fun_frontend
stop_filebrowser
stop_fun_client
stop_hb_gateway
stop_hb_client
}
stop() {
source ~/.bashrc
if [[ $# -eq 0 ]]; then
stop_all
return
fi
while [[ $# -gt 0 ]]; do
case "$1" in
--stop_all)
stop_all
return
;;
--stop_fun_frontend)
stop_fun_frontend
return
;;
--stop_filebrowser)
stop_filebrowser
return
;;
--stop_fun_client)
stop_fun_client
return
;;
--stop_hb_gateway)
stop_hb_gateway
return
;;
--stop_hb_client)
stop_hb_client
return
;;
*)
esac
shift
done
}
status() {
local fun_frontend_status=$(tmux has-session -t "fun-frontend" 2>/dev/null && echo "running" || echo "stopped")
local filebrowser_status=$(tmux has-session -t "filebrowser" 2>/dev/null && echo "running" || echo "stopped")
local fun_client_status=$(tmux has-session -t "fun-client" 2>/dev/null && echo "running" || echo "stopped")
local hb_client_status=$(tmux has-session -t "hb-client" 2>/dev/null && echo "running" || echo "stopped")
local hb_gateway_status=$(tmux has-session -t "hb-gateway" 2>/dev/null && echo "running" || echo "stopped")
output=$(cat << OUTPUT
{
"fun-frontend": "$fun_frontend_status",
"filebrowser": "$filebrowser_status",
"fun-client": "$fun_client_status",
"hb-client": "$hb_client_status",
"hb-gateway": "$hb_gateway_status"
}
OUTPUT
)
echo $output
}
encrypt_message() {
local message=$1
# After encryption, it is converted to base64 format to avoid failures in transfers between variables and programs
local encrypted_message_base64=$(echo "$message" | openssl pkeyutl -encrypt -pubin -inkey /root/.ssh/id_rsa_openssl.pub.pem -pkeyopt rsa_padding_mode:oaep | base64)
echo "$encrypted_message_base64"
}
decrypt_message() {
local encrypted_message_base64=$1
# Decode the Base64 encrypted message and decrypt it directly
local decrypted_message=$(echo "$encrypted_message_base64" | base64 --decode | openssl pkeyutl -decrypt -inkey /root/.ssh/id_rsa -pkeyopt rsa_padding_mode:oaep)
echo "$decrypted_message"
}
generate_sha256sum() {
local message=$1
# local hash_value=$(echo -n "$message" | openssl dgst -sha256)
local hash_value=$(echo -n "$message" | sha256sum | awk '{print $1}')
echo "$hash_value"
}
escape_string() {
local string=$1
local escaped_string=""
# local ord
local symbols='$#&|;()<>*!?[]\/\"\`'
for ((i=0; i<${#string}; i++)); do
character="${string:i:1}"
if [[ $symbols =~ "$character" ]]; then
# ord=$(printf '%d' "'$character")
# escaped_string+="\\$ord"
escaped_string+="\\$character"
else
escaped_string+="$character"
fi
done
echo "$escaped_string"
}
extract_from_json() {
local path=$1
local json=$2
echo $json | /usr/bin/jq -r ".$path"
}
get_credentials() {
local username="$1"
local password="$2"
local credentials_json
if [ -z "$username" ]; then
read -rp "Username: " username
username=$(escape_string "$username")
fi
if [ -z "$password" ]; then
read -rs -p "Password: " password
password=$(escape_string "$password")
fi
credentials_json="{\"username\":\"$username\",\"password\":\"$password\"}"
echo "$credentials_json"
}
authenticate() {
local username="$1"
local password="$2"
if [ ! -f "/root/.ssh/id_rsa" ] || { [[ -n "$username" ]] && [[ -n "$password" ]]; }; then
if [ -n "$NON_ENCRYPTED_CREDENTIALS_SHA256SUM" ]; then
local non_encrypted_informed_credentials_json
local non_encrypted_informed_credentials_json_sha256sum
if [[ -n "$username" && -n "$password" ]]; then
non_encrypted_informed_credentials_json=$(get_credentials "$username" "$password")
else
non_encrypted_informed_credentials_json=$(get_credentials)
fi
non_encrypted_informed_credentials_json_sha256sum=$(generate_sha256sum "$non_encrypted_informed_credentials_json")
if [ "$non_encrypted_informed_credentials_json_sha256sum" == "$NON_ENCRYPTED_CREDENTIALS_SHA256SUM" ]; then
echo $non_encrypted_informed_credentials_json
else
>&2 echo "Error: Authentication failed. Invalid username or password."
return 1
fi
else
>&2 echo "Error: Authentication failed. No stored credentials hash found."
return 1
fi
else
if [ -n "$ENCRYPTED_CREDENTIALS" ]; then
local decrypted_stored_credentials_json
decrypted_stored_credentials_json=$(decrypt_message "$ENCRYPTED_CREDENTIALS")
echo $decrypted_stored_credentials_json
else
>&2 echo "Error: Authentication failed. No stored encrypted credentials found."
return 1
fi
fi
}
log_all () {
tail -n 0 -f \
~/shared/logs/tmux/fun-frontend.log \
~/shared/logs/tmux/filebrowser.log \
~/shared/logs/tmux/fun-client.log \
~/shared/logs/tmux/hb-gateway.log \
~/shared/logs/fun-client/info.log \
~/shared/logs/fun-client/warning.log \
~/shared/logs/fun-client/error.log \
~/shared/logs/fun-client/critical.log \
~/shared/logs/hb-gateway/* \
~/shared/logs/hb-client/*
}
log_front_all () {
tail -n 0 -f \
~/shared/logs/tmux/fun-frontend.log \
~/shared/logs/tmux/filebrowser.log \
~/shared/logs/tmux/fun-client.log \
~/shared/logs/tmux/hb-gateway.log
}
log_back_all () {
tail -n 0 -f \
~/shared/logs/fun-client/info.log \
~/shared/logs/fun-client/warning.log \
~/shared/logs/fun-client/error.log \
~/shared/logs/fun-client/critical.log \
~/shared/logs/hb-gateway/* \
~/shared/logs/hb-client/*
}
log_filebrowser () {
tail -n 0 -f ~/shared/logs/tmux/filebrowser.log
}
log_front_filebrowser () {
tail -n 0 -f ~/shared/logs/tmux/filebrowser.log
}
log_back_filebrowser () {
tail -n 0 -f /dev/null
}
log_hb_gateway () {
tail -n 0 -f \
~/shared/logs/tmux/hb-gateway.log \
~/shared/logs/hb-gateway/*
}
log_front_hb_gateway () {
tail -n 0 -f ~/shared/logs/tmux/hb-gateway.log
}
log_back_hb_gateway () {
tail -n 0 -f ~/shared/logs/hb-gateway/*
}
log_hb_client () {
tail -n 0 -f ~/shared/logs/hb-client/*
}
log_front_hb_client () {
tail -n 0 -f /dev/null
}
log_back_hb_client () {
tail -n 0 -f ~/shared/logs/hb-client/*
}
log_fun_frontend () {
tail -n 0 -f ~/shared/logs/tmux/fun-frontend.log
}
log_front_fun_frontend () {
tail -n 0 -f ~/shared/logs/tmux/fun-frontend.log
}
log_back_fun_frontend () {
tail -n 0 -f /dev/null
}
log_fun_client () {
tail -n 0 -f \
~/shared/logs/tmux/fun-client.log \
~/shared/logs/fun-client/info.log \
~/shared/logs/fun-client/warning.log \
~/shared/logs/fun-client/error.log \
~/shared/logs/fun-client/critical.log
}
log_front_fun_client () {
tail -n 0 -f ~/shared/logs/tmux/fun-client.log
}
log_back_fun_client () {
tail -n 0 -f \
~/shared/logs/fun-client/info.log \
~/shared/logs/fun-client/warning.log \
~/shared/logs/fun-client/error.log \
~/shared/logs/fun-client/critical.log
}
quick_deploy_fun_hb_client () {
set -ex
local branch="$1"
cd /root/funttastic/client || { echo "Failed to open the repository folder..."; return 1; }
unlink /root/funttastic/client/resources
git reset
git stash
if [ -n "$branch" ]; then
current_branch_name=$(git rev-parse --abbrev-ref HEAD)
if [ ! "$branch" == "$current_branch_name" ]; then
git switch "$current_branch_name"
fi
fi
git fetch --all
git pull
rm -rf /root/funttastic/client/resources
ln -s /root/shared/funttastic/client/resources /root/funttastic/client/resources
git stash apply
cd ~ || return
set +ex
}