forked from BlackBeard085/x1console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
x1console.sh
executable file
·722 lines (629 loc) · 22.6 KB
/
x1console.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
#!/bin/bash
# Function to check if a Node.js package is installed
check_npm_package() {
PACKAGE=$1
# Check if the package is installed by looking for it in the node_modules directory
if npm list -g --depth=0 | grep -q "$PACKAGE@"; then
echo -e "\n$PACKAGE is already installed."
else
echo -e "\n$PACKAGE is not installed. Installing..."
npm install -g "$PACKAGE"
fi
}
# Function to check x1/solanalabs directory and handle user choice
check_solanalabs_directory() {
SOLANALABS_DIR="$HOME/x1/solanalabs"
ARCHIVE_DIR="$HOME/archive"
if [ -d "$SOLANALABS_DIR" ]; then
echo -e "\nx1/solanalabs directory already exists, do you wish to delete or archive this directory? (delete/archive)"
read -r action
case $action in
delete)
echo -e "\nDeleting $SOLANALABS_DIR..."
rm -rf "$SOLANALABS_DIR" && rm -rf $HOME/x1console/wallets.json && rm -rf $HOME/x1console/addressbook.json
echo -e "$SOLANALABS_DIR has been deleted.\n"
;;
archive)
echo -e "\nArchiving $SOLANALABS_DIR..."
# Check if archive directory exists; if not, create it
mkdir -p "$ARCHIVE_DIR"
# Move the solanalabs directory to archive
mv -f "$SOLANALABS_DIR" "$ARCHIVE_DIR/"
echo -e "$SOLANALABS_DIR has been moved to $ARCHIVE_DIR.\n"
;;
*)
echo -e "\nInvalid action. Continuing without deleting or archiving.\n"
;;
esac
fi
}
# Function to execute the install_run.sh script
install() {
echo -e "\nDo you have existing X1 validator wallets? (yes/no)"
read -r wallet_response
if [[ "$wallet_response" == "yes" ]]; then
echo -e "\nHave these been copied to the .config/solana directory? (yes/no)"
read -r copied_response
if [[ "$copied_response" == "yes" ]]; then
echo -e "\nContinuing with X1 installation...\n"
else
echo -e "\nPlease copy these wallets to your '.config/solana' directory before starting X1 install."
echo -e "Please note your id.json is also your withdrawer and sometimes saved as withdrawer.json; please rename it to id.json if needed.\n"
exit 1
fi
else
echo -e "\nYour validator wallets will be created for you. Continuing with X1 installation...\n"
fi
# Check x1/solanalabs directory before proceeding
check_solanalabs_directory
# Allowing the firewall for ports 8000 to 10000
echo -e "\nConfiguring firewall to allow access to ports 8000-10000 and 3334..."
sudo ufw allow 8000:10000/tcp
sudo ufw allow 8000:10000/udp
sudo ufw allow 3334
# Execute install_run.sh
if [ -f ./install_run.sh ]; then
echo -e "\nExecuting install_run.sh..."
./install_run.sh
# Change the path for copying solana-validator to your
echo -e "\nCopying solana-validator to your path..."
cp "$HOME/x1/solanalabs/target/release/solana-validator" "$HOME/.local/share/solana/install/active_release/bin/solana-validator"
sudo cp "$HOME/x1/solanalabs/target/release/solana-validator" /usr/local/bin
echo -e "\nCopying wallets.json to x1console directory..."
cp "$HOME/x1/solanalabs/wallets.json" "$HOME/x1console"
# New Addition: Attempt to execute 1ststake.js
echo -e "\nAttempting to execute 1ststake.js..."
if [ -f ./1ststake.js ]; then
node ./1ststake.js
if [ $? -eq 0 ]; then
echo -e "\n1ststake.js executed successfully.\n"
else
echo -e "\nFailed to execute 1ststake.js.\n"
fi
else
echo -e "\n1ststake.js does not exist. Please create it in the directory.\n"
fi
# Attempting to restart validator
echo -e "\nAttempting to restart validator..."
if [ -f ./1strestart.js ]; then
# Using spawn for executing 1strestart.js
node ./1strestart.js
if [ $? -eq 0 ]; then
echo -e "\nValidator has been restarted successfully."
# Run setpinger.js after restart is successful
if [ -f ./setpinger.js ]; then
echo -e "\nExecuting setpinger.js..."
node ./setpinger.js
if [ $? -eq 0 ]; then
echo -e "\nsetpinger.js executed successfully.\n"
else
echo -e "\nFailed to execute setpinger.js.\n"
fi
else
echo -e "\nsetpinger.js does not exist. Please create it in the directory.\n"
fi
else
echo -e "\nFailed to restart the validator.\n"
fi
else
echo -e "\nrestart.js does not exist. Please create it.\n"
fi
else
echo -e "\ninstall_run.sh does not exist. Please create it.\n"
fi
}
# Function to update Solana CLI and the application
update_x1() {
SOLANALABS_DIR="$HOME/x1/solanalabs"
if [ -d "$SOLANALABS_DIR" ]; then
cd "$SOLANALABS_DIR" || exit
# Check if the validator is running on port 8899
if lsof -i :8899; then
echo -e "\nValidator is currently running. Stopping the validator..."
solana-validator exit -f
echo -e "Validator has been stopped."
else
echo -e "\nValidator is not running. Continuing with the update...\n"
fi
echo -e "\nUpdating Server"
sudo apt update && sudo apt upgrade
echo -e "\nUpdating X1 Validator"
git stash && git pull
echo -e "\nCleaning up Cargo build..."
cargo clean
echo -e "\nBuilding project in release mode..."
cargo build --release
echo -e "\nCopying solana-validator to /usr/local/bin..."
sudo cp "$HOME/x1/solanalabs/target/release/solana-validator" /usr/local/bin
else
echo -e "\nDirectory $SOLANALABS_DIR does not exist. Skipping Cargo commands.\n"
fi
echo -e "\nSystem updated.\n"
# Execute restart.js after updating
if [ -f "$HOME/x1console/restart.js" ]; then
echo -e "\nExecuting restart.js..."
node "$HOME/x1console/restart.js"
if [ $? -eq 0 ]; then
echo -e "\nRestart script executed successfully.\n"
else
echo -e "\nFailed to execute the restart script.\n"
fi
else
echo -e "\nrestart.js does not exist in $HOME/x1console.\n"
fi
pause
}
# Function to update the X1 console
update_x1_console() {
echo -e "\nStashing local changes..."
git stash
echo -e "\nPulling latest changes..."
git pull
echo -e "\nX1 console updated.\n"
pause
}
# Function for health check and start validator
health_check() {
echo -e "\nRunning setwithdrawer.js..."
node "$HOME/x1console/setwithdrawer.js"
echo -e "\nRunning health.js..."
HEALTH_OUTPUT=$(node "$HOME/x1console/health.js")
echo -e "$HEALTH_OUTPUT"
if echo "$HEALTH_OUTPUT" | grep -q "WARNING"; then
echo -e "\nWARNING issued in health check."
# Execute checkaccounts.js before getbalances.js
echo -e "\nRunning checkaccounts.js..."
node "$HOME/x1console/checkaccounts.js"
echo -e "\nRunning getbalances.js..."
node "$HOME/x1console/getbalances.js"
echo -e "\nRunning checkstake.js..."
STAKE_OUTPUT=$(node "$HOME/x1console/checkstake.js")
echo -e "$STAKE_OUTPUT"
if echo "$STAKE_OUTPUT" | grep -q "0 active stake"; then
echo -e "\n0 active stake found. Running activatestake.js..."
node "$HOME/x1console/activatestake.js"
echo -e "\nRunning restart.js after activating stake..."
node "$HOME/x1console/restart.js"
else
echo -e "\nActive stake found. Running restart.js..."
node "$HOME/x1console/restart.js"
fi
else
echo -e "\nNo WARNING issued in health check. Exiting.\n"
fi
pause
}
# New function to check balances
balances() {
echo -e "\nRunning setwithdrawer.js..."
node "$HOME/x1console/setwithdrawer.js"
echo -e "\nRunning checkaccounts.js..."
if [ -f "$HOME/x1console/checkaccounts.js" ]; then
node "$HOME/x1console/checkaccounts.js"
if [ $? -eq 0 ]; then
echo -e "\nAccounts checked successfully.\n"
else
echo -e "\nUnable to send funds to underfunded wallets.\n"
fi
else
echo -e "\ncheckaccounts.js does not exist. Please create it.\n"
fi
echo -e "\nRunning getbalances.js..."
if [ -f "$HOME/x1console/getbalances.js" ]; then
node "$HOME/x1console/getbalances.js"
if [ $? -eq 0 ]; then
echo -e "\nBalances checked successfully.\n"
else
echo -e "\nFailed to check balances.\n"
fi
else
echo -e "\ngetbalances.js does not exist. Please create it.\n"
fi
pause
}
# Updated function to publish validator info
publish_validator() {
echo -e "\nRunning setwithdrawer.js..."
node "$HOME/x1console/setwithdrawer.js"
echo -e "\nPublishing validator information..."
if [ -f "$HOME/x1console/publish.js" ]; then
node "$HOME/x1console/publish.js"
if [ $? -eq 0 ]; then
echo -e "\nValidator info published on X1.\n"
else
echo -e "\nFailed to publish validator info.\n"
fi
else
echo -e "\npublish.js does not exist. Please create it.\n"
fi
pause
}
# New function to manage pinger
pinger() {
echo -e "\nChoose a subcommand:"
echo -e "1. Restart Pinger"
echo -e "2. Ping Times"
read -p "Enter your choice [1-2]: " pinger_choice
case $pinger_choice in
1)
restart_pinger
;;
2)
ping_times
;;
*)
echo -e "\nInvalid subcommand choice. Returning to main menu.\n"
;;
esac
}
# New function to restart pinger
restart_pinger() {
echo -e "\nExecuting setpinger.js..."
if [ -f "$HOME/x1console/setpinger.js" ]; then
node "$HOME/x1console/setpinger.js"
if [ $? -eq 0 ]; then
echo -e "\nsetpinger.js executed successfully.\n"
else
echo -e "\nFailed to execute setpinger.js.\n"
fi
else
echo -e "\nsetpinger.js does not exist. Please create it.\n"
fi
pause
}
# New function to check ping times
ping_times() {
echo -e "\nFetching ping times...\n"
curl http://localhost:3334/ping_times | jq
echo -e "\nFinished fetching ping times. Returning to menu.\n"
pause
}
# New function for managing the ledger
ledger() {
echo -e "\nChoose a subcommand:"
echo -e "1. Ledger Monitor"
echo -e "2. Remove Ledger"
read -p "Enter your choice [1-2]: " ledger_choice
case $ledger_choice in
1)
ledger_monitor
;;
2)
remove_ledger
;;
*)
echo -e "\nInvalid subcommand choice. Returning to main menu.\n"
;;
esac
}
# New function to monitor the ledger
ledger_monitor() {
echo -e "\nStarting ledger monitoring. Press any key to stop...\n"
# Navigate to the solanalabs directory and run the command
cd "$HOME/x1/solanalabs/" || exit
solana-validator --ledger ledger monitor & # Run in the background
# Get the PID of the last command run in the background
PID=$!
# Wait for user input to stop the command
read -n 1 -s -r -p "Press any key to stop the ledger monitoring..."
# Kill the running process
kill "$PID"
echo -e "\nLedger monitoring stopped.\n"
pause
}
# New function to remove the ledger
remove_ledger() {
# Check if the validator is running using port 8899
if lsof -i :8899; then
echo -e "\nValidator is running. Ledger can only be removed when the validator has stopped."
pause
return
fi
# If validator is not running, ask for confirmation to remove ledger
echo -e "\nAre you sure you wish to remove the ledger? (y/n)"
read -r confirmation
case $confirmation in
y|Y)
echo -e "\nRemoving the ledger..."
rm -rf "$HOME/x1/solanalabs/ledger"
echo -e "Ledger removed successfully.\n"
;;
n|N)
echo -e "\nOperation canceled. Returning to menu.\n"
;;
*)
echo -e "\nInvalid option. Returning to menu.\n"
;;
esac
pause
}
# New function for setting commission
set_commission() {
# Run setwithdrawer.js
echo -e "\nRunning setwithdrawer.js..."
node "$HOME/x1console/setwithdrawer.js"
# Prompt user for the commission percentage
read -p "What percent would you like to set your commission at? (0-100): " commission_percent
# Validate the user input
if [[ "$commission_percent" -ge 0 ]] && [[ "$commission_percent" -le 100 ]]; then
# Run the commission setting command
echo -e "\nSetting commission to $commission_percent%..."
solana vote-update-commission "$HOME/.config/solana/vote.json" "$commission_percent" "$HOME/.config/solana/id.json"
if [ $? -eq 0 ]; then
echo -e "\nCommission set successfully.\n"
else
echo -e "\nFailed to set commission.\n"
fi
else
echo -e "\nInvalid percentage. Please enter a value between 0 and 100.\n"
fi
pause
}
# Function for 'Other' menu
other_options() {
while true; do
echo -e "\nChoose an option under 'Other':"
echo -e "1. Install, Start X1 and Pinger or [RESET]"
echo -e "2. Update"
echo -e "3. Pinger"
echo -e "4. Speed Test"
echo -e "5. Return to Main Menu"
read -p "Enter your choice [1-5]: " other_choice
case $other_choice in
1)
install
# Display wallet addresses after installation
echo -e "\n"
# Read wallet addresses from wallets.json
if [ -f "$HOME/x1/solanalabs/wallets.json" ]; then
echo -e "Wallet Addresses:"
# Using jq to parse the JSON file
jq -r 'to_entries | .[] | "\(.key): \(.value)"' "$HOME/x1/solanalabs/wallets.json"
else
echo -e "\nwallets.json not found.\n"
fi
echo -e "\nThese are your pubkeys for your validator wallets; the private keys are stored in the .config/solana directory; please keep them safe.\n"
echo -e "If this was your first installation, please copy the following command and run it in your terminal to be able to run the CLI straight away:"
echo -e "\nexport PATH=\"$HOME/.local/share/solana/install/active_release/bin:\$PATH\"\n"
echo -e "\nOR LOG OUT AND BACK IN TO YOUR SERVER FOR CHANGES TO TAKE EFFECTn"
# Indicate that setup is complete
echo -e "Setup is complete.\n"
;;
2)
echo -e "\nChoose a subcommand:"
echo -e "1. Update X1 Validator"
echo -e "2. Update X1 Console"
read -p "Enter your choice [1-2]: " update_choice
case $update_choice in
1)
update_x1
;;
2)
update_x1_console
;;
*)
echo -e "\nInvalid subcommand choice. Returning to main menu.\n"
;;
esac
;;
3)
pinger
;;
4)
# Execute speedtest.sh when chosen
echo -e "\nExecuting speedtest.sh..."
if [ -f "$HOME/x1console/speedtest.sh" ]; then
bash "$HOME/x1console/speedtest.sh"
if [ $? -eq 0 ]; then
echo -e "\nSpeed test completed successfully.\n"
else
echo -e "\nFailed to execute speed test.\n"
fi
else
echo -e "\nspeedtest.sh does not exist. Please create it in the x1console directory.\n"
fi
;;
5)
break
;;
*)
echo -e "\nInvalid choice. Please choose from 1 to 5.\n"
;;
esac
done
}
# Function to handle transfers and an address book
transfers() {
while true; do
echo -e "\nChoose a subcommand for Transfers:"
echo -e "1. Transfer"
echo -e "2. Address Book"
echo -e "3. Return to Main Menu"
read -p "Enter your choice [1-3]: " transfer_choice
case $transfer_choice in
1)
echo -e "\nRunning setwithdrawer.js..."
node "$HOME/x1console/setwithdrawer.js"
echo -e "\nRunning transfer.js..."
if [ -f "$HOME/x1console/transfer.js" ]; then
node "$HOME/x1console/transfer.js"
if [ $? -eq 0 ]; then
echo -e "\nTransfer completed successfully.\n"
else
echo -e "\nTransfer failed.\n"
fi
else
echo -e "\ntransfer.js does not exist. Please create it.\n"
fi
pause
;;
2)
echo -e "\nRunning addressbook.js..."
if [ -f "$HOME/x1console/addressbook.js" ]; then
node "$HOME/x1console/addressbook.js"
if [ $? -eq 0 ]; then
echo -e "\nAddress Book accessed successfully.\n"
else
echo -e "\nFailed to access Address Book.\n"
fi
else
echo -e "\naddressbook.js does not exist. Please create it.\n"
fi
pause
;;
3)
break
;;
*)
echo -e "\nInvalid choice. Please choose from 1 to 3.\n"
;;
esac
done
}
# Function for managing stake
manage_stake() {
echo -e "\nRunning managestake.sh..."
if [ -f "$HOME/x1console/managestake.sh" ]; then
bash "$HOME/x1console/managestake.sh"
if [ $? -eq 0 ]; then
echo -e "\nManage Stake completed successfully.\n"
else
echo -e "\nFailed to manage stake.\n"
fi
else
echo -e "\nmanagestake.sh does not exist. Please create it.\n"
fi
pause
}
# Function for withdrawing stake/vote
withdraw_stake_vote() {
echo -e "\nRunning withdraw.sh..."
if [ -f "$HOME/x1console/withdraw.sh" ]; then
bash "$HOME/x1console/withdraw.sh"
if [ $? -eq 0 ]; then
echo -e "\nWithdraw Stake/Vote completed successfully.\n"
else
echo -e "\nFailed to withdraw stake/vote.\n"
fi
else
echo -e "\nwithdraw.sh does not exist. Please create it.\n"
fi
pause
}
# Placeholder function for speed test (this will be handled in other_options now)
speed_test() {
echo -e "\nRunning Speed Test...\n"
# Placeholder for speed test logic
pause
}
# Function to exit the script
exit_script() {
echo -e "\nExiting the script.\n"
exit 0
}
# Function to pause and wait for user input
pause() {
read -n 1 -s -r -p "Press any button to return to the menu..."
echo -e "\n"
}
# Check if NVM is installed
if command -v nvm &> /dev/null; then
echo -e "\nNVM is already installed."
else
echo -e "\nNVM is not installed. Installing..."
# Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash
# Load NVM into the current shell session
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
fi
# Source .bashrc to ensure the NVM command is available in the session
source ~/.bashrc
# Install Node.js version 20.0.0
nvm install v20.0.0
# Check for @solana/web3.js package
check_npm_package "@solana/web3.js"
# Make another script executable
if [ -f ./install_run.sh ]; then
chmod +x ./install_run.sh
echo -e "\ninstall_run.sh has been made executable.\n"
else
echo -e "\ninstall_run.sh does not exist. Please create it.\n"
fi
# Print welcome message
echo -e "\nAHOY MI HEARTIES, WELCOME TO X1'S THE BLACK PEARL - THE INTERACTIVE, AUTOMATED X1 VALIDATOR MANAGER! YOUR DELEGATIONS ARE MUCH APPRECIATED! ==============FOR FIRST TIME USER NAVIGATE TO OTHER MENU, OPTION 10, THEN OPTION 1. INSTALL, START X1 AND PINGER==========\n"
# Interaction to execute install function or update, health check, or exit
while true; do
echo -e "\nChoose an option:"
echo -e "1. Health Check and Start Validator"
echo -e "2. Validator"
echo -e "3. Check Balances"
echo -e "4. Transfers"
echo -e "5. Manage Stake"
echo -e "6. Withdraw Stake/Vote"
echo -e "7. Ledger"
echo -e "8. Set Commission"
echo -e "9. Publish Validator"
echo -e "10. Other"
echo -e "11. Exit"
read -p "Enter your choice [1-11]: " choice
case $choice in
1)
health_check
continue
;;
2)
echo -e "\nRunning manageval.sh..."
if [ -f "$HOME/x1console/manageval.sh" ]; then
bash "$HOME/x1console/manageval.sh"
if [ $? -eq 0 ]; then
echo -e "\nValidator management completed successfully.\n"
else
echo -e "\nFailed to manage validator.\n"
fi
else
echo -e "\nmanageval.sh does not exist. Please create it.\n"
fi
pause
continue
;;
3)
balances
continue
;;
4)
transfers
continue
;;
5)
manage_stake
continue
;;
6)
withdraw_stake_vote
continue
;;
7)
ledger
continue
;;
8)
set_commission
continue
;;
9)
publish_validator
continue
;;
10)
other_options
continue
;;
11)
exit_script
;;
*)
echo -e "\nInvalid choice. Please choose from 1 to 11.\n"
;;
esac
done