forked from dominant-strategies/quai-node-cli-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
quai.sh
executable file
·519 lines (490 loc) · 19.3 KB
/
quai.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
#!/bin/bash
DIALOG_CANCEL=1
DIALOG_ESC=255
STYLECONFIG=~/.dialogrc
MAIN_DIR="quainetwork"
NODE_PROCESS="go-quai"
MINER_PROCESS="quai-cpu-miner"
if [ -f "$STYLECONFIG" ]; then
echo "Styling config found."
if cmp --silent "$STYLECONFIG" ".dialogrc"; then
:
else
cp .dialogrc ~/.dialogrc
fi
else
dialog --create-rc $STYLECONFIG
cp .dialogrc ~/.dialogrc
fi
if command -v go 2>/dev/null; then
:
else
dialog --title "Installation" --msgbox "\nGolang is not installed. Please install to run this script." 0 0
echo "Golang can be installed at https://go.dev/doc/install"
exit
fi
if command -v git 2>/dev/null; then
:
else
dialog --title "Installation" --msgbox "\nGit is not installed. Please install to run this script." 0 0
echo "Git can be installed at https://github.com/git-guides/install-git"
exit
fi
# Check installation status, if not found, prompt the user to install.
if [[ -d "$HOME/$MAIN_DIR/go-quai" && -d "$HOME/$MAIN_DIR/quai-cpu-miner" ]]; then
:
else
# Check if user has configured wallet addresses
dialog --title "Installation" --yesno "\nHave you configured 13 Quai addresses? You'll need them to run a node and mine." 0 0
response=$?
case $response in
0) : ;;
1)
# Inform user to configure addresses
dialog --title "Installation" --msgbox "\nPlease configure your wallet addresses before continuing." 0 0
echo "You can set up addresses here: https://docs.quai.network/use-quai/wallets/quaisnap"
exit
;;
255)
exit
;;
esac
# Check if user wants to install
dialog --title "Installation" --yesno "\nThis will install go-quai and quai-cpu-miner in the home directory. Continue?" 0 0
response=$?
case $response in
0)
# Create directory
cd $HOME
mkdir $MAIN_DIR
# Clone into go-quai
cd $MAIN_DIR
git clone https://github.com/dominant-strategies/go-quai>/dev/null 2>&1 | \
dialog --title "Installation" \
--no-collapse \
--infobox "\nInstalling Node. Please wait." 7 28
#Inform user node is installed
dialog --title "Installation" \
--no-collapse \
--msgbox "\nNode installed.\n \nPress OK to continue." 7 28
#Configure go-quai
cd $HOME/$MAIN_DIR/go-quai
cp network.env.dist network.env
make go-quai>/dev/null 2>&1 |
dialog --title "Installation" \
--no-collapse \
--infobox "\nGenerating binaries.\n \nPlease wait. " 7 28
#Inform user node is configured
dialog --title "Installation" \
--no-collapse \
--msgbox "\nNode configured.\n \nPress OK to continue." 0 0
# Clone into quai-cpu-miner
cd $HOME/$MAIN_DIR
git clone https://github.com/dominant-strategies/quai-cpu-miner>/dev/null 2>&1 | \
dialog --title "Installation" \
--no-collapse \
--infobox "\nInstalling Miner.\n \nPlease wait." 7 28
#Inform user miner is installed
dialog --title "Installation" \
--no-collapse \
--msgbox "\nMiner installed.\n \nPress OK to continue." 7 28
#Configure quai-cpu-miner
cd $HOME/$MAIN_DIR/quai-cpu-miner/config
cp config.yaml.dist config.yaml
cd $HOME/$MAIN_DIR/quai-cpu-miner
make quai-cpu-miner>/dev/null 2>&1 | \
dialog --title "Installation"
--no-collapse \
--infobox "\nGenerating binaries.\n \nPlease wait. " 7 28
#Inform user miner is configured
dialog --title "Installation" \
--no-collapse \
--msgbox "\nMiner configured.\n \nInstallation complete." 0 0
;;
1)
echo "Installation cancelled."
exit ;;
255)
echo "Installation cancelled."
exit ;;
esac
fi
while true; do
# Check if node logs exist (psuedo-check to see if the node has been started before)
if [ -d "$HOME/$MAIN_DIR/go-quai/nodelogs" ]; then
NODELOGS="True"
else
NODELOGS="False"
fi
# Check if miner logs exist (psuedo-check to see if the miner has been started before)
if [ -d "$HOME/$MAIN_DIR/quai-cpu-miner/logs" ]; then
MININGLOGS="True"
else
MININGLOGS="False"
fi
# Check if node is running
if pgrep -x "$NODE_PROCESS">/dev/null 2>&1; then
ISRUNNING="True"
STARTFULLNODE="Node - \Z2Running\Zn"
else
ISRUNNING="False"
STARTFULLNODE="Start Node - \Z1Stopped\Zn"
fi
# Check if miner is running
if pgrep -x "$MINER_PROCESS">/dev/null 2>&1; then
ISMINING="True"
STARTMINING="Miner - \Z2Running\Zn"
else
ISMINING="False"
STARTMINING="Start Miner - \Z1Stopped\Zn"
fi
exec 3>&1
selection=$(dialog \
--backtitle "Quai Hardware Manager" \
--clear \
--colors \
--cancel-label "EXIT" \
--menu "Select an Option:" 14 50 10 \
"1" "$STARTFULLNODE" \
"2" "$STARTMINING" \
"3" "Stop" \
"4" "Update" \
"5" "Node Logs" \
"6" "Miner Logs" \
2>&1 1>&3)
exit_status=$?
exec 3>&-
case $exit_status in
$DIALOG_CANCEL)
# Verify the user wants to stop their node and miner
dialog --colors --title "Alert" --yesno "\nExit the Quai Hardware Manager?\n \n\Z1This will stop your node and miner.\Zn" 0 0
response=$?
EXIT="False"
case $response in
0) EXIT="True";;
1) EXIT="False";;
255) EXIT="False";;
esac
if [ $EXIT = "True" ]; then
#If user chooses stop, kill node
cd $HOME/$MAIN_DIR/quai-cpu-miner
make stop>/dev/null 2>&1
cd $HOME/$MAIN_DIR/go-quai
make stop>/dev/null 2>&1 | \
dialog --title "Stop" \
--colors \
--no-collapse \
--infobox "\nStopping Node and/or Miner.\n \nPlease wait." 0 0
clear
echo "Quai Hardware Manager stopped."
exit
fi
;;
$DIALOG_ESC)
# Verify the user wants to stop their node and miner
dialog --colors --title "Alert" --yesno "\nExit the Quai Hardware Manager?\n \n\Z1This will stop your node and miner.\Zn" 0 0
response=$?
EXIT="False"
case $response in
0) EXIT="True";;
1) EXIT="False";;
255) EXIT="False";;
esac
if [ $EXIT = "True" ]; then
#If user chooses stop, kill node
cd $HOME/$MAIN_DIR/quai-cpu-miner
make stop>/dev/null 2>&1
cd $HOME/$MAIN_DIR/go-quai
make stop>/dev/null 2>&1 | \
dialog --title "Stop" \
--colors \
--no-collapse \
--infobox "\nStopping Node and/or Miner. Please wait." 0 0
clear
echo "Quai Hardware Manager stopped."
exit
fi
;;
esac
case $selection in
1 )
#If node is running, redirect back to menu
if [ $ISRUNNING = "True" ]; then
dialog --title "Alert" \
--no-collapse \
--msgbox "\nNode is already running." 0 0
else
# Start go-quai
cd $HOME/$MAIN_DIR/go-quai && make run-all>/dev/null 2>&1 | \
dialog --title "Node" \
--no-collapse \
--infobox "\nStarting Node. Please wait." 0 0
# Ask the user if they would like to view nodelogs
dialog --title "Alert" \
--no-collapse \
--yesno "\nNode started. Would you like to view the last 40 lines of your nodelogs?" 0 0
response=$?
case $response in
0)
#Print nodelogs
cd
LOCATION=$(dialog --nocancel --menu "In which location would you like to view nodelogs?" 0 0 13 \
1 "Prime" \
2 "Cyprus" \
3 "Paxos" \
4 "Hydra" \
5 "Cyprus-1" \
6 "Cyprus-2" \
7 "Cyprus-3" \
8 "Paxos-1" \
9 "Paxos-2" \
10 "Paxos-3" \
11 "Hydra-1" \
12 "Hydra-2" \
13 "Hydra-3" 3>&1 1>&2 2>&3 3>&- )
case $LOCATION in
1)
FILE="$MAIN_DIR/go-quai/nodelogs/prime.log"
;;
2)
FILE="$MAIN_DIR/go-quai/nodelogs/region-0.log"
;;
3)
FILE="$MAIN_DIR/go-quai/nodelogs/region-1.log"
;;
4)
FILE="$MAIN_DIR/go-quai/nodelogs/region-2.log"
;;
5)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-0-0.log"
;;
6)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-0-1.log"
;;
7)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-0-2.log"
;;
8)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-1-0.log"
;;
9)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-1-1.log"
;;
10)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-1-2.log"
;;
11)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-2-0.log"
;;
12)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-2-1.log"
;;
13)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-2-2.log"
;;
esac
result=`tail -40 $FILE`
dialog --cr-wrap --title "$FILE" --no-collapse --msgbox "\n$result" 30 90
;;
1) clear;;
255) clear;;
esac
fi
;;
2 )
#If miner is running, redirect back to menu
if [ $ISMINING = "True" ]; then
dialog --title "Alert" \
--no-collapse \
--msgbox "\nMiner is already running." 0 0
elif [ $ISRUNNING = "False" ]; then
dialog --title "Alert" \
--no-collapse \
--msgbox "\nPlease start your Node before starting the Miner." 0 0
else
REGION=$(dialog --nocancel --menu "Which regiond would you like to mine?" 0 0 3 \
1 "Cyprus" \
2 "Paxos" \
3 "Hydra" 3>&1 1>&2 2>&3 3>&- )
ZONE=$(dialog --nocancel --menu "Which region would you like to mine?" 0 0 3 \
1 "Zone-0" \
2 "Zone-1" \
3 "Zone-2" 3>&1 1>&2 2>&3 3>&- )
# Start go-quai
REGION=$(($REGION-1))
ZONE=$(($ZONE-1))
cd $HOME/$MAIN_DIR/quai-cpu-miner && make run-mine-background region=$REGION zone=$ZONE
dialog --title "Alert" \
--no-collapse \
--msgbox "Miner started in: \nRegion: $REGION \nZone: $ZONE" 0 0
# Ask the user if they would like to view nodelogs
dialog --title "Alert" \
--no-collapse \
--yesno "\nMiner started. Would you like to view the last 40 lines of your miner logs?" 0 0
response=$?
case $response in
0)
# Print nodelogs
cd
result=`tail -40 $MAIN_DIR/quai-cpu-miner/logs/slice-$REGION-$ZONE.log`
dialog --cr-wrap --title "$MAIN_DIR/quai-manger/logs/slice-$REGION-$ZONE.log" --msgbox "\n$result" 30 90
;;
1) clear;;
255) clear;;
esac
fi
;;
3 )
# Verify the user wants to stop their node and miner
dialog --title "Alert" --yesno "\nAre you sure you want to stop the Node and/or Miner?" 0 0
response=$?
STOP="False"
case $response in
0) STOP="True";;
1) STOP="False";;
255) STOP="False";;
esac
if [ $STOP = "True" ]; then
#If user chooses stop, kill node
cd $HOME/$MAIN_DIR/quai-cpu-miner
make stop>/dev/null 2>&1
cd $HOME/$MAIN_DIR/go-quai
make stop>/dev/null 2>&1 | \
dialog --title "Stop" \
--no-collapse \
--infobox "\nStopping Node and/or Miner. Please wait." 0 0
dialog --title "Stop" \
--no-cancel \
--msgbox "\nNode and/or Miner stopped. Press OK to return to the menu." 0 0
fi
;;
4 )
if [ $ISMINING = "True" ]; then
dialog --title "Alert" \
--no-collapse \
--msgbox "\nPlease stop your node and miner to update." 0 0
elif [ $ISRUNNING = "True" ]; then
dialog --title "Alert" \
--no-collapse \
--msgbox "\nPlease stop your node and miner to update." 0 0
else
# Update go-quai
cd $HOME/$MAIN_DIR/go-quai
git pull>/dev/null 2>&1 | \
dialog --title "Update" \
--no-collapse \
--infobox "\nUpdating Node. Please wait." 7 28
make go-quai>/dev/null 2>&1 | \
dialog --title "Update" \
--no-collapse \
--infobox "\nUpdating Node. Please wait." 7 28
dialog --title "Update" \
--no-collapse \
--msgbox "\nNode updated. Press OK to continue." 7 28
# Update quai-cpu-miner
cd $HOME/$MAIN_DIR/quai-cpu-miner
git pull>/dev/null 2>&1 | \
dialog --title "Update" \
--no-collapse \
--infobox "\nUpdating Miner. Please wait." 7 28
make quai-cpu-miner>/dev/null 2>&1 | \
dialog --title "Update" \
--no-collapse \
--infobox "\nUpdating Miner. Please wait." 7 28
dialog --title "Update" \
--no-collapse \
--msgbox "\nMiner updated. Press OK to return to the menu." 0 0
fi
;;
5 )
if [ $NODELOGS = "False" ]; then
dialog --title "Alert" \
--no-collapse \
--msgbox "\nPlease start your node before viewing nodelogs." 0 0
else
#Print nodelogs
cd $HOME
LOCATION=$(dialog --nocancel --menu "In which location would you like to view nodelogs?" 0 0 13 \
1 "Prime" \
2 "Cyprus" \
3 "Paxos" \
4 "Hydra" \
5 "Cyprus-1" \
6 "Cyprus-2" \
7 "Cyprus-3" \
8 "Paxos-1" \
9 "Paxos-2" \
10 "Paxos-3" \
11 "Hydra-1" \
12 "Hydra-2" \
13 "Hydra-3" 3>&1 1>&2 2>&3 3>&- )
case $LOCATION in
1)
FILE="$MAIN_DIR/go-quai/nodelogs/prime.log"
;;
2)
FILE="$MAIN_DIR/go-quai/nodelogs/region-0.log"
;;
3)
FILE="$MAIN_DIR/go-quai/nodelogs/region-1.log"
;;
4)
FILE="$MAIN_DIR/go-quai/nodelogs/region-2.log"
;;
5)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-0-0.log"
;;
6)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-0-1.log"
;;
7)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-0-2.log"
;;
8)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-1-0.log"
;;
9)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-1-1.log"
;;
10)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-1-2.log"
;;
11)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-2-0.log"
;;
12)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-2-1.log"
;;
13)
FILE="$MAIN_DIR/go-quai/nodelogs/zone-2-2.log"
;;
esac
result=`tail -40 $FILE`
dialog --cr-wrap --title "$FILE" --msgbox "\n$result" 0 0
fi
;;
6 )
if [ $MININGLOGS = "False" ]; then
dialog --title "Alert" \
--no-collapse \
--msgbox "\nPlease start your miner before viewing logs." 0 0
else
# Print Miner Logs
REGION=$(dialog --nocancel --menu "Which region would you like to view logs for?" 0 0 3 \
1 "Cyprus" \
2 "Paxos" \
3 "Hydra" 3>&1 1>&2 2>&3 3>&- )
ZONE=$(dialog --nocancel --menu "Which region would you like to view logs for?" 0 0 3 \
1 "Zone-1" \
2 "Zone-2" \
3 "Zone-3" 3>&1 1>&2 2>&3 3>&- )
# Start miner
REGION=$(($REGION-1))
ZONE=$(($ZONE-1))
cd
result=`tail -40 quainetwork/quai-cpu-miner/logs/slice-$REGION-$ZONE.log`
dialog --cr-wrap --title "quainetwork/quai-cpu-miner/logs/slice-$REGION-$ZONE.log" --msgbox "\n$result" 30 90
fi
;;
esac
done