-
Notifications
You must be signed in to change notification settings - Fork 2
/
smartcoin_control.sh
1812 lines (1468 loc) · 47.2 KB
/
smartcoin_control.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
# smartcoin_control.sh
# This script handles all of the user configurable options and menu system of smartcoin.
# Only one instance of this control script runs on the local machine, it uses and stores database information
# which lets smartcoin interact with multiple machines.
# This script only handles database interaction, and doesn't launch or kill any other processes directly.
if [[ $( dirname "$0" ) == "/usr/bin" ]]; then
CUR_LOCATION=$(dirname $(readlink -f $( dirname "$0" )/smartcoin))
else
CUR_LOCATION="$( cd "$( dirname "$0" )" && pwd )"
fi
. $CUR_LOCATION/smartcoin_ops.sh
# Update system
Do_Update()
{
clear
ShowHeader
echo "Getting svn information. Please be patient..."
local svn_rev=$(GetRevision)
local svn_repo=$(GetRepo)
local svn_exp=$(GetHead "$svn_repo")
local svn_stb=$(GetStableHead "$svn_repo")
E="Your current version is r$svn_rev$G_BRANCH_ABBV.\n"
E=$E"The current experimental version is r$svn_exp""e\n"
E=$E"The current stable version is r$svn_stb""s\n"
E=$E"Are you sure that you wish to perform an update?"
GetYesNoSelection doInstall "$E"
if [[ "$doInstall" == "0" ]]; then
return
fi
# First, lets update only the update script!
echo ""
echo "Bring update script up to current..."
svn update $CUR_LOCATION/smartcoin_update.sh >/dev/null 2>&1
echo ""
Q="SELECT value FROM settings WHERE data='dev_branch';"
R=$(RunSQL "$Q")
local branch=$(Field 1 "$R")
if [[ "$branch" == "stable" ]]; then
$CUR_LOCATION/smartcoin_update.sh
elif [[ "$branch" == "experimental" ]]; then
$CUR_LOCATION/smartcoin_update.sh 1
else
echo ""
echo "Error! Specified branch must be either \"experimental\" or \"stable\"."
sleep 5
fi
# Lets update the master revision variable
export REVISION=$(GetRevision)
}
# Failover Order Menu
Do_SetFailoverOrder()
{
local thisMachine
clear
ShowHeader
echo "CHANGE FAILOVER ORDER"
echo "---------------------"
Q="SELECT COUNT(*) FROM profile;"
R=$(RunSQL "$Q")
local count=$(Field 1 "$R")
if [[ "$count" -le "1" ]]; then
E="You need at least 2 manual profiles set up to use the failover system. "
E=$E"Please set up some profiles, then come back here to set a specific failover order."
echo "$E"
sleep 5
return
fi
local thisProfile
local usedProfiles=""
local i=0
Q="SELECT pk_machine, name from machine;"
E="Please select the machine from the list above that you wish to edit Failover order on"
GetPrimaryKeySelection thisMachine "$Q" "$E"
echo ""
echo "Current failover order:"
echo "-----------------------"
Q="SELECT pk_profile, name FROM profile WHERE fk_machine='$thisMachine' AND failover_order>'0' ORDER BY failover_order;"
R=$(RunSQL "$Q")
for row in $R; do
local thisProfile=$(Field 1 "$row")
local thisProfileName=$(Field 2 "$row")
echo "$thisProfile) $thisProfileName"
done
if [[ -z "$R" ]]; then
echo "<<<Failover order not yet set!>>>"
fi
echo "-----------------------"
echo ""
echo "The current profile failover order is listed above."
echo ""
E="Do you want to change the failover order, (y)es or (n)o?"
GetYesNoSelection changeOrder "$E"
echo ""
if [[ "$changeOrder" == "1" ]]; then
# Mark all profiles to not be included into the failover system
Q="UPDATE profile SET failover_order='-1' WHERE fk_machine='$thisMachine';"
RunSQL "$Q"
Q="SELECT pk_profile, name FROM profile WHERE fk_machine='$thisMachine' ORDER BY pk_profile;"
R=$(RunSQL "$Q")
for row in $R; do
local thisProfile=$(Field 1 "$row")
local thisProfileName=$(Field 2 "$row")
echo "$thisProfile) $thisProfileName"
done
echo ""
echo "Enter a comma-separated list of the ID numbers above to define the failover order. I.e. 1,5,2,3"
echo "Note: leave out ID numbers to exclude them from the failover system"
read profileOrder
echo "Updating the Failover order..."
# Filter out spaces
profileOrder=${profileOrder//" "/""}
# then convert to a list that can be iterated with for
profileOrder=${profileOrder//","/" "}
for thisProfile in $profileOrder; do
let i++
Q="UPDATE profile SET failover_order='$i' WHERE pk_profile='$thisProfile';"
RunSQL "$Q"
done
echo "done."
sleep 1
fi
}
# Profile Menu
Do_ChangeProfile() {
local autoEntry
clear
ShowHeader
# Add the flags for the dynamically generated profiles
autoEntry=$(FieldArrayAdd "-2 1 Donation")
autoEntry=$autoEntry$(FieldArrayAdd "-1 2 Automatic")
autoEntry=$autoEntry$(FieldArrayAdd "-3 3 Failover")
autoEntry=$autoEntry$(FieldArrayAdd "-4 4 Idle")
# Display menu
Q="SELECT pk_machine,name from machine"
E="Select the machine from the list above that you wish to change the profile on"
GetPrimaryKeySelection thisMachine "$Q" "$E"
Q="SELECT pk_profile, name FROM profile where fk_machine=$thisMachine AND pk_profile>0 ORDER BY pk_profile ASC;"
E="Select the profile from the list above that you wish to switch to"
GetPrimaryKeySelection thisProfile "$Q" "$E" "" "$autoEntry"
SetCurrentProfile "$thisMachine" "$thisProfile"
# Lets see if we can automatically go to the status screen
Q="SELECT name FROM machine WHERE pk_machine=$thisMachine;"
R=$(RunSQL "$Q")
machineName=$(Field 1 "$R")
screen -r $sessionName -X screen -p 1
}
Do_Settings() {
local autoEntry
local thisMachine
clear
ShowHeader
echo "EDIT SETTINGS"
echo "-------------"
echo ""
Q=""
E="Which settings would you like to edit?"
autoEntry=$(FieldArrayAdd "1 1 General Settings")
autoEntry=$autoEntry$(FieldArrayAdd "2 2 Machine Settings")
GetPrimaryKeySelection settingsType "$Q" "$E" "" "$autoEntry"
echo ""
if [[ "$settingsType" == "2" ]]; then
Q="SELECT pk_machine,name from machine"
E="Select the machine from the list above that you wish to edit settings on"
GetPrimaryKeySelection thisMachine "$Q" "$E"
else
thisMachine=0
fi
echo ""
clear
ShowHeader
if [[ "$thisMachine" == "0" ]]; then
echo "EDIT GENERAL SETTINGS"
echo "---------------------"
else
echo "EDIT MACHINE #$thisMachine SETTINGS"
echo "----------------------"
fi
Q="SELECT pk_settings, description FROM settings WHERE fk_machine='$thisMachine' AND description !='' ORDER BY display_order;"
E="Select the setting from the list above that you wish to edit"
GetPrimaryKeySelection thisSetting "$Q" "$E"
echo " "
clear
ShowHeader
echo "EDIT SETTING"
echo "------------"
echo ""
Q="SELECT information FROM settings WHERE pk_settings='$thisSetting';"
R=$(RunSQL "$Q")
local information=$(Field 1 "$R")
echo "Here is some general information about this setting:"
echo "--------------------"
echo -ne "$information\n"
echo "--------------------"
echo ""
Q="SELECT value, description FROM settings WHERE pk_settings=$thisSetting;"
R=$(RunSQL "$Q")
settingValue=$(Field 1 "$R")
settingDescription=$(Field 2 "$R")
echo "New $settingDescription"
read -e -i "$settingValue" newSetting
echo "Updating Setting..."
Q="UPDATE settings SET value='$newSetting' WHERE pk_settings=$thisSetting;"
RunSQL "$Q"
sleep 1
echo "done."
Reload $thisMachine "Settings have been changed. Reloading miners."
}
# Configure Machines Menu
Do_Machines() {
clear
ShowHeader
#Add/Edit/Delete?
AddEditDelete "machines"
action=$(GetAEDSelection)
case "$action" in
ADD)
Add_Machines
;;
DELETE)
Delete_Machines
;;
EDIT)
Edit_Machines
;;
EXIT)
return
;;
*)
DisplayError "Invalid selection!" "5"
;;
esac
}
GenKeysAndCopy() {
local machinePort=$1
local machineUser=$2
local machineServer=$3
# Step 1: Generate the keys if needed!
if [[ ! -f ~/.ssh/id_rsa.smartcoin ]]; then
Log "SSH keys have not been generated yet" 1
echo "Generating..."
ssh-keygen -q -N "" -f ~/.ssh/id_rsa.smartcoin -C "Smartcoin RSA key"
echo "Done."
fi
# If we can copy the key over to the remote machine, then success!
#ssh $machineUser@$machineServer -p $machinePort uname -r 2> /dev/null
ssh-copy-id -i ~/.ssh/id_rsa.smartcoin.pub "-q -p $machinePort $machineUser@$machineServer"
return $?
}
Add_Machines() {
clear
ShowHeader
echo "ADDING MACHINE"
echo "--------------"
echo ""
echo "Give this machine a nickname"
read machineName
echo ""
echo "Enter this machines server address"
read machineServer
echo ""
echo "Enter this machines server port"
read -e -i "22" machinePort
echo ""
echo "Enter the username to use with this machine"
read machineUser
echo ""
# Now its time to determine whether or not the remote machine is online.
# We can only add it to teh database if it is online - as we have to generate some RSA keys!
echo "In order to continue, we need to attempt to connect to this remote machine."
echo "If we can successfully connect, we will generate RSA keys for secure communication."
echo "Press any key to attempt to connect to the remote machine. You will need to enter the password for the remote machine when prompted!"
read
echo
GenKeysAndCopy "$machinePort" "$machineUser" "$machineServer"
if [[ $? -ne 0 ]]; then
echo "Aborting!"
echo "We were unable to connect to the remote server. This most likely means that the server is either offline, or information was entered incorrectly."
echo "Please try again, and make sure that the server is online, and that information entered is correct."
echo "(Any key to continue)"
read
else
echo "Connection successful!"
echo ""
E="Would you like to disable this machine? (y)es or (n)o?"
GetYesNoSelection machineDisabled "$E" "n"
echo ""
# Add the machine to the database!
echo "Updating Machines..."
Q="INSERT INTO machine (name,server,ssh_port,username,disabled) VALUES ('$machineName','$machineServer','$machinePort','$machineUser','$machineDisabled');"
RunSQL "$Q"
sleep 1
echo "done."
# TODO: Auto-detection on remote machine!
Q="SELECT pk_machine FROM machine ORDER BY pk_machine DESC LIMIT 1;"
R=$(RunSQL "$Q")
local insertedMachine=$(Field 1 "$R")
MachineSettings "$insertedMachine"
MachineDefaults "$insertedMachine"
AutoDetect "$insertedMachine"
fi
return
}
Edit_Machines() {
# TODO: Use this function as a model for local variable scope and return values. Need to someday clean up all other functions to be as tidy.
local connectionInformationChanged
clear
ShowHeader
echo "EDITING MACHINE"
echo "---------------"
echo ""
local thisMachine
Q="SELECT pk_machine,name FROM machine WHERE pk_machine<>'1';"
E="Select the machine from the list above that you wish to edit"
GetPrimaryKeySelection thisMachine "$Q" "$E"
echo ""
Q="SELECT name,username,server,ssh_port,disabled FROM machine WHERE pk_machine='$thisMachine'";
R=$(RunSQL "$Q")
local cname=$(Field 1 "$R")
local cusername=$(Field 2 "$R")
local cserver=$(Field 3 "$R")
local cssh_port=$(Field 4 "$R")
local cdisabled=$(Field 5 "$R")
local machineName
echo "Enter a nickname for this machine:"
read -e -i "$cname" machineName
echo ""
local machineUsername
echo "Enter the username for this machine:"
read -e -i "$cusername" machineUsername
echo ""
if [[ "$machineUsername" != "$cusername" ]]; then
connectionInformationChanged="1"
fi
local machineServer
echo "Enter the server host address for this machine:"
read -e -i "$cserver" machineServer
echo ""
if [[ "$machineServer" != "$cserver" ]]; then
connectionInformationChanged="1"
fi
local machinePort
echo "Enter the ssh port for this machine:"
read -e -i "$cssh_port" machinePort
echo ""
local machineDisabled
E="Would you like to disable this machine?"
GetYesNoSelection machineDisabled "$E" "$cdisabled"
echo ""
if [[ "$connectionInformationChanged" == "1" ]]; then
Log "Connection information has changed. Trying to establish a new connection." 1
GenKeysAndCopy "$machinePort" "$machineUsername" "$machineServer"
if [[ $? -ne 0 ]]; then
echo ""
Log "New connection was not successful." 1
echo "Please try again and make sure you have entered the correct connection information."
echo "Changes will not be written to the database."
echo "(Any key to continue)"
read
return 1
else
Log "New connection successful!" 1
fi
fi
echo ""
echo "Updating machine..."
Q="UPDATE machine SET name='$machineName', username='$machineUsername', server='$machineServer', ssh_port='$machinePort', disabled='$machineDisabled' WHERE pk_machine='$thisMachine';"
RunSQL "$Q"
echo "done."
sleep 1
Reload $thisMachine "Machines have changed. Reloading miners."
return 0
}
Delete_Machines() {
clear
ShowHeader
echo "SELECT MACHINE TO DELETE"
Q="SELECT COUNT(*) FROM machine;"
R=$(RunSQL "$Q")
local numMachines=$(Field 1 "$R")
if [[ "$numMachines" -le "1" ]]; then
echo "You have no extra machines to delete, and you cannot delete the localhost machine."
echo "Press any key to return to the control screen."
read
return
fi
Q="SELECT pk_machine,name FROM machine WHERE pk_machine<>'1';"
E="Select the machine from the list above that you wish to delete"
GetPrimaryKeySelection thisMachine "$Q" "$E"
echo "Deleting Machine..."
local tables="settings current_profile miner device macro_map profile"
local thisTable
for thisTable in $tables; do
Q="DELETE FROM $thisTable WHERE fk_machine='$thisMachine';"
RunSQL "$Q"
done
# Delete the actual machine entry
Q="DELETE FROM machine WHERE pk_machine='$thisMachine';"
RunSQL "$Q"
echo "done."
sleep 1
}
# Configure Miners Menu
Do_Miners() {
clear
ShowHeader
#Add/Edit/Delete?
AddEditDelete "miners"
action=$(GetAEDSelection)
case "$action" in
ADD)
Add_Miners
;;
DELETE)
Delete_Miners
;;
EDIT)
Edit_Miners
;;
EXIT)
return
;;
*)
DisplayError "Invalid selection!" "5"
;;
esac
}
Add_Miners()
{
#table:miner fields:pk_miner, name, launch, path
clear
ShowHeader
echo "ADDING MINER"
echo "------------"
Q="SELECT pk_machine, name from machine;"
E="Please select the machine from the list above that is hosting this miner"
GetPrimaryKeySelection thisMachine "$Q" "$E"
echo "Give this miner a nickname"
read minerName
echo "Enter the miner's path (i.e. /home/you/miner/)"
read minerPath
echo "Enter the miner's launch string"
echo "Note:use special strings <#user#>, <#path#>, <#server#>"
echo "<#port#>, and <#device#>"
echo "i.e. phoenix.py -v -u http://<#user#>:<#pass#>@<#server#>:<#port#>/ -k phatk device=<#device#> worksize=256 vectors aggression=11 bfi_int fastloop=false"
read minerLaunch
E="Do you want this to be the the default miner for this machine?"
GetYesNoSelection defaultMiner "$E"
echo "Adding Miner..."
Q="INSERT INTO miner (name,launch,path,fk_machine) VALUES ('$minerName','$minerLaunch','$minerPath','$thisMachine');"
RunSQL "$Q"
Q="SELECT pk_miner FROM miner ORDER BY pk_miner DESC LIMIT 1;"
R=$(RunSQL "$Q")
insertedID=$(Field 1 "$R")
if [[ "$defaultMiner" = "1" ]]; then
SetDefaultMiner "$thisMachine" "$insertedID"
fi
echo "done."
Reload $thisMachine "Miners have been changed. Reloading miners."
sleep 1
}
Edit_Miners()
{
clear
ShowHeader
echo "SELECT MINER TO EDIT"
Q="SELECT pk_machine,name FROM machine;"
E="Select the machine the miner resides on"
GetPrimaryKeySelection thisMachine "$Q" "$E"
empty=$(tableIsEmpty "miner" "WHERE fk_machine=$thisMachine")
if [[ "$empty" ]]; then
echo ""
echo "There are no miners to edit."
sleep 3
return
fi
Q="SELECT pk_miner, name FROM miner WHERE fk_machine=$thisMachine;"
E="Select the miner you wish to edit"
GetPrimaryKeySelection thisMiner "$Q" "$E"
Q="SELECT name, launch, path, fk_machine, default_miner FROM miner WHERE pk_miner=$thisMiner;"
R=$(RunSQL "$Q")
cname=$(Field 1 "$R")
claunch=$(Field 2 "$R")
cpath=$(Field 3 "$R")
cmachine=$(Field 4 "$R")
cdefault=$(Field 5 "$R")
if [[ "$cdefault" == "1" ]]; then
cdefault="y"
else
cdefault="n"
fi
clear
ShowHeader
echo "EDITING MINER"
echo "------------"
Q="SELECT pk_machine, name from machine;"
E="Please select the machine from the list above that is hosting this
miner"
GetPrimaryKeySelection thisMachine "$Q" "$E" "$cmachine"
echo "Please give this miner a nickname"
read -e -i "$cname" minerName
echo "Enter the miner's path (i.e. /home/you/miner/)"
read -e -i "$cpath" minerPath
echo "Enter the miner's launch string"
echo "Note:use special strings <#user#>, <#path#>, <#server#>"
echo "<#port#>, and <#device#>"
read -e -i "$claunch" minerLaunch
E="Do you want this to be the the default miner for this machine?"
GetYesNoSelection defaultMiner "$E" "$cdefault"
echo "Updating Miner..."
Q="UPDATE miner SET name='$minerName', launch='$minerLaunch', path='$minerPath', fk_machine=$thisMachine WHERE pk_miner=$thisMiner"
RunSQL "$Q"
if [[ "$defaultMiner" = "1" ]]; then
SetDefaultMiner "$thisMachine" "$thisMiner"
fi
echo "done."
sleep 1
Reload $thisMachine "Miners have been changed. Reloading miners."
}
Delete_Miners()
{
#TODO: deal with situation where we delete the default miner - a new one needs set!
clear
ShowHeader
echo "SELECT MINER TO DELETE"
Q="SELECT pk_machine,name FROM machine;"
E="Select the machine from the list above that the miner resides on"
GetPrimaryKeySelection thisMachine "$Q" "$E"
empty=$(tableIsEmpty "miner" "WHERE fk_machine=$thisMachine")
if [[ "$empty" ]]; then
echo ""
echo "There are no miners to delete."
sleep 3
return
fi
Q="SELECT pk_miner,name FROM miner WHERE fk_machine=$thisMachine;"
E="Please select the miner from the list above to delete"
GetPrimaryKeySelection thisMiner "$Q" "$E"
echo "Deleting Miner..."
Q="DELETE FROM profile_map WHERE fk_miner=$thisMiner;"
RunSQL "$Q"
Q="DELETE FROM miner WHERE pk_miner=$thisMiner"
RunSQL "$Q"
echo "done."
sleep 1
Reload $thisMachine "Miners have been changed. Reloading miners."
}
# Configure Pools Menu
Do_Pools() {
clear
ShowHeader
#Add/Edit/Delete?
AddEditDelete "pools"
action=$(GetAEDSelection)
case "$action" in
ADD)
Add_Pool
;;
DELETE)
Delete_Pool
;;
EDIT)
Edit_Pool
;;
EXIT)
return
;;
*)
DisplayError "Invalid selection!" "5"
;;
esac
# Reload all miners
Reload "0" "Pool information has been changed. Reloading miners."
}
Add_Pool()
{
clear
ShowHeader
echo "ADDING POOL"
echo "-----------"
echo "Give this pool a nickname"
read poolName
echo ""
echo "Enter the main server address for this pool"
read poolServer
echo ""
echo "Enter an optional alternate server address for this pool"
read poolAlternate
echo ""
echo "Enter the port number to connect to this pool"
read poolPort
echo ""
echo "Enter a disconnection timeout for this pool"
read poolTimeout
echo ""
# TODO: auto_allow and disabled aren't used yet (if ever?)
# fix hard coding once a decision is made
Q="INSERT INTO pool (name,server,alternate_server,port,timeout,auto_allow,disabled) VALUES ('$poolName','$poolServer','$poolAlternate','$poolPort','$poolTimeout',1,0);"
RunSQL "$Q"
echo "done."
sleep 1
}
Edit_Pool()
{
clear
ShowHeader
empty=$(tableIsEmpty "pool")
if [[ "$empty" ]]; then
echo ""
echo "There are no pools to edit."
sleep 3
return
fi
echo "SELECT POOL TO EDIT"
Q="SELECT pk_pool, name FROM pool;"
E="Please select the pool from the list above to edit"
GetPrimaryKeySelection thisPool "$Q" "$E"
Q="SELECT name,server,alternate_server,port,timeout FROM pool WHERE pk_pool=$thisPool;"
R=$(RunSQL "$Q")
cname=$(Field 1 "$R")
cserver=$(Field 2 "$R")
calternate=$(Field 3 "$R")
cport=$(Field 4 "$R")
ctimeout=$(Field 5 "$R")
clear
ShowHeader
echo "EDITING POOL"
echo "------------"
echo "Give this pool a nickname"
read -e -i "$cname" poolName
echo ""
echo "Enter the main server address for this pool"
read -e -i "$cserver" poolServer
echo ""
echo "Enter an optional alternate server address for this pool"
read -e -i "$calternate" poolAlternate
echo ""
echo "Enter the port number to connect to this pool"
read -e -i "$cport" poolPort
echo ""
echo "Enter a disconnection timeout for this pool"
read -e -i "$ctimeout" poolTimeout
echo ""
echo "Updating Pool..."
Q="UPDATE pool SET name='$poolName', server='$poolServer', alternate_server='$poolAlternate', port='$poolPort', timeout='$poolTimeout' WHERE pk_pool=$thisPool"
RunSQL "$Q"
echo "done."
sleep 1
}
Delete_Pool()
{
clear
ShowHeader
empty=$(tableIsEmpty "pool")
if [[ "$empty" ]]; then
echo ""
echo "There are no pools to delete."
sleep 3
return
fi
echo "SELECT POOL TO DELETE"
Q="SELECT pk_pool,name from pool;"
E="Please select the pool from the list above to delete"
GetPrimaryKeySelection thisPool "$Q" "$E"
echo "Deleting pool..."
# Get a list of the workers that reference the pool...
Q="SELECT * FROM worker WHERE fk_pool=$thisPool;"
R=$(RunSQL "$Q")
for row in $R; do
thisWorker=$(Field 1 "$row")
# We have to delete all workers that refer to this pool!
# And delete the profile_map entries that refer to those workers
Q="DELETE FROM profile_map WHERE fk_worker=$thisWorker;"
RunSQL "$Q"
done
Q="DELETE FROM worker WHERE fk_pool=$thisPool;"
RunSQL "$Q"
# And finally, delete the pool!
Q="DELETE FROM pool WHERE pk_pool=$thisPool;"
RunSQL "$Q"
echo "done."
sleep 1
}
# Configure Workers Menu
Do_Workers() {
clear
ShowHeader
#Add/Edit/Delete?
AddEditDelete "workers"
action=$(GetAEDSelection)
case "$action" in
ADD)
Add_Workers
;;
DELETE)
Delete_Workers
;;
EDIT)
Edit_Workers
;;
EXIT)
return
;;
*)
DisplayError "Invalid selection!" "5"
;;
esac
# Reload all miners
Reload 0 "Worker information has been changed. Reloading miners."
}
Add_Workers()
{
#table:miner fields:pk_miner, name, launch, path
clear
ShowHeader
echo "ADDING WORKER"
echo "-------------"
Q="SELECT pk_pool, name FROM pool;"
E="What pool listed above is this worker associated with?"
GetPrimaryKeySelection thisPool "$Q" "$E"
echo " "
echo "Give this worker a nickname"
read -e -i "default" workerName
echo " "
echo "Enter the username for this worker"
read userName
echo " "
echo "Enter the password for this worker"
read password
echo " "
E="Would you like this worker to be available to the automatic profile? (y)es or (n)o?"
GetYesNoSelection workerAllow "$E" 1
echo "Adding Worker..."
Q="INSERT INTO worker (fk_pool, name, user, pass, auto_allow, disabled) VALUES ('$thisPool','$workerName','$userName','$password','$workerAllow','0');"
R=$(RunSQL "$Q")
echo "done."
sleep 1
}
Edit_Workers()
{
clear
ShowHeader
empty=$(tableIsEmpty "worker")
if [[ "$empty" ]]; then
echo ""
echo "There are no workers to edit."
sleep 3
return
fi
echo "SELECT WORKER TO EDIT"
Q="SELECT pk_worker, pool.name || '.' || worker.name as fullName FROM worker LEFT JOIN pool ON worker.fk_pool = pool.pk_pool;"
E="Please select the worker from the list above to edit"
GetPrimaryKeySelection EditPK "$Q" "$E"
Q="SELECT fk_pool,name,user,pass,auto_allow FROM worker WHERE pk_worker=$EditPK;"
R=$(RunSQL "$Q")
cpool=$(Field 1 "$R")
cname=$(Field 2 "$R")
cuser=$(Field 3 "$R")
cpass=$(Field 4 "$R")
callow=$(Field 5 "$R")
clear
ShowHeader
echo "EDITING WORKER"
echo "------------"
Q="SELECT pk_pool,name FROM pool;"
E="Which pool does this worker belong to?"
GetPrimaryKeySelection workerPool "$Q" "$E" "$cpool"
echo ""
echo "Give this worker a nickname"
read -e -i "$cname" workerName
echo ""
echo "Enter the user name for this worker"
read -e -i "$cuser" workerUser
echo ""
echo "Enter the password for this worker"
read -e -i "$cpass" workerPass
echo ""
E="Do you want to allow this worker to be added to the automatic profile?"
GetYesNoSelection workerAllow "$E" "$callow"
echo "Updating Worker..."
Q="UPDATE worker SET fk_pool='$workerPool', name='$workerName', user='$workerUser', pass='$workerPass', auto_allow='$workerAllow' WHERE pk_worker=$EditPK"
RunSQL "$Q"
echo "done"
sleep 1
}
Delete_Workers()
{
clear
ShowHeader
empty=$(tableIsEmpty "worker")
if [[ "$empty" ]]; then
echo ""
echo "There are no workers to delete."
sleep 3
return
fi
echo "SELECT WORKER TO DELETE"
Q="SELECT pk_worker, pool.name || '.' || worker.name AS fullName FROM worker LEFT JOIN pool ON worker.fk_pool = pool.pk_pool;"
E="Please select the worker from the list above to delete"
GetPrimaryKeySelection thisWorker "$Q" "$E"