-
Notifications
You must be signed in to change notification settings - Fork 15
/
qone_2.sh
1206 lines (1024 loc) · 37.1 KB
/
qone_2.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
# Define the version number here
SCRIPT_VERSION="2.5.0"
#=====================
# Menu interface
#=====================
display_menu() {
clear
source ~/.bashrc
cat << EOF
Q1Q1Q1\ Q1\
Q1 __Q1\ Q1Q1 |
Q1 | Q1 |\_Q1 |
Q1 | Q1 | Q1 |
Q1 | Q1 | Q1 |
Q1 Q1Q1 | Q1 |
\Q1Q1Q1 / Q1Q1Q1\
\___Q1Q\ \______| QUILIBRIUM.ONE
\___|
==================================================================
////////////////// Q1 QUICKSTART MENU - $SCRIPT_VERSION ////////////////////
==================================================================
Node guide: https://docs.quilibrium.one
------------------------------------------------------------------
EOF
# Perform a fresh check only if the parameter is not "skip_check"
if [ "$1" != "skip_check" ]; then
while IFS= read -r line; do
if [[ $line == *"Node installed:"* ]]; then
NODE_INSTALLED=${line#*: }
elif [[ $line == *"Current Node version:"* ]]; then
CURRENT_NODE_VERSION=${line#*: }
elif [[ $line == *"Latest Node version:"* ]]; then
LATEST_NODE_VERSION=${line#*: }
elif [[ $line == *"Qclient installed:"* ]]; then
QCLIENT_INSTALLED=${line#*: }
elif [[ $line == *"Current Qclient version:"* ]]; then
CURRENT_QCLIENT_VERSION=${line#*: }
elif [[ $line == *"Latest Qclient version:"* ]]; then
LATEST_QCLIENT_VERSION=${line#*: }
fi
done < <(fresh_check)
fi
if [ "$NODE_INSTALLED" = "Yes" ]; then
display_version_status "$CURRENT_NODE_VERSION" "$LATEST_NODE_VERSION" "Node"
else
echo -e "🔴 ${RED}Node not installed${NC}"
fi
if [ "$QCLIENT_INSTALLED" = "Yes" ]; then
display_version_status "$CURRENT_QCLIENT_VERSION" "$LATEST_QCLIENT_VERSION" "Qclient"
else
echo -e "🔴 ${RED}Qclient not installed${NC}"
fi
# Autoudpate Toggle
echo
echo -e "Auto-update: $([ "$(check_autoupdate_status)" = "ON" ] && echo "🟢" || echo "🔴") $(check_autoupdate_status)"
# Display installation instructions only if node is not installed
if [ "$NODE_INSTALLED" != "Yes" ]; then
cat << EOF
HOW TO INSTALL A NEW NODE?
Choose option 1, reboot and then choose 2.
Let your node run for 30 minutes, then choose option 3. Done!
1) Prepare your server
2) Install node
3) Set up gRPCurl
EOF
fi
cat << EOF
-----------------------------------------------------------------
3) Set up gRPCurl 11) Balance log
4) Node Log 12) Backup your node
5) Update node 13) Restore backup
6) Stop node
7) Start node 14) Qclient install/update
8) Restart node 15) Qclient actions (BETA)
9) Node info & balance
10) Node status 16) Auto-update ON/OFF
-----------------------------------------------------------------
B) ⭐ Best server providers A) Menu autoload on login
D) 💜 Donations H) Help
-----------------------------------------------------------------
E) Exit X) Disclaimer
EOF
}
#=====================
# Main Menu loop
#=====================
main() {
while true; do
if $REDRAW_MENU; then
display_menu
REDRAW_MENU=false
fi
read -rp "Enter your choice: " choice
case $choice in
1)
if confirm_action "$(wrap_text "$prepare_server_message" "")" "Prepare your server" install_prerequisites; then
prompt_return_to_menu "skip_check"
fi
;;
2)
if confirm_action "$(wrap_text "$install_node_message" "")" "Install node" install_node; then
prompt_return_to_menu
fi
;;
3) confirm_action "$(wrap_text "$setup_grpcurl_message" "")" "Set up gRPCurl" configure_grpcurl && prompt_return_to_menu "skip_check" ;;
4) node_logs; press_any_key ;;
5)
if confirm_action "$(wrap_text "$update_node_message" "")" "Update node" update_node; then
prompt_return_to_menu
fi
;;
6) stop_node; press_any_key ;;
7) start_node; press_any_key ;;
8) restart_node; press_any_key ;;
9) node_info; press_any_key ;;
10) node_status; press_any_key ;;
11) balance_log && prompt_return_to_menu "skip_check" ;;
12) confirm_action "$(wrap_text "$backup_storj_message" "")" "Backup your node on StorJ" backup_storj && prompt_return_to_menu "skip_check" ;;
13) confirm_action "$(wrap_text "$backup_restore_storj_message" "")" "Restore a node backup from StorJ" backup_restore_storj && prompt_return_to_menu "skip_check" ;;
#14) system_cleaner && prompt_return_to_menu "skip_check" ;;
14)
if confirm_action "$(wrap_text "$qclient_install_message" "")" "qClient install" qclient_install; then
prompt_return_to_menu
fi
;;
15) qclient_actions; clear; display_menu "skip_check" ;;
16) toggle_autoupdate; press_any_key ;;
[bB]) best_providers; press_any_key ;;
[dD]) donations; press_any_key ;;
[eE]) exit ;;
[aA]) handle_menu_autoload; press_any_key ;;
[xX]) disclaimer; press_any_key ;;
[hH]) help_message; press_any_key ;;
*) echo "Invalid option, please try again."; press_any_key ;;
esac
done
}
#=====================
# Message Definitions
#=====================
prepare_server_message='
This action will install the necessary prerequisites for your server.
If this is the first time you install a Quilibrium node I suggest you
to follow the online guide instead at: https://docs.quilibrium.one/
'
install_node_message='
This action will install the Qnode & Qclient.
If this is the first time you install a Quilibrium node I suggest you
to follow the online guide instead at: https://docs.quilibrium.one/
Ensure that your server meets all the requirements and that you have
already prepared you server via Step 1.
'
update_node_message='
⚠️ It is strongly advised to backup your "node/.config" folder before updating the node
This action will update your Node & Qclient.
Only use this if you have installed the node via the guide at
https://docs.quilibrium.one/
'
qclient_install_message='
This action will install or update the Qclient.
'
setup_grpcurl_message='
This action will make some edit to your config.yml to enable communication with the network.
If this a fresh node installation, let the node run for 30 minutes before doing this.
'
peer_manifest_message='
This action will check the peer manifest to provide information about the difficulty metric score of your node.
It only works after 15-30 minutes that the node has been running.
'
balance_log_message='
This installer sets up a script to check your node balance
and then sets up a cronjob to log your balance every hour in a CSV file.
To see your existing balance log run "cat ~/scripts/balance_log.csv"
To download the balance log directly run visit:
https://docs.quilibrium.one/start/tutorials/log-your-node-balance-every-1-hour
'
backup_storj_message='
This action automates the backup of your node data to StorJ.
You need a StorJ account https://www.storj.io/ and a Public/Secret access key.
For security we suggest you to create a bucket specific to Quilibrium, and specific keys for accessing only that bucket.
'
backup_restore_storj_message='
This action restores a backup of the node '.config' folder from StorJ.
It will only work if you performed the .config folder backup via the script
in the Q.One Quickstart menu.
'
best_providers_message='
---------------------
BEST SERVER PROVIDERS
---------------------
Check out the best server providers for your node
at ★ https://iri.quest/q-best-providers ★
Avoid using providers that specifically ban crypto and mining.
'
donations_message='
----------
DONATIONS
----------
Quilbrium.one is a one-man volunteer effort.
If you would like to chip in some financial help, thank you!
You can send ERC-20 tokens at this address:
0x0fd383A1cfbcf4d1F493Dd71b798ebca89e8a013
Or visit this page: https://iri.quest/q-donations
'
disclaimer_message='
------------
DISCLAIMER:
------------
This tool and all related scripts are unofficial and are being shared as-is.
I take no responsibility for potential bugs or any misuse of the available options.
All scripts are open source; feel free to inspect them before use.
Repo: https://github.com/lamat1111/QuilibriumScripts
'
test_script_message='
This will run the test script.
'
help_message='
=================================
Q1 HELP
=================================
If something does not work in Q1 please try to update to the
latest version manually by running the code that you find here:
https://docs.quilibrium.one/quilibrium-node-setup-guide/node-quickstart
>> FOLDERS!
The menu will work correctly only if your node istallation follows the default folder structure.
> Node: "$HOME/ceremonyclient/node"
> Qclient: "$HOME/ceremonyclient/client"
> .config folder: "$HOME/ceremonyclient/node/"
> Service name: "ceremonyclient"
>> NODE/QCLIENT is installed, but menu says not installed
In some rare cases the menu may not telling the truth...
But you can always check by looking at your Node log or by trying to use the Qclient
>> UNINSTALL Q1 MENU
To remove the script completely, run: rm ~/qone.sh
------------------------------------------------------
>> Q1 MENU OPTIONS DETAILS
------------------------------------------------------
B) Best server providers:
Check out the best server providers for your node
at ⭐️ https://iri.quest/q-best-providers ⭐️
Avoid using providers that specifically ban crypto and mining.
1) Prepare your server:
Installs the necessary prerequisites for your server.
If this is the first time you install a Quilibrium node, it is recommended
to follow the online guide at: https://docs.quilibrium.one/
2) Install node:
Installs the Qnode & Qclient on your server.
If this is the first time you install a Quilibrium node, it is recommended
to follow the online guide at: https://docs.quilibrium.one/
Ensure that your server meets all the requirements and that you have
already prepared your server via Step 1.
3) Set up gRPCurl:
Edits your config.yml to enable communication with the network.
If this is a fresh node installation, let the node run for 30 minutes before doing this.
You can run the action multiple times and it wiill not cause issues.
4) Node Log:
Displays the log of the node.
5) Update node:
Updates your Qnode & Qclient, if necessary.
Only use this if you have installed the Q1 menu node or the guide at
https://docs.quilibrium.one/
6) Stop node:
Stops the node.
7) Start node:
Starts the node.
8) Restart node:
Stop and then starts the node again.
9) Node info (peerID & balance):
Displays information about your node peerID and balance.
10) Node status:
Shows the status of your node service.
11) Balance log:
Logs your balance every 1 hour on a CSV file.
For more info on how to see/download your balance CSV log, please visit:
https://docs.quilibrium.one/start/tutorials/log-your-node-balance-every-1-hour
12) Backup your node:
Backups your node .config folder and other data on StorJ.
You need a Storj account https://www.storj.io/ and a Public/Secret access key.
13) Restore backup:
Restores your node backup from StorJ.
You need a Storj account https://www.storj.io/ and a Public/Secret access key.
14) System cleaner:
Performs system cleanup tasks. It will not affect your node.
15) Qclient install:
Installs or update the Qclient, to manage your QUIL tokens via CLI.
16) Qclient actions:
Opens a submenu with serveral actions for the Qclient, like: check balance,
create transaction, accept transaction etc.
17) Auto-update ON/OFF:
Sets up auto-updates for Node and Qclient via service file and timer.
If they are already set up, it will activate or deactivate them on user choice.
The timer checks for updates every 1 hour at a random minute.
'
#=====================
# MENU options functions
#=====================
# Function definitions
install_prerequisites() {
echo
echo "⌛️ Preparing server with necessary apps and settings..."
mkdir -p ~/scripts
curl -sSL -o ~/scripts/server_setup.sh "$PREREQUISITES_URL"
chmod +x ~/scripts/server_setup.sh
~/scripts/server_setup.sh
return $?
}
install_node() {
echo
echo "⌛️ Installing node..."
mkdir -p ~/scripts
curl -sSL -o ~/scripts/qnode_service_installer.sh "$NODE_INSTALL_URL"
chmod +x ~/scripts/qnode_service_installer.sh
~/scripts/qnode_service_installer.sh
return $?
}
configure_grpcurl() {
echo
echo "⌛️ Setting up gRPCurl..."
mkdir -p ~/scripts
curl -sSL -o ~/scripts/qnode_gRPC_calls_setup.sh "$GRPCURL_CONFIG_URL"
chmod +x ~/scripts/qnode_gRPC_calls_setup.sh
~/scripts/qnode_gRPC_calls_setup.sh
prompt_return_to_menu
return $?
}
update_node() {
echo
echo "⌛️ Updating node..."
mkdir -p ~/scripts
curl -sSL -o ~/scripts/qnode_service_update.sh "$NODE_UPDATE_URL"
chmod +x ~/scripts/qnode_service_update.sh
~/scripts/qnode_service_update.sh
return $?
}
autoupdate_setup() {
echo
echo "⌛️ Setting up auto-update..."
mkdir -p ~/scripts
curl -sSL -o ~/scripts/qnode_autoupdate_setup.sh "$AUTOUPDATE_SETUP_URL"
chmod +x ~/scripts/qnode_autoupdate_setup.sh
~/scripts/qnode_autoupdate_setup.sh
return $?
}
qclient_install() {
echo
echo "⌛️ Installing qClient..."
mkdir -p ~/scripts
curl -sSL -o ~/scripts/qclient_install.sh "$QCLIENT_INSTALL_URL"
chmod +x ~/scripts/qclient_install.sh
~/scripts/qclient_install.sh
return $?
}
qclient_actions() {
clear # This clears everything, including the main menu
if [ ! -f ~/scripts/qclient_actions.sh ]; then
mkdir -p ~/scripts
curl -sSL -o ~/scripts/qclient_actions.sh "$QCLIENT_ACTIONS_URL"
chmod +x ~/scripts/qclient_actions.sh
fi
~/scripts/qclient_actions.sh # This runs in the cleared screen
local exit_status=$?
# Only redraw menu if we didn't exit the qclient actions menu
if [ $exit_status -eq 0 ]; then
clear
display_menu "skip_check"
fi
return $exit_status
}
system_cleaner() {
echo
echo "⌛️ Cleaning your system..."
curl -sSL "$SYSTEM_CLEANER_URL" | bash
return $?
}
balance_log() {
echo
if [ -f "$HOME/scripts/qnode_balance_checker.sh" ] && crontab -l | grep -q "qnode_balance_checker.sh"; then
echo "Balance log is already set up. What would you like to do?"
echo
echo "1 - Download balance log"
echo "2 - See balance log"
echo "3 - Clean balance log"
echo
read -p "Enter your choice (1, 2 or 3): " choice
case $choice in
1)
echo
mkdir -p ~/scripts && \
curl -sSL -o ~/scripts/qnode_balance_log_download.sh "https://raw.githubusercontent.com/lamat1111/QuilibriumScripts/main/tools/qnode_balance_log_download.sh" && \
chmod +x ~/scripts/qnode_balance_log_download.sh && \
~/scripts/qnode_balance_log_download.sh
;;
2)
if [ -f "$HOME/scripts/balance_log.csv" ]; then
echo
echo "Balance Log"
echo "================="
echo
cat "$HOME/scripts/balance_log.csv"
else
echo "Balance log file not found."
fi
;;
3)
echo "This option will completely delete your balance log. Proceed? (y/n)"
read -p "> " confirm
if [[ "$confirm" =~ ^[Yy]$ ]]; then
if rm "$HOME/scripts/balance_log.csv"; then
echo "Balance log has been deleted."
else
echo "Error: Failed to delete balance log or file doesn't exist."
fi
else
echo "Operation cancelled."
fi
;;
*)
echo "Invalid choice. Please run the balance log option again."
;;
esac
else
echo "⌛️ Installing the balance log script..."
curl -sSL "$BALANCE_LOG_URL" | bash
fi
return $?
}
backup_storj() {
echo
echo "⌛️ Downloading Storj backup script..."
mkdir -p ~/scripts
if curl -sSL -o ~/scripts/qnode_backup_storj.sh "$BACKUP_STORJ_URL"; then
chmod +x ~/scripts/qnode_backup_storj.sh
if ~/scripts/qnode_backup_storj.sh; then
echo "✅ Storj backup completed successfully."
else
echo "❌ Storj backup script encountered an error."
fi
else
echo "❌ Failed to download Storj backup script."
fi
return $?
}
backup_restore_storj() {
echo
echo "⌛️ Downloading Storj backup restore script..."
mkdir -p ~/scripts
if curl -sSL -o ~/scripts/qnode_backup_restore_storj.sh "$BACKUP_RESTORE_STORJ_URL"; then
chmod +x ~/scripts/qnode_backup_restore_storj.sh
if ~/scripts/qnode_backup_restore_storj.sh; then
echo "✅ Storj backup restore completed successfully."
else
echo "❌ Storj backup restore script encountered an error."
fi
else
echo "❌ Failed to download Storj backup restore script."
fi
return $?
}
quil_balance() {
if [ ! -f "$SERVICE_FILE" ]; then
echo "$MISSING_SERVICE_MSG"
return 1
elif [ -z "$NODE_EXEC" ]; then
echo "Error: No node binary found. Is the node installed correctly?"
return 1
else
echo
echo "⌛️ Displaying your QUIL balance..."
echo "The node has to be running for at least 10 minutes for this command to work."
echo "If it still doesn't work you can try the direct commands: https://iri.quest/q-node-info"
echo
if [ -d "$NODE_DIR" ]; then
"$NODE_EXEC" -balance
else
echo "Error: Node directory not found. Is the node installed correctly?"
fi
echo
return 0
fi
}
node_info() {
if [ ! -f "$SERVICE_FILE" ]; then
echo "$MISSING_SERVICE_MSG"
elif [ -z "$NODE_EXEC" ]; then
echo "Error: No node binary found. Is the node installed correctly?"
else
echo
echo "⌛️ Displaying node info..."
echo "If this doesn't work you can try the direct commands: https://iri.quest/q-node-info"
echo
if [ -d "$NODE_DIR" ]; then
"$NODE_EXEC" -node-info
else
echo "Error: Node directory not found. Is the node installed correctly?"
fi
echo
fi
}
node_logs() {
if [ ! -f "$SERVICE_FILE" ]; then
echo "$MISSING_SERVICE_MSG"
display_menu "skip_check"
return 0
fi
echo
echo "⌛️ Displaying your node log... (Press CTRL+C to return to the main menu)"
echo
# Trap CTRL+C to directly call display_menu
trap 'display_menu "skip_check"' INT
sudo journalctl -u ceremonyclient.service -f --no-hostname -o cat
# If the command exited without CTRL+C, call display_menu
if [ $? -ne 130 ]; then
display_menu "skip_check"
fi
}
start_node() {
if [ ! -f "$SERVICE_FILE" ]; then
echo "$MISSING_SERVICE_MSG"
else
echo
echo "⌛️ Starting node service..."
echo
service ceremonyclient start
echo "✅ Node started"
echo
fi
}
stop_node() {
if [ ! -f "$SERVICE_FILE" ]; then
echo "$MISSING_SERVICE_MSG"
else
echo
echo "⌛️ Stopping node service..."
echo
service ceremonyclient stop
echo "🔴 Node stopped"
echo
fi
}
restart_node() {
if [ ! -f "$SERVICE_FILE" ]; then
echo "$MISSING_SERVICE_MSG"
else
echo
echo "⌛️ Restarting node service..."
echo
service ceremonyclient restart
echo "✅ Node restarted"
echo
fi
}
node_status() {
if [ ! -f "$SERVICE_FILE" ]; then
echo "$MISSING_SERVICE_MSG"
press_any_key
else
echo
echo "Quilibrium Node Service Status:"
echo
# Get the status output, excluding log entries
systemctl status ceremonyclient.service --no-pager |
awk '
/^[●○]/ { print; in_cgroup = 0; next }
/^ *(Loaded|Active|Process|Main PID|Tasks|Memory|CPU):/ { print; in_cgroup = 0; next }
/^ CGroup:/ { print; in_cgroup = 1; next }
in_cgroup == 1 && /^[[:space:]]/ { print; next }
in_cgroup == 1 && $0 == "" { exit }
'
echo
fi
}
# peer_manifest() {
# echo "⌛️ Checking peer manifest (Difficulty metric)..."
# curl -sSL "$PEER_MANIFEST_URL" | bash
# return $? # This ensures we go back to the main loop
# }
# node_version() {
# if [ ! -f "$SERVICE_FILE" ]; then
# echo "$MISSING_SERVICE_MSG"
# press_any_key
# else
# echo
# echo "⌛️ Displaying node version..."
# echo
# journalctl -u ceremonyclient -r --no-hostname -n 1 -g "Quilibrium Node" -o cat
# echo
# fi
# }
best_providers() {
wrap_text "$best_providers_message"
echo
echo "-------------------------------"
}
donations() {
wrap_text "$donations_message"
echo
echo "-------------------------------"
}
disclaimer() {
wrap_text "$disclaimer_message"
echo
echo "-------------------------------"
}
help_message() {
echo "$help_message"
echo
return $?
}
test_script() {
echo "⌛️ Running test script..."
wget --no-cache -O - "$TEST_URL" | bash
}
#==========================
# CHECK UPDATES
#==========================
# Function to check for newer script version
check_for_updates() {
local SCRIPT_NAME="qone"
local SCRIPT_VERSION="${SCRIPT_VERSION:-0.0.0}" # Fallback if not defined
local GITHUB_RAW_URL="https://raw.githubusercontent.com/lamat1111/QuilibriumScripts/main/qone.sh"
local LATEST_VERSION
LATEST_VERSION=$(curl -sS "$GITHUB_RAW_URL" | grep 'SCRIPT_VERSION=' | head -1 | cut -d'"' -f2)
if [ $? -ne 0 ] || [ -z "$LATEST_VERSION" ]; then
echo "Failed to check for updates. Continuing with current version."
return 1
fi
if [ "$SCRIPT_VERSION" != "$LATEST_VERSION" ]; then
echo "New version available. Attempting update..."
if curl -sS -o "${HOME}/${SCRIPT_NAME}_new.sh" "$GITHUB_RAW_URL"; then
chmod +x "${HOME}/${SCRIPT_NAME}_new.sh"
mv "${HOME}/${SCRIPT_NAME}_new.sh" "${HOME}/${SCRIPT_NAME}.sh"
echo "✅ New version ($LATEST_VERSION) installed. Restarting script..."
exec "${HOME}/${SCRIPT_NAME}.sh"
else
echo "Error: Failed to download the new version. Update aborted."
return 1
fi
else
echo "Current version is up to date."
fi
}
#==========================
# ADD ALIASES
#==========================
setup_aliases() {
SCRIPTS_DIR="$HOME/scripts"
ALIAS_MARKER_FILE="$SCRIPTS_DIR/.q1_alias_added"
# Ensure the scripts directory exists
mkdir -p "$SCRIPTS_DIR"
if [ ! -f "$ALIAS_MARKER_FILE" ]; then
echo "⌛️ Setting up aliases..."
# Remove old alias block (from old script versions)
sed -i '/=== qone.sh setup ===/,/=== end qone.sh setup ===/d' "$HOME/.bashrc"
# Remove new alias block (from newer script versions)
sed -i '/=== qone.sh aliases ===/,/=== end qone.sh aliases ===/d' "$HOME/.bashrc"
# Add the new alias setup
cat << 'EOF' >> "$HOME/.bashrc"
# === qone.sh aliases ===
# The following lines are added to create aliases for qone.sh
alias qone='~/qone.sh'
alias q1='~/qone.sh'
# === end qone.sh aliases ===
EOF
# Create marker file to prevent redundant setup
touch "$ALIAS_MARKER_FILE"
# Source .bashrc to make sure aliases are available immediately
if [ -n "$BASH_VERSION" ]; then
source "$HOME/.bashrc"
echo "Aliases 'q1' and 'qone' are now active."
else
echo "Please run 'source ~/.bashrc' or restart your terminal to use the 'q1' and 'qone' commands."
fi
else
: #echo "Aliases are already set up."
fi
}
#=============================
# VARIABLES
#=============================
#Reload menu
REDRAW_MENU=true
# Service file path
SERVICE_FILE="/lib/systemd/system/ceremonyclient.service"
# Common message for missing service file
MISSING_SERVICE_MSG="⚠️ Your service file does not exist. Looks like you do not have a node running as a service yet!"
INSTALLATION_DIR="$HOME/ceremonyclient" # Default installation directory
NODE_DIR="${INSTALLATION_DIR}/node"
CLIENT_DIR="${INSTALLATION_DIR}/client"
# Find the latest executables
NODE_EXEC=$(find "${NODE_DIR}" -name "node-*" ! -name "*.dgst" ! -name "*.sig*" -type f -executable 2>/dev/null | sort -V | tail -n 1)
QCLIENT_EXEC=$(find "${CLIENT_DIR}" -name "qclient-*" -type f -executable 2>/dev/null | sort -V | tail -n 1)
# URLs for scripts
PREREQUISITES_URL="https://raw.githubusercontent.com/lamat1111/quilibriumscripts/master/server_setup.sh"
NODE_INSTALL_URL="https://raw.githubusercontent.com/lamat1111/QuilibriumScripts/master/qnode_service_installer.sh"
QCLIENT_INSTALL_URL="https://raw.githubusercontent.com/lamat1111/QuilibriumScripts/main/tools/qclient_install.sh"
GRPCURL_CONFIG_URL="https://raw.githubusercontent.com/lamat1111/quilibriumscripts/master/tools/qnode_gRPC_calls_setup.sh"
NODE_UPDATE_URL="https://raw.githubusercontent.com/lamat1111/QuilibriumScripts/master/qnode_service_update.sh"
#PEER_MANIFEST_URL="https://raw.githubusercontent.com/lamat1111/quilibriumscripts/master/tools/qnode_peermanifest_checker.sh"
#CHECK_VISIBILITY_URL="https://raw.githubusercontent.com/lamat1111/QuilibriumScripts/master/tools/qnode_visibility_check.sh"
SYSTEM_CLEANER_URL="https://raw.githubusercontent.com/lamat1111/quilibrium-node-auto-installer/master/tools/qnode_system_cleanup.sh"
BACKUP_STORJ_URL="https://raw.githubusercontent.com/lamat1111/QuilibriumScripts/main/tools/qnode_backup_storj.sh"
BACKUP_RESTORE_STORJ_URL="https://raw.githubusercontent.com/lamat1111/QuilibriumScripts/main/tools/qnode_backup_restore_storj.sh"
BALANCE_LOG_URL="https://raw.githubusercontent.com/lamat1111/QuilibriumScripts/main/tools/qnode_balance_checker_installer.sh"
QCLIENT_ACTIONS_URL="https://raw.githubusercontent.com/lamat1111/quilibriumscripts/master/tools/qclient_actions.sh"
AUTOUPDATE_SETUP_URL="https://raw.githubusercontent.com/lamat1111/QuilibriumScripts/main/tools/qnode_autoupdate_setup.sh"
TEST_URL="https://raw.githubusercontent.com/lamat1111/QuilibriumScripts/main/test/test_script.sh"
#=====================
# Autoupdate Toggle
#=====================
# Function to check if auto-update service files exist
check_autoupdate_files() {
if [ -f "/etc/systemd/system/qnode-autoupdate.service" ] && [ -f "/etc/systemd/system/qnode-autoupdate.timer" ]; then
return 0
else
return 1
fi
}
# Function to check the status of the auto-update service
check_autoupdate_status() {
if check_autoupdate_files; then
if systemctl is-active --quiet qnode-autoupdate.timer; then
echo "ON"
else
echo "OFF"
fi
else
echo "OFF"
fi
}
# Function to set up auto-update
setup_autoupdate() {
echo "⌛️ Setting up auto-update..."
mkdir -p ~/scripts && \
curl -sSL "https://raw.githubusercontent.com/lamat1111/QuilibriumScripts/main/tools/qnode_autoupdate_setup.sh" -o ~/scripts/qnode_autoupdate_setup.sh && \
chmod +x ~/scripts/qnode_autoupdate_setup.sh && \
sudo ~/scripts/qnode_autoupdate_setup.sh
if [ $? -eq 0 ]; then
echo "✅ Auto-update setup completed successfully."
return 0
else
echo "❌ Failed to set up auto-update."
return 1
fi
}
# Function to enable auto-update
enable_autoupdate() {
echo
echo "⌛️ Enabling auto-update..."
if sudo systemctl enable qnode-autoupdate.timer && sudo systemctl start qnode-autoupdate.timer; then
echo "✅ Auto-update enabled."
return 0
else
echo "❌ Failed to enable auto-update."
return 1
fi
}
# Function to disable auto-update
disable_autoupdate() {
echo
echo "⌛️ Disabling auto-update..."
if sudo systemctl stop qnode-autoupdate.timer && sudo systemctl disable qnode-autoupdate.timer; then
echo "✅ Auto-update disabled."
return 0
else
echo "❌ Failed to disable auto-update."
return 1
fi
}
# Main toggle function
toggle_autoupdate() {
local current_status=$(check_autoupdate_status)
if [ "$current_status" = "OFF" ]; then
if ! check_autoupdate_files; then
echo "⌛️ Auto-update is not set up. Setting up now..."
if ! setup_autoupdate; then
echo "❌ Failed to set up auto-update. Please check your permissions and try again."
return 1
fi
else
enable_autoupdate
fi
else
disable_autoupdate
fi
# Refresh status after changes
current_status=$(check_autoupdate_status)
echo "Auto-update is now $current_status."
}
#=====================
# Check node and qclient installations
#=====================
# Define color codes
RED='\033[0;31m'
GREEN='\033[1;32m'
NC='\033[0m' # No Color
version_gt() {
test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1"
}
# Function to display version status with color
display_version_status() {
local current_version=$1
local latest_version=$2
local component=$3
if [ -z "$current_version" ]; then
echo -e "🔴 ${RED}$component: Not installed${NC}"
elif version_gt "$latest_version" "$current_version"; then
echo -e "🟠 ${RED}$component: $current_version - update needed${NC}"
else
echo -e "🟢 $component: $current_version - up to date"
fi
}
# Put these at the top with other functions
get_latest_node_version() {
curl -s https://releases.quilibrium.com/release | grep -oP 'node-\K[0-9]+(\.[0-9]+){2,3}' | sort -V | tail -n 1
}
get_current_node_version() {
basename "$NODE_EXEC" | grep -oP 'node-\K[0-9]+(\.[0-9]+){2,3}'
}
# Same for qclient
get_latest_qclient_version() {
curl -s https://releases.quilibrium.com/qclient-release | grep -oP 'qclient-\K[0-9]+(\.[0-9]+){2,3}' | sort -V | tail -n 1
}
get_current_qclient_version() {
basename "$QCLIENT_EXEC" | grep -oP 'qclient-\K[0-9]+(\.[0-9]+){2,3}'
}
# Function to perform a fresh check of installations and versions
fresh_check() {
# Check node installation and version
if [ -d "${NODE_DIR}" ]; then
if [ -n "$NODE_EXEC" ]; then
local current_version="$(get_current_node_version)"
local latest_version="$(get_latest_node_version)"
if [ $? -eq 0 ] && [ -n "$latest_version" ]; then
echo "Node installed: Yes"
echo "Current Node version: $current_version"
echo "Latest Node version: $latest_version"
else
echo "Node installed: Yes"
echo "Current Node version: $current_version"
echo "Latest Node version: Error fetching"
fi
else
echo "Node installed: Yes, but no executable found"
fi
else
echo "Node installed: No"
fi