forked from XK4MiLX/zelnode
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathflux_common.sh
executable file
·3180 lines (3070 loc) · 123 KB
/
flux_common.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
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
#disable bash history
set +o history
#trap EXIT call and unset vars and enable history if history if off
trap toolbox_close EXIT
function toolbox_close(){
unset ROOT_BRANCH
unset BRANCH_ALREADY_REFERENCE
if [[ $(set -o | grep history) == *"off"* ]]; then
set -o history
fi
}
trap ctrl_c INT
# exit on ctl_c and call toolbox close from EXIT trap
function ctrl_c() {
exit
}
# Collection of common vars and functions used throughout multitoolbox.
#color codes
RED='\033[1;31m'
YELLOW='\033[1;33m'
BLUE="\\033[38;5;27m"
SEA="\\033[38;5;49m"
GREEN='\033[1;32m'
CYAN='\033[1;36m'
NC='\033[0m'
#emoji codes
CHECK_MARK="${GREEN}\xE2\x9C\x94${NC}"
X_MARK="${RED}\xE2\x9C\x96${NC}"
PIN="${RED}\xF0\x9F\x93\x8C${NC}"
CLOCK="${GREEN}\xE2\x8C\x9B${NC}"
ARROW="${SEA}\xE2\x96\xB6${NC}"
BOOK="${RED}\xF0\x9F\x93\x8B${NC}"
HOT="${ORANGE}\xF0\x9F\x94\xA5${NC}"
WORNING="${RED}\xF0\x9F\x9A\xA8${NC}"
RIGHT_ANGLE="${GREEN}\xE2\x88\x9F${NC}"
#bootstrap variable
server_offline="0"
failed_counter="0"
#Explorers
network_url_1="explorer.zelcash.online"
network_url_2="explorer.runonflux.io"
network_url_3="blockbook.zel.network"
#Wallet variable
COIN_NAME='flux'
CONFIG_DIR='.flux'
CONFIG_FILE='flux.conf'
#FluxOS variable
FLUX_DIR='zelflux'
#Ports
RPCPORT=16124
PORT=16125
#dialog color
export NEWT_COLORS='
title=black,
'
if [[ -z $FLUXOS_VERSION ]]; then
FLUXOS_PATH="/home/$USER/zelflux"
FLUX_WATCHDOG_PATH="/home/$USER/watchdog"
FLUX_DAEMON_PATH="/home/$USER/.flux"
FLUX_BENCH_PATH="/home/$USER/.fluxbenchmark"
DATA_PATH="/home/$USER"
MONGODB_DATA_PATH="/var/lib/mongodb"
MONGODB_LOG_PATH="/var/log/mongodb"
FLUX_DAEMON_SERVICE="zelflux"
FLUX_APPS_FOLDER="$FLUXOS_PATH/ZelApps"
else
FLUXOS_PATH="/dat/usr/lib/fluxos"
FLUX_WATCHDOG_PATH="/dat/usr/lib/fluxwatchdog"
FLUX_DAEMON_PATH="/dat/var/lib/fluxd"
FLUX_BENCH_PATH="/dat/usr/lib/fluxbenchd"
DATA_PATH="/dat"
MONGODB_DATA_PATH="/dat/var/lib/mongodb"
MONGODB_LOG_PATH="/dat/var/log/mongodb"
FLUX_DAEMON_SERVICE="fluxd"
FLUX_APPS_FOLDER="/dat/var/lib/fluxos/flux-apps"
fi
##### CONFIGS SECTION ######################################
function watchdog_conf_create(){
sudo touch $FLUX_WATCHDOG_PATH/config.js
sudo chown $USER:$USER $FLUX_WATCHDOG_PATH/config.js
cat <<- EOF >| $FLUX_WATCHDOG_PATH/config.js
module.exports = {
label: '${node_label}',
tier_eps_min: '${eps_limit}',
zelflux_update: '${flux_update}',
zelcash_update: '${daemon_update}',
zelbench_update: '${bench_update}',
action: '${fix_action}',
ping: '${ping}',
web_hook_url: '${discord}',
telegram_alert: '${telegram_alert}',
telegram_bot_token: '${telegram_bot_token}',
telegram_chat_id: '${telegram_chat_id}'
}
EOF
}
function fluxos_conf_create(){
if [[ "$1" == "true" ]]; then
testnet=true
else
testnet=false
fi
if [[ -n $FLUXOS_VERSION ]]; then
FLUXOS_CONFIG="/tmp"
else
FLUXOS_CONFIG="$FLUXOS_PATH/config"
fi
touch $FLUXOS_CONFIG/userconfig.js
cat <<- EOF >| $FLUXOS_CONFIG/userconfig.js
module.exports = {
initial: {
ipaddress: '${WANIP}',
zelid: '${ZELID}',
kadena: '${KDA_A}',
development: false,
blockedPorts: [],
testnet: $testnet,
}
}
EOF
if [[ -n $FLUXOS_VERSION ]]; then
sudo mv $FLUXOS_CONFIG/userconfig.js $FLUXOS_PATH/config/userconfig.js
fi
}
function flux_daemon_conf_create() {
explorers=(
"explorer.runonflux.io"
"explorer.zelcash.online"
"blockbook.runonflux.io"
"explorer.flux.zelcore.io"
)
selected_ips=($(curl -s -m 20 https://api.runonflux.io/apps/enterprisenodes | jq -r '.data[] | select(.score >= 2200 and .score <= 3000) | .ip' 2>/dev/null | shuf -n 25))
nodes=("${selected_ips[@]}" "${explorers[@]}")
RPCUSER=$(pwgen -1 8 -n)
PASSWORD=$(pwgen -1 20 -n)
touch $FLUX_DAEMON_PATH/$CONFIG_FILE
{
cat <<- EOF
rpcuser=$RPCUSER
rpcpassword=$PASSWORD
rpcallowip=127.0.0.1
rpcallowip=172.18.0.1
rpcport=$RPCPORT
port=$PORT
zelnode=1
zelnodeprivkey=$zelnodeprivkey
zelnodeoutpoint=$zelnodeoutpoint
zelnodeindex=$zelnodeindex
server=1
daemon=1
txindex=1
addressindex=1
timestampindex=1
spentindex=1
insightexplorer=1
experimentalfeatures=1
listen=1
externalip=$WANIP
bind=0.0.0.0
maxconnections=256
zmqpubhashtx=tcp://127.0.0.1:16123
zmqpubhashblock=tcp://127.0.0.1:16123
zmqpubrawblock=tcp://127.0.0.1:16123
zmqpubrawtx=tcp://127.0.0.1:16123
zmqpubsequence=tcp://127.0.0.1:16123
# Addnode list
EOF
IFS=$'\n'
for node in "${nodes[@]}"; do
echo "addnode=$node"
done
} | sed 's/^[[:space:]]*//' >| $FLUX_DAEMON_PATH/$CONFIG_FILE
}
function install_conf_create(){
sudo touch $DATA_PATH/install_conf.json
sudo chown $USER:$USER $DATA_PATH/install_conf.json
cat <<- EOF >| $DATA_PATH/install_conf.json
{
"import_settings": "${import_settings}",
"prvkey": "${prvkey}",
"outpoint": "${outpoint}",
"index": "${index}",
"zelid": "${zel_id}",
"kda_address": "${kda_address}",
"firewall_disable": "${firewall_disable}",
"bootstrap_url": "${bootstrap_url}",
"bootstrap_zip_del": "${bootstrap_zip_del}",
"swapon": "${swapon}",
"use_old_chain": "${use_old_chain}",
"node_label": "${node_label}",
"zelflux_update": "${zelflux_update}",
"zelcash_update": "${zelcash_update}",
"zelbench_update": "${zelbench_update}",
"discord": "${discord}",
"ping": "${ping}",
"telegram_alert": "${telegram_alert}",
"telegram_bot_token": "${telegram_bot_token}",
"telegram_chat_id": "${telegram_chat_id}",
"eps_limit": "${eps_limit}",
"upnp_port": "${upnp_port}",
"gateway_ip": "${gateway_ip}",
"upnp_enabled": "${upnp_enabled}",
"thunder": "${thunder:-0}"
}
EOF
}
###### SMART CONFIG
function padding() {
msg="$1"
padding=".................................................................................................................."
echo -e "$(printf "%s%s %s\n" "$msg" "${CYAN}${padding:${#msg}}" "${CYAN}[$2${CYAN}]${NC}")"
}
function insert() {
local file="$1" line="$2" newText="$3"
sudo sed -i -e "/$line/i"$'\\\n'"$newText"$'\n' "$file"
}
function RemoveLine(){
if [[ -n $FLUXOS_VERSION ]]; then
SUDO_CMD="sudo"
fi
$SUDO_CMD sed -i "/$1/d" $FLUXOS_PATH/config/userconfig.js
}
function ClearList() {
string="\[\]"
display=""
}
function buildBlockedPortsList() {
if [[ ! -f $FLUXOS_PATH/config/userconfig.js ]]; then
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}Config file does not exist...${NC}" "${X_MARK}"
exit
fi
if [[ "$1" == "" || "$2" == "" ]]; then
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}Empty key/value skipped${NC}" "${X_MARK}"
exit
fi
key="$1"
value="$2"
if [[ $(cat "$FLUXOS_PATH/config/userconfig.js" | grep "$key") == "" ]]; then
insert "$FLUXOS_PATH/config/userconfig.js" "testnet" " $key: $value,"
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}$3${NC}" "${CHECK_MARK}"
return
fi
}
function CreateBlockedPortsList() {
ADD=$(whiptail --inputbox "Enter the ports to the blocked list, separated by commas" 8 85 3>&1 1>&2 2>&3)
if [[ $? == 1 ]]; then
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}The operation was canceled${NC}" "${X_MARK}"
echo -e ""
exit
fi
NumberCheck=$(sed 's/,/1/g' <<< $ADD)
ADD=$(sed 's/,/ /g' <<< $ADD)
if ! [[ "$NumberCheck" =~ ^[0-9]+$ ]]; then
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}Input contains non numerical value${NC}" "${X_MARK}"
exit
fi
array=($ADD)
sorted_unique_ids=($(echo "${array[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
printf -v joined '%s,' "${sorted_unique_ids[@]}"
if [[ "${joined%,}" != "" ]]; then
string="\[${joined%,}\]"
display="${joined%,}"
fi
}
function AddBlockedPorts() {
string=$(grep "blockedPorts" $FLUXOS_PATH/config/userconfig.js | awk -F'[][]' '{print $2}' )
delimiter=","
declare -a array=($(echo $string | tr "$delimiter" " "))
ADD=$(whiptail --inputbox "Enter the ports to the blocked list, separated by commas" 8 85 3>&1 1>&2 2>&3)
if [[ $? == 1 ]]; then
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}The operation was canceled${NC}" "${X_MARK}"
echo -e ""
exit
fi
NumberCheck=$(sed 's/,/1/g' <<< $ADD)
ADD=$(sed 's/,/ /g' <<< $ADD)
if ! [[ "$NumberCheck" =~ ^[0-9]+$ ]]; then
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}Input contains non numerical value${NC}" "${X_MARK}"
exit
fi
array+=($ADD)
sorted_unique_ids=($(echo "${array[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
printf -v joined '%s,' "${sorted_unique_ids[@]}"
string="\[${joined%,}\]"
display="${joined%,}"
}
function ImportBlockedPorts(){
array=($(grep -w blockedPorts $FLUXOS_PATH/config/userconfig.js | grep -o '[[:digit:]]*'))
sorted_unique_ids=($(echo "${array[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
printf -v joined '%s,' "${sorted_unique_ids[@]}"
if [[ "${joined%,}" != "" ]]; then
blockedPortsList="\[${joined%,}\]"
display="${joined%,}"
fi
}
function blocked_ports(){
CHOICE=$(
whiptail --title "FluxOS Blocked Ports Management" --menu "Make your choice" 15 40 6 \
"1)" "Create new list" \
"2)" "Add ports" \
"3)" "Clear list" 3>&2 2>&1 1>&3 )
case $CHOICE in
"1)")
CreateBlockedPortsList
echo -e "${ARROW}${GREEN} BlockedPorts: [$display]${NC}"
RemoveLine "blockedPorts"
buildBlockedPortsList " blockedPorts" "$string" "Blocked ports list crated successful!" "fluxos"
;;
"2)")
AddBlockedPorts
echo -e "${ARROW}${GREEN} BlockedPorts: [$display]${NC}"
RemoveLine "blockedPorts"
buildBlockedPortsList " blockedPorts" "$string" "Blocked ports list updated successful!" "fluxos"
;;
"3)")
ClearList
RemoveLine "blockedPorts"
buildBlockedPortsList " blockedPorts" "$string" "Blocked ports list cleared successful!" "fluxos"
;;
esac
}
function CreateBlockedRepositoryList() {
ADD=$(whiptail --inputbox "Enter the repositories to the blocked list, separated by commas" 8 85 3>&1 1>&2 2>&3)
if [[ $? == 1 ]]; then
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}The operation was canceled${NC}" "${X_MARK}"
echo -e ""
exit
fi
ADD=$(sed 's/,/ /g' <<< $ADD)
temp_array=($ADD)
for i in ${temp_array[@]}
do
array+=("'$i'")
done
sorted_unique_ids=($(echo "${array[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
printf -v joined '%s,' "${sorted_unique_ids[@]}"
if [[ "${joined%,}" != "" ]]; then
string="\[${joined%,}\]"
display="${joined%,}"
fi
}
function AddBlockedRepository() {
string=$(grep "blockedRepositories" $FLUXOS_PATH/config/userconfig.js | awk -F'[][]' '{print $2}' )
delimiter=","
declare -a array=($(echo $string | tr "$delimiter" " "))
ADD=$(whiptail --inputbox "Enter the repositories to the blocked list, separated by commas" 8 85 3>&1 1>&2 2>&3)
if [[ $? == 1 ]]; then
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}The operation was canceled${NC}" "${X_MARK}"
echo -e ""
exit
fi
ADD=$(sed 's/,/ /g' <<< $ADD)
temp_array=($ADD)
for i in ${temp_array[@]}
do
array+=("'$i'")
done
sorted_unique_ids=($(echo "${array[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
printf -v joined '%s,' "${sorted_unique_ids[@]}"
string="\[${joined%,}\]"
display="${joined%,}"
}
function buildBlockedRepositoryList() {
if [[ ! -f "$FLUXOS_PATH/config/userconfig.js" ]]; then
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}Config file does not exist...${NC}" "${X_MARK}"
exit
fi
if [[ "$1" == "" || "$2" == "" ]]; then
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}Empty key/value skipped${NC}" "${X_MARK}"
exit
fi
key="$1"
value="$2"
if [[ $(cat $FLUXOS_PATH/config/userconfig.js | grep "$key") == "" ]]; then
insert "$FLUXOS_PATH/config/userconfig.js" "testnet" " $key: $value,"
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}$3${NC}" "${CHECK_MARK}"
return
fi
}
function ImportBlockedRepository() {
string=$(grep "blockedRepositories" $FLUXOS_PATH/config/userconfig.js | awk -F'[][]' '{print $2}' )
delimiter=","
declare -a array=($(echo $string | tr "$delimiter" " "))
sorted_unique_ids=($(echo "${array[@]}" | tr ' ' '\n' | sort -u | tr '\n' ' '))
printf -v joined '%s,' "${sorted_unique_ids[@]}"
if [[ "${joined%,}" != "" ]]; then
blockedRepositoryList="\[${joined%,}\]"
display="${joined%,}"
fi
}
function blocked_repositories(){
CHOICE=$(
whiptail --title "FluxOS Blocked Repositories Management" --menu "Make your choice" 15 40 6 \
"1)" "Create new list" \
"2)" "Add Repositories" \
"3)" "Clear list" 3>&2 2>&1 1>&3 )
case $CHOICE in
"1)")
CreateBlockedRepositoryList
echo -e "${ARROW}${GREEN} BlockedRepositories: [$display]${NC}"
RemoveLine "blockedRepositories"
buildBlockedRepositoryList " blockedRepositories" "$string" "Blocked repositories list crated successful!" "fluxos"
;;
"2)")
AddBlockedRepository
echo -e "${ARROW}${GREEN} BlockedRepositories: [$display]${NC}"
RemoveLine "blockedRepositories"
buildBlockedRepositoryList " blockedRepositories" "$string" "Blocked repositories list updated successful!" "fluxos"
;;
"3)")
ClearList
RemoveLine "blockedRepositories"
buildBlockedRepositoryList " blockedRepositories" "$string" "Blocked repositories list cleared successful!" "fluxos"
;;
esac
echo -e ""
}
function fluxosConfigBackup(){
ConfigFile="$FLUXOS_PATH/config/userconfig.js"
if [[ -f $ConfigFile ]]; then
if [[ -n $FLUXOS_VERSION ]]; then
SUDO_CMD="sudo"
fi
$SUDO_CMD cp -nf $ConfigFile $DATA_PATH/userconfig.js.backup > /dev/null 2>&1
if [[ -f $DATA_PATH/userconfig.js.backup ]]; then
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}FluxOs userconfig.js backup successfully${NC}" "${CHECK_MARK}"
else
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}FluxOs userconfig.js backup failed${NC}" "${X_MARK}"
fi
else
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}FluxOs userconfig.js file not exists${NC}" "${X_MARK}"
fi
echo -e ""
}
function fluxosConfigRestore(){
ConfigFile="$FLUXOS_PATH/config/userconfig.js"
if [[ -d $FLUXOS_PATH ]]; then
if [[ -f $DATA_PATH/userconfig.js.backup ]]; then
if [[ -n $FLUXOS_VERSION ]]; then
SUDO_CMD="sudo"
fi
$SUDO_CMD cp -nf $DATA_PATH/userconfig.js.backup $ConfigFile > /dev/null 2>&1
if [[ -f $ConfigFile ]]; then
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}FluxOs userconfig.js restored successfully${NC}" "${CHECK_MARK}"
else
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}FluxOs userconfig.js restored failed${NC}" "${X_MARK}"
fi
else
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}FluxOs userconfig.js backup not exists${NC}" "${X_MARK}"
fi
else
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}FluxOs not installed${NC}" "${X_MARK}"
fi
echo -e ""
}
function config_builder() {
########################################################
if [[ "$4" == "fluxos" ]]; then
key="$1"
value_check=$2
if [[ "$2" == "false" || "$2" == "true" || "$2" =~ ^[0-9]+$ ]]; then
value=$2
else
value="\'$2\'"
fi
if [[ "$1" == "kadena" ]]; then
if [[ $( grep "chainid" <<< "$2") == "" ]]; then
value="\'kadena:$2?chainid=0\'"
fi
fi
if [[ ! -f $FLUXOS_PATH/config/userconfig.js ]]; then
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}Config file does not exist...${NC}" "${X_MARK}"
return
fi
if [[ "$1" == "" || "$2" == "" ]]; then
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}Empty key/value skipped${NC}" "${X_MARK}"
return
fi
if [[ $(cat $FLUXOS_PATH/config/userconfig.js | grep "$key") == "" ]]; then
insert "$FLUXOS_PATH/config/userconfig.js" "testnet" " $key: $value,"
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}$3 added successfully${NC}" "${CHECK_MARK}"
return
fi
if [[ $(cat $FLUXOS_PATH/config/userconfig.js | grep "$key" | grep "$value_check") != "" ]]; then
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}$3 skipped${NC}" "${X_MARK}"
return
fi
if [[ $(cat $FLUXOS_PATH/config/userconfig.js | grep "$key") != "" ]]; then
RemoveLine "$key"
insert "$FLUXOS_PATH/config/userconfig.js" "testnet" " $key: $value,"
padding "${ARROW}${GREEN} [FluxOS] ${CYAN}$3 changed successfully${NC}" "${CHECK_MARK}"
fi
fi
#####################################################
if [[ "$4" == "daemon" ]]; then
if [[ ! -f $FLUX_DAEMON_PATH/$CONFIG_FILE ]]; then
padding "${ARROW}${GREEN} [Daemon] ${CYAN}Config file does not exist...${NC}" "${X_MARK}"
return
fi
if [[ "$1" == "" || "$2" == "" ]]; then
padding "${ARROW}${GREEN} [Daemon] ${CYAN}Empty key/value skipped${NC}" "${X_MARK}"
return
fi
if [[ ! $(grep -w $1 $FLUX_DAEMON_PATH/$CONFIG_FILE) && -f $FLUX_DAEMON_PATH/$CONFIG_FILE ]]; then
echo "$1=$2" >> $FLUX_DAEMON_PATH/$CONFIG_FILE
if [[ "$1=$2" == $(grep -w $1 $FLUX_DAEMON_PATH/$CONFIG_FILE) ]]; then
padding "${ARROW}${GREEN} [Daemon] ${CYAN}$3 added successfully${NC}" "${CHECK_MARK}"
return
fi
fi
if [[ "$1=$2" == $(grep -w $1 $FLUX_DAEMON_PATH/$CONFIG_FILE) ]]; then
padding "${ARROW}${GREEN} [Daemon] ${CYAN}$3 skipped${NC}" "${X_MARK}"
return
else
sed -i "s/$(grep -e $1 $FLUX_DAEMON_PATH/$CONFIG_FILE)/$1=$2/" $FLUX_DAEMON_PATH/$CONFIG_FILE
if [[ "$1=$2" == $(grep -w $1 $FLUX_DAEMON_PATH/$CONFIG_FILE) ]]; then
padding "${ARROW}${GREEN} [Daemon] ${CYAN}$3 replaced successfully${NC}" "${CHECK_MARK}"
fi
fi
fi
###################################################
if [[ "$4" == "benchmark" ]]; then
if [[ "$1" == "" || "$2" == "" ]]; then
padding "${ARROW}${GREEN} [BenchD] ${CYAN}Empty key/value skipped${NC}" "${X_MARK}"
return
fi
if [[ ! -f "$FLUX_BENCH_PATH/fluxbench.conf" ]]; then
mkdir -p $FLUX_BENCH_PATH > /dev/null 2>&1
echo "$1=$2" >> $FLUX_BENCH_PATH/fluxbench.conf
if [[ "$1=$2" == $(grep -w $1 $FLUX_BENCH_PATH/fluxbench.conf) ]]; then
padding "${ARROW}${GREEN} [BenchD] ${CYAN}$3 added successfully${NC}" "${CHECK_MARK}"
return
fi
fi
if [[ ! $(grep -w $1 $FLUX_BENCH_PATH/fluxbench.conf) ]]; then
echo "$1=$2" >> $FLUX_BENCH_PATH/fluxbench.conf
if [[ "$1=$2" == $(grep -w $1 $FLUX_BENCH_PATH/fluxbench.conf) ]]; then
padding "${ARROW}${GREEN} [BenchD] ${CYAN}$3 added successfully${NC}" "${CHECK_MARK}"
return
fi
fi
if [[ "$1=$2" == $(grep -w $1 $FLUX_BENCH_PATH/fluxbench.conf) ]]; then
padding "${ARROW}${GREEN} [BenchD] ${CYAN}$3 skipped${NC}" "${X_MARK}"
else
sed -i "s/$(grep -e $1 $FLUX_BENCH_PATH/fluxbench.conf)/$1=$2/" $FLUX_BENCH_PATH/fluxbench.conf
if [[ "$1=$2" == $(grep -w $1 $FLUX_BENCH_PATH/fluxbench.conf) ]]; then
padding "${ARROW}${GREEN} [BenchD] ${CYAN}$3 replaced successfully${NC}" "${CHECK_MARK}"
fi
fi
fi
###################################################
if [[ "$4" == "watchdog" ]]; then
if [[ ! -f "$FLUX_WATCHDOG_PATH/config.js" ]]; then
padding "${ARROW}${GREEN} [WatchD] ${CYAN}Config file does not exist...${NC}" "${X_MARK}"
return
fi
if [[ "$1" == "" || "$2" == "" ]]; then
padding "${ARROW}${GREEN} [WatchD] ${CYAN}Empty key/value skipped${NC}" "${X_MARK}"
return
fi
if [[ $(cat $FLUX_WATCHDOG_PATH/config.js | grep "$1: '$2'") != "" ]]; then
padding "${ARROW}${GREEN} [WatchD] ${CYAN}$3 skipped${NC}" "${X_MARK}"
return
fi
if [[ $(cat $FLUX_WATCHDOG_PATH/config.js | grep "$1") != "" ]]; then
sed -i "s/$(grep -e $1 $FLUX_WATCHDOG_PATH/config.js)/ $1: '$2',/" $FLUX_WATCHDOG_PATH/config.js
if [[ $(grep -w $2 $FLUX_WATCHDOG_PATH/config.js) != "" ]]; then
padding "${ARROW}${GREEN} [WatchD] ${CYAN}$3 replaced successfully${NC}" "${CHECK_MARK}"
fi
fi
fi
}
function smart_reconfiguration(){
watchdog_settings_list=("label", "tier_eps_min", "zelflux_update", "zelcash_update", "zelbench_update", "action", "ping", "web_hook_url", "telegram_alert", "telegram_bot_token", "telegram_chat_id")
fluxos_settings_list=("kadena", "zelid", "apiport", "ipaddress", "development")
daemon_settings_list=("zelnodeprivkey", "zelnodeoutpoint", "zelnodeindex")
benchmark_settings_list=("fluxport", "thunder", "speedtestserverid")
config_list=$(cat <<-END
{
"prvkey": [{"key": "zelnodeprivkey", "label": "Identity Key"}],
"outpoint": [{"key": "zelnodeoutpoint", "label": "Collateral TX ID"}],
"index": [{"key": "zelnodeindex", "label": "Output Index"}],
"node_label": [{"key": "label", "label": "Node Label"}],
"kda_address": [{"key": "kadena", "label": "Kadena Address"}],
"ping": [{"key": "ping", "label": "Discord Nick Ping"}],
"zelflux_update": [{"key": "zelflux_update", "label": "FluxOS Auto Update"}],
"zelcash_update": [{"key": "zelcash_update", "label": "Daemon Auto Update"}],
"zelbench_update": [{"key": "zelbench_update", "label": "Benchmark Auto Update"}],
"fluxport": [{"key": "fluxport", "label": "Multi Node Port"}],
"thunder": [{"key": "thunder", "label": "Thunder Mode"}],
"speedtestserverid": [{"key": "speedtestserverid", "label": "Speed Test Server ID"}],
"upnp_port": [{"key": "apiport", "label": "UPnP Port"}],
"development": [{"key": "development", "label": "Development Mode"}]
}
END
)
install_settings=($(jq -r 'keys | @sh' $DATA_PATH/install_conf.json))
for i in "${install_settings[@]}"
do
install_key=$(echo $i | tr -d "'")
key=$(jq -r .$install_key[].key 2> /dev/null <<< "$config_list")
if [[ "$key" == "" ]]; then
key=$install_key
fi
label=$(jq -r .$install_key[].label 2> /dev/null <<< "$config_list")
if [[ "$label" == "" ]]; then
label=${install_key^}
fi
if [[ $(echo ${daemon_settings_list[@]} | grep -ow "$key" | wc -l) == "1" ]]; then
config="daemon"
value=$(jq -r .$install_key $DATA_PATH/install_conf.json)
config_builder "$key" "$value" "$label" "$config"
fi
if [[ $(echo ${benchmark_settings_list[@]} | grep -ow "$key" | wc -l) == "1" ]]; then
config="benchmark"
value=$(jq -r .$install_key $DATA_PATH/install_conf.json)
config_builder "$key" "$value" "$label" "$config"
fi
if [[ $(echo ${fluxos_settings_list[@]} | grep -ow "$key" | wc -l) == "1" ]]; then
config="fluxos"
value=$(jq -r .$install_key $DATA_PATH/install_conf.json)
config_builder "$key" "$value" "$label" "$config"
fi
if [[ $(echo ${watchdog_settings_list[@]} | grep -ow "$key" | wc -l) == "1" ]]; then
config="watchdog"
value=$(jq -r .$install_key $DATA_PATH/install_conf.json)
config_builder "$key" "$value" "$label" "$config"
fi
done
}
function smart_install_conf(){
if [[ "$3" == "import" ]]; then
return
fi
if [[ ! -f $DATA_PATH/install_conf.json ]]; then
echo "{}" >| $DATA_PATH/install_conf.json
fi
echo "$(jq -r --arg key "$1" --arg value "$2" '.[$key]=$value' install_conf.json)" >| $DATA_PATH/install_conf.json
}
function config_smart_create() {
if [[ "$1" != "import" ]]; then
rm -rf $DATA_PATH/install_conf.json
fi
#daemon
if [[ -f $FLUX_DAEMON_PATH/$CONFIG_FILE ]]; then
echo -e ""
echo -e "${ARROW} ${YELLOW}Imported daemon settings:${NC}"
zelnodeprivkey=$(grep -w zelnodeprivkey $FLUX_DAEMON_PATH/$CONFIG_FILE | sed -e 's/zelnodeprivkey=//' | sed 's/ //g')
echo -e "${PIN}${CYAN} Identity Key = ${GREEN}$zelnodeprivkey${NC}"
smart_install_conf "prvkey" "$zelnodeprivkey" "$1"
zelnodeoutpoint=$(grep -w zelnodeoutpoint $FLUX_DAEMON_PATH/$CONFIG_FILE | sed -e 's/zelnodeoutpoint=//' | sed 's/ //g')
echo -e "${PIN}${CYAN} Collateral TX ID = ${GREEN}$zelnodeoutpoint${NC}"
smart_install_conf "outpoint" "$zelnodeoutpoint" "$1"
zelnodeindex=$(grep -w zelnodeindex $FLUX_DAEMON_PATH/$CONFIG_FILE | sed -e 's/zelnodeindex=//' | sed 's/ //g')
echo -e "${PIN}${CYAN} Output Index = ${GREEN}$zelnodeindex${NC}"
smart_install_conf "index" "$zelnodeindex" "$1"
fi
#Benchmark
if [[ -f $FLUX_BENCH_PATH/fluxbench.conf ]]; then
echo -e ""
echo -e "${ARROW} ${YELLOW}Imported Benchmark settings:${NC}"
thunder=$(grep -Po "(?<=thunder=)\d+" $FLUX_BENCH_PATH/fluxbench.conf)
if [[ "$thunder" == "1" ]]; then
echo -e "${PIN}${CYAN} Thunder Mode = ${GREEN}ENABLED${NC}"
smart_install_conf "thunder" "$thunder" "$1"
fi
speedtestserverid=$(grep -Po "(?<=speedtestserverid=)\d+" $FLUX_BENCH_PATH/fluxbench.conf)
if [[ "$speedtestserverid" != "" ]]; then
echo -e "${PIN}${CYAN} SpeedTest Server ID = ${GREEN}$speedtestserverid${NC}"
smart_install_conf "speedtestserverid" "$speedtestserverid" "$1"
fi
fluxport=$(grep -Po "(?<=fluxport=)\d+" $FLUX_BENCH_PATH/fluxbench.conf)
if [[ "$fluxport" != "" ]]; then
upnp_enabled=true
echo -e "${PIN}${CYAN} Flux Port = ${GREEN}$fluxport${NC}"
smart_install_conf "fluxport" "$fluxport" "$1"
smart_install_conf "upnp_enabled" "$upnp_enabled" "$1"
fi
fi
#fluxOS
if [[ -f $FLUXOS_PATH/config/userconfig.js ]]; then
echo -e ""
echo -e "${ARROW} ${YELLOW}Imported fluxOS settings:${NC}"
ZELID=$(grep -w zelid $FLUXOS_PATH/config/userconfig.js | sed -e 's/.*zelid: .//' | sed -e 's/.\{2\}$//')
if [[ "$ZELID" != "" ]]; then
echo -e "${PIN}${CYAN} Flux/SSP ID = ${GREEN}$ZELID${NC}"
smart_install_conf "zelid" "$ZELID" "$1"
fi
KDA_A=$(grep -w kadena $FLUXOS_PATH/config/userconfig.js | sed -e 's/.*kadena: .//' | sed -e 's/.\{2\}$//')
if [[ "$KDA_A" != "" ]]; then
echo -e "${PIN}${CYAN} KDA address = ${GREEN}$KDA_A${NC}"
smart_install_conf "kda_address" "$KDA_A" "$1"
fi
upnp_port=$(grep -w apiport $FLUXOS_PATH/config/userconfig.js | grep -o '[[:digit:]]*')
if [[ "$upnp_port" != "" ]]; then
gateway_ip=$(ip rout | head -n1 | awk '{print $3}' 2>/dev/null)
echo -e "${PIN}${CYAN} API Port = ${GREEN}$upnp_port${NC}"
if [[ "$upnp_enabled" == "true" ]]; then
echo -e "${PIN}${CYAN} Router IP = ${GREEN}$gateway_ip${NC}"
fi
smart_install_conf "upnp_port" "$upnp_port" "$1"
smart_install_conf "gateway_ip" "$gateway_ip" "$1"
fi
fi
#watchdog
if [[ -f $FLUX_WATCHDOG_PATH/config.js ]]; then
echo -e ""
echo -e "${ARROW} ${YELLOW}Imported watchdog settings:${NC}"
node_label=$(grep -w label $FLUX_WATCHDOG_PATH/config.js | sed -e 's/.*label: .//' | sed -e 's/.\{2\}$//')
if [[ "$node_label" != "" && "$node_label" != "0" ]]; then
echo -e "${PIN}${CYAN} Label = ${GREEN}$node_label${NC}"
smart_install_conf "node_label" "$node_label" "$1"
else
echo -e "${PIN}${CYAN} Label = ${RED}Disabled${NC}"
fi
eps_limit=$(grep -w tier_eps_min $FLUX_WATCHDOG_PATH/config.js | sed -e 's/.*tier_eps_min: .//' | sed -e 's/.\{2\}$//')
if [[ "$eps_limit" != "" && "$eps_limit" != "0" ]]; then
echo -e "${PIN}${CYAN} Tier_eps_min = ${GREEN}$eps_limit${NC}"
smart_install_conf "eps_limit" "$eps_limit" "$1"
fi
discord=$(grep -w web_hook_url $FLUX_WATCHDOG_PATH/config.js | sed -e 's/.*web_hook_url: .//' | sed -e 's/.\{2\}$//')
if [[ "$discord" != "" && "$discord" != "0" ]]; then
echo -e "${PIN}${CYAN} Discord alert = ${GREEN}Enabled${NC}"
smart_install_conf "discord" "$discord" "$1"
else
echo -e "${PIN}${CYAN} Discord alert = ${RED}Disabled${NC}"
fi
ping=$(grep -w ping $FLUX_WATCHDOG_PATH/config.js | sed -e 's/.*ping: .//' | sed -e 's/.\{2\}$//')
if [[ "$ping" != "" && "$ping" != "0" ]]; then
if [[ "$discord" != "" && "$discord" != "0" ]]; then
echo -e "${PIN}${CYAN} Discord nick ping = ${GREEN}Enabled${NC}"
smart_install_conf "ping" "$ping" "$1"
else
echo -e "${PIN}${CYAN} Discord nick ping = ${RED}Disabled${NC}"
fi
fi
telegram_alert=$(grep -w telegram_alert $FLUX_WATCHDOG_PATH/config.js | sed -e 's/.*telegram_alert: .//' | sed -e 's/.\{2\}$//')
if [[ "$telegram_alert" != "" && "$telegram_alert" != "0" ]]; then
echo -e "${PIN}${CYAN} Telegram alert = ${GREEN}Enabled${NC}"
smart_install_conf "telegram_alert" "$telegram_alert" "$1"
else
echo -e "${PIN}${CYAN} Telegram alert = ${RED}Disabled${NC}"
smart_install_conf "telegram_alert" "0" "$1"
fi
telegram_bot_token=$(grep -w telegram_bot_token $FLUX_WATCHDOG_PATH/config.js | sed -e 's/.*telegram_bot_token: .//' | sed -e 's/.\{2\}$//')
if [[ "$telegram_alert" == "1" ]]; then
echo -e "${PIN}${CYAN} Telegram bot token = ${GREEN}$telegram_bot_token${NC}"
smart_install_conf "telegram_bot_token" "$telegram_bot_token" "$1"
fi
telegram_chat_id=$(grep -w telegram_chat_id $FLUX_WATCHDOG_PATH/config.js | sed -e 's/.*telegram_chat_id: .//' | sed -e 's/.\{1\}$//')
if [[ "$telegram_alert" == "1" ]]; then
echo -e "${PIN}${CYAN} Telegram chat id = ${GREEN}$telegram_chat_id${NC}"
smart_install_conf "telegram_chat_id" "$telegram_chat_id" "$1"
fi
zelflux_update=$(grep -w zelflux_update $FLUX_WATCHDOG_PATH/config.js | sed -e 's/.*zelflux_update: .//' | egrep -o '[0-9]')
if [[ "$zelflux_update" == "1" ]]; then
echo -e "${PIN}${CYAN} FluxOS auto update = ${GREEN}Enabled${NC}"
smart_install_conf "zelflux_update" "1" "$1"
else
echo -e "${PIN}${CYAN} FluxOS auto update = ${GREEN}Disabled${NC}"
smart_install_conf "zelflux_update" "0" "$1"
fi
zelcash_update=$(grep -w zelcash_update $FLUX_WATCHDOG_PATH/config.js | sed -e 's/.*zelcash_update: .//' | egrep -o '[0-9]')
if [[ "$zelcash_update" == "1" ]]; then
echo -e "${PIN}${CYAN} Daemon auto update = ${GREEN}Enabled${NC}"
smart_install_conf "zelcash_update" "1" "$1"
else
echo -e "${PIN}${CYAN} Daemon auto update = ${GREEN}Disabled${NC}"
smart_install_conf "zelcash_update" "0" "$1"
fi
zelbench_update=$(grep -w zelbench_update $FLUX_WATCHDOG_PATH/config.js | sed -e 's/.*zelbench_update: .//' | egrep -o '[0-9]')
if [[ "$zelbench_update" == "1" ]]; then
echo -e "${PIN}${CYAN} Benchmark auto update = ${GREEN}Enabled${NC}"
smart_install_conf "zelbench_update" "1" "$1"
else
echo -e "${PIN}${CYAN} Benchmark auto update = ${GREEN}Disabled${NC}"
smart_install_conf "zelbench_update" "0" "$1"
fi
action=$(grep -w action $FLUX_WATCHDOG_PATH/config.js | sed -e 's/.*action: .//' | egrep -o '[0-9]')
if [[ "$action" == "1" ]]; then
echo -e "${PIN}${CYAN} Fix action = ${GREEN}Enabled${NC}"
smart_install_conf "action" "1" "$1"
else
echo -e "${PIN}${CYAN} Fix action = ${GREEN}Disabled${NC}"
smart_install_conf "action" "0" "$1"
fi
fi
echo -e ""
if [[ "$1" != "import" ]]; then
echo -e "${HOT}${CYAN} Config file created, path: ${GREEN}$DATA_PATH/install_conf.json${NC}"
echo -e ""
fi
}
function manual_build(){
skip_zelcash_config='0'
skip_bootstrap='0'
if [[ -d $FLUX_DAEMON_PATH ]]; then
if whiptail --yesno "Would you like import old settings from daemon and Flux?" 8 65; then
import_settings='1'
skip_zelcash_config='1'
sleep 1
else
import_settings='0'
sleep 1
fi
if whiptail --yesno "Would you like use exist Flux chain?" 8 65; then
use_old_chain='1'
skip_bootstrap='1'
sleep 1
else
use_old_chain='0'
sleep 1
fi
fi
if [[ "$skip_zelcash_config" == "1" ]]; then
prvkey=""
outpoint=""
index=""
zelid=""
kda_address=""
node_label="0"
fix_action="1"
eps_limit="0"
discord="0"
ping="0"
telegram_alert="0"
telegram_bot_token="0"
telegram_chat_id="0"
else
prvkey=$(whiptail --inputbox "Enter your FluxNode Identity Key from Zelcore" 8 65 3>&1 1>&2 2>&3)
sleep 1
outpoint=$(whiptail --inputbox "Enter your FluxNode Collateral TX ID from Zelcore" 8 72 3>&1 1>&2 2>&3)
sleep 1
index=$(whiptail --inputbox "Enter your FluxNode Output Index from Zelcore" 8 65 3>&1 1>&2 2>&3)
sleep 1
while true
do
zel_id=$(whiptail --title "Flux Configuration" --inputbox "Enter your ZEL ID from ZelCore (Apps -> Zel ID (CLICK QR CODE)) " 8 72 3>&1 1>&2 2>&3)
if [ $(printf "%s" "$zel_id" | wc -c) -eq "34" ] || [ $(printf "%s" "$zel_id" | wc -c) -eq "33" ] || [ $(grep -Eo "^0x[a-fA-F0-9]{40}$" <<< "$zel_id") ]; then
echo -e "${ARROW} ${CYAN}Zel ID is valid${CYAN}.........................[${CHECK_MARK}${CYAN}]${NC}"
break
else
echo -e "${ARROW} ${CYAN}Zel ID is not valid try again...........[${X_MARK}${CYAN}]${NC}"
sleep 4
fi
done
sleep 1
while true
do
KDA_A=$(whiptail --inputbox "Please enter your Kadena address from Zelcore" 8 85 3>&1 1>&2 2>&3)
KDA_A=$(grep -Eo "^k:[0-9a-z]{64}\b" <<< "$KDA_A")
if [[ "$KDA_A" != "" && "$KDA_A" != *kadena* && "$KDA_A" = *k:* ]]; then
echo -e "${ARROW} ${CYAN}Kadena address is valid.................[${CHECK_MARK}${CYAN}]${NC}"
kda_address="kadena:$KDA_A?chainid=0"
sleep 2
break
else
echo -e "${ARROW} ${CYAN}Kadena address is not valid.............[${X_MARK}${CYAN}]${NC}"
sleep 2
fi
done
sleep 1
if whiptail --yesno "Would you like enable autoupdate?" 8 65; then
zelflux_update='1'
zelcash_update='1'
zelbench_update='1'
else
zelflux_update='0'
zelcash_update='0'
zelbench_update='0'
fi
if whiptail --yesno "Would you like enable alert notification?" 8 65; then
whiptail --msgbox "Info: to select/deselect item use 'space' ...to switch to OK/Cancel use 'tab' " 10 60
sleep 1
CHOICES=$(whiptail --title "Choose options: " --separate-output --checklist "Choose options: " 10 45 5 \
"1" "Discord notification " ON \
"2" "Telegram notification " OFF 3>&1 1>&2 2>&3 )
if [[ -z "$CHOICES" ]]; then
echo -e "${ARROW} ${CYAN}No option was selected...Alert notification disabled! ${NC}"
sleep 1
discord="0"
ping="0"
telegram_alert="0"
telegram_bot_token="0"
telegram_chat_id="0"
node_label="0"
else
for CHOICE in $CHOICES; do
case "$CHOICE" in
"1")
discord=$(whiptail --inputbox "Enter your discord server webhook url" 8 65 3>&1 1>&2 2>&3)
sleep 1
if whiptail --yesno "Would you like enable nick ping on discord?" 8 60; then
while true
do
ping=$(whiptail --inputbox "Enter your discord user id" 8 60 3>&1 1>&2 2>&3)
if [[ $ping == ?(-)+([0-9]) ]]; then
string_limit_check_mark "UserID is valid..........................................."
break
else
string_limit_x_mark "UserID is not valid try again............................."
sleep 1
fi
done
sleep 1
else
ping="0"
sleep 1
fi
;;
"2")
telegram_alert="1"
while true
do
telegram_bot_token=$(whiptail --inputbox "Enter telegram bot token from BotFather" 8 65 3>&1 1>&2 2>&3)
if [[ $(grep ':' <<< "$telegram_bot_token") != "" ]]; then
string_limit_check_mark "Bot token is valid..........................................."
break
else
string_limit_x_mark "Bot token is not valid try again............................."
sleep 1
fi
done
sleep 1
while true
do
telegram_chat_id=$(whiptail --inputbox "Enter your chat id from GetIDs Bot" 8 60 3>&1 1>&2 2>&3)
if [[ $telegram_chat_id == ?(-)+([0-9]) ]]; then
string_limit_check_mark "Chat ID is valid..........................................."
break
else
string_limit_x_mark "Chat ID is not valid try again............................."
sleep 1
fi
done
sleep 1
;;
esac
done
fi
while true
do
node_label=$(whiptail --inputbox "Enter name of your node (alias)" 8 65 3>&1 1>&2 2>&3)
if [[ "$node_label" != "" && "$node_label" != "0" ]]; then
string_limit_check_mark "Node name is valid..........................................."
break
else
string_limit_x_mark "Node name is not valid try again............................."
sleep 1
fi
done
else
discord="0"
ping="0"
telegram_alert="0"
telegram_bot_token="0"
telegram_chat_id="0"
node_label="0"
sleep 1
fi