-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdynStartupScript.sh
More file actions
1575 lines (1365 loc) · 73.6 KB
/
dynStartupScript.sh
File metadata and controls
1575 lines (1365 loc) · 73.6 KB
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/sh
# Summary:
# This script is a one stop installing and maintenance script for Dynamic.
# It is used to startup a new VPS. It will download, compile, and maintain the wallet.
# myScrapeAddress: This is the address that the wallet will scrape mining coins to:
# "IF YOU DON'T USE ATTRIBUTES TO PASS IN YOUR VALUES THEN:"
# "CHANGE THE ADDRESS BELOW TO BE THE ONE FOR YOUR WALLET"
myScrapeAddress=D9T2NVLGZEFSw3yc6ye4BenfK7n356wudR
# "CHANGE THE ADDRESS ABOVE TO BE THE ONE FOR YOUR WALLET"
# "CHANGE THE ADDRESS ABOVE TO BE THE ONE FOR YOUR WALLET"
# Credit:
# Written by those who are dedicated to teaching other about ion (ionomy.com) and other cryptocurrencies.
# Contributors: DYN Donation Address BTC Address
# LordDarkHelmet D9T2NVLGZEFSw3yc6ye4BenfK7n356wudR 1NZya3HizUdeJ1CNbmeJEW3tHkXUG6PoNn
# Broyhill
# Coinkiller
# razerrazer
# Your name here, help add value by contributing. Contact LordDarkHelmet on Github!
# Version:
varVersionNumber="2.5.0.0.a"
varVersionDate="August 12, 2021"
varVersion="${varVersionNumber} dynStartupScript.sh ${varVersionDate} Released by LordDarkHelmet"
# The script was tested using on Vultr. Ubuntu 20.04 x64, 1 CPU, 1024 MB ram, 25 GB SSD, 1000 GB bandwidth
# We recommend running Ubuntu 20.04. This is the LTS or Long Term Support version. This OS version is supported in the long run. The next LTS version will be 22.04
# LordDarkHelmet's affiliate link: http://www.vultr.com/?ref=6923885
#
# If you are using Vultr as a VPN service and you run this in as your startup script, then you should see the results in /tmp/firstboot.log
# The script will take some time to run. You can view progress when you first log in by typing in the command:
# tail -f /tmp/firstboot.log
echo ""
echo "==========================================================================="
echo "$varVersion"
echo "Original Version found at: https://github.com/LordDarkHelmet/DynamicScripts"
echo "Local Filename: $0"
echo "Local Time: $(date +%F_%T)"
echo "System Info: $(uname -a)"
echo "User $(id -u -n) UserID: $(id -u)"
echo "==========================================================================="
# Variables:
# These variables control the script's function. The only item you should change is the scrape address (the first variable, see above)
#
# Are you setting up a Dynode? if so you want to set these variables
# Set varDynode to 1 if you want to run a node, otherwise set it to zero.
varDynode=0
# This will set the external IP to your IP address (Linux only), or you can put your IP address in here
varDynodeExternalIP=$(hostname -I | cut -d' ' -f1)
# This is your Dynode pairing key. To get it run dynamic-cli dynode genkey,
varDynodePairingKey=""
# This is the label you want to give your Dynode
varDynodeLabel=""
# Location of Dynamic Binaries, GIT Directories, and other useful files
# Do not use the GIT directory (/Dynamic/) for anything other than GIT stuff
varUserDirectory=/root/
varDynamicBinaries="${varUserDirectory}DYN/bin/"
varScriptsDirectory="${varUserDirectory}DYN/UserScripts/"
varDynamicConfigDirectory="${varUserDirectory}.dynamic/"
varDynamicConfigFile="${varDynamicConfigDirectory}dynamic.conf"
varGITRootPath="${varUserDirectory}"
varGITDynamicPath="${varGITRootPath}Dynamic/"
varBackupDirectory="${varUserDirectory}DYN/Backups/"
# Quick Non-Source Start (get binaries and blockchain from the web, not completely safe or reliable, but fast!)
# Quick Start Binaries
varQuickStart=true
# Quick Start compressed file location and name
varQuickStartCompressedFileLocation=https://github.com/duality-solutions/Dynamic/releases/download/v2.5.0.0/Dynamic-2.5.0.0-Linux-x64.tar.gz
varQuickStartCompressedFileName="Dynamic-2.5.0.0-Linux-x64.tar.gz"
#varQuickStartCompressedFileDirectory="dynamic-2.5.0/bin/"
varQuickStartCompressedFileDirectory="bin/"
varQuickStartCompressedFilePathForDaemon="${varQuickStartCompressedFileDirectory}dynamicd"
varQuickStartCompressedFilePathForCLI="${varQuickStartCompressedFileDirectory}dynamic-cli"
# Quick Start Bootstrap (The developer recommends that you sync from the blockchain)
varQuickBootstrap=true
varQuickStartCompressedBootstrapLocation=https://duality.solutions/duality/bootstraps/dyn/bootstrap-latest.zip
varQuickStartCompressedBootstrapFileName=bootstrap-latest.zip
varQuickStartCompressedBootstrapFileIsZip=true
# Quick Start Blockchain (Downloading the blockchain will save time. It is up to you if you want to take the risk.) No longer available.
varQuickBlockchainDownload=false
varQuickStartCompressedBlockChainLocation=_INVALID_http://108.61.216.160/cryptochainer.chains/chains/Dynamic_blockchain.zip
varQuickStartCompressedBlockChainFileName=Dynamic_blockchain.zip
varQuickStartCompressedBlockChainFileIsZip=true
# Compile
# -varCompile will compile the code
varCompile=true
# Default Dynode Ports
DefaultDynode_rpcport=33350
DefaultDynode_port=33300
DefaultDynode_DHT_uTP_a=33311
DefaultDynode_DHT_uTP_b=33312
DefaultDynode_DHT_uTP_c=33313
DefaultDynode_DHT_uTP_d=33314
DefaultDynode_DHT_uTP_e=33315
DefaultDynode_DHT_uTP_f=33316
DefaultDynode_DHT_uTP_g=33317
DefaultDynode_DHT_uTP_h=33318
# P2P
DefaultP2P_Port=33300
# TestNet Ports
TestNetDynode_rpcport=33450
TestNetDynode_port=33400
TestNetDynode_DHT_uTP_a=33611
TestNetDynode_DHT_uTP_b=33612
TestNetDynode_DHT_uTP_c=33613
TestNetDynode_DHT_uTP_d=33614
TestNetDynode_DHT_uTP_e=33615
TestNetDynode_DHT_uTP_f=33616
TestNetDynode_DHT_uTP_g=33617
TestNetDynode_DHT_uTP_h=33618
# P2P
TestNetP2P_Port=33400
#
#Expand Swap File
varExpandSwapFile=true
#Mining Variables
#varMining0ForNo1ForYes controls if we mine or not. set it to 0 if you don't want to mine, set to 1 if you want to mine
varMining0ForNo1ForYes=0
#varMiningProcessorLimit set the number of processors you want to use -1 for unbounded (all of them).
varMiningProcessorLimit=-1
#varMiningProcessorAutoDetect if true, the script will automatically detect and explicitly add the number of CPUs (sockets * cores * threads per core)
varMiningProcessorAutoDetect=true
#varMiningScrapeTime is the amount of time in minutes between scrapes use 5 recommended
varMiningScrapeTime=5
#Dynamic GIT
varRemoteRepository=https://github.com/duality-solutions/Dynamic
#Script Repository
#This can be used to auto heal and update the script system.
#If a future deployment breaks something, an update by the repository owner can run a script on your machine.
#This is dangerous and not implemented
varRemoteScriptRepository=https://github.com/LordDarkHelmet/DynamicScripts
#AutoUpdater
#This runs the auto update script. If you do not want to automatically update the script, then set this to false. If a new update
varAutoUpdate=true
#AutoRepair
#Future Repair System.
varAutoRepair=true
#Watchdog timer. Check every X min to see if we are still running. (5 min recommended)
varWatchdogTime=5
#Turn on or off the watchdog. default is true.
varWatchdogEnabled=true
#System Lockdown, Firewall, security rules, etc.
varSystemLockdown=true
#Filenames of Generated Scripts
dynStop="${varScriptsDirectory}dynStopDynamicd.sh"
dynStart="${varScriptsDirectory}dynMineStart.sh"
dynScrape="${varScriptsDirectory}dynScrape.sh"
dynAutoUpdater="${varScriptsDirectory}dynAutoUpdater.sh"
dynWatchdog="${varScriptsDirectory}dynWatchdog.sh"
#Vultr API additions
varVultrAPIKey=""
varVultrLabelmHz=false
#Other and Test
Is_TestNet=false
#Developer's donation address
donationAddress=D9T2NVLGZEFSw3yc6ye4BenfK7n356wudR
#End of Variables
#
echo "-------------------------------------------"
echo "Read in attributes. This allows someone to run the script with their variables without having to modify this script."
echo ""
echo "To see all options pass in the -h attribute"
echo ""
echo "Options passed in: $@"
echo ""
while getopts :s:d:y:a:r:l:w:c:v:b:m:t:h option
do
case "${option}"
in
s)
myScrapeAddress=${OPTARG}
echo "-s has set myScrapeAddress=${myScrapeAddress}"
;;
d)
varDynodePairingKey=${OPTARG}
varDynode=1
if [ "$( echo "$varDynodePairingKey" | tr '[A-Z]' '[a-z]' )" = "unknown" ]; then
varDynodePairingKey=""
fi
echo "-d has set varDynode=1, and has set varDynodePairingKey=${varDynodePairingKey} (the script will set up a Dynode)"
;;
y)
varDynodeLabel=${OPTARG}
echo "-y has set varDynodeLabel=${varDynodeLabel}"
;;
a)
if [ "$( echo "${OPTARG}" | tr '[A-Z]' '[a-z]' )" = true ]; then
varAutoUpdate=true
echo "-a has set varAutoUpdate to true (default), the system will auto update at a random time every 24 hours"
else
varAutoUpdate=false
echo "-a has set varAutoUpdate to false, the system will not auto update. If an update occurs, you must do it manually."
fi
;;
r)
if [ "$( echo "${OPTARG}" | tr '[A-Z]' '[a-z]' )" = true ]; then
varAutoRepair=true
echo "-r AUTO REPAIR NOT IMPLEMENTED YET, Auto Repair is set to True (default), the system will auto repair"
else
varAutoRepair=false
echo "-r AUTO REPAIR NOT IMPLEMENTED YET, Auto Repair is set to FALSE, the system will not auto repair. If there is an issue you must repair it manually."
fi
;;
l)
if [ "$( echo "${OPTARG}" | tr '[A-Z]' '[a-z]' )" = true ]; then
varSystemLockdown=true
echo "-l AUTO LOCKDOWN, Auto Lockdown is set to True (default), System will be secured"
else
varSystemLockdown=false
echo "-l AUTO LOCKDOWN, Auto Lockdown is set to FALSE, the system will not be secured."
fi
;;
w)
if [ "$( echo "${OPTARG}" | tr '[A-Z]' '[a-z]' )" = true ]; then
varWatchdogEnabled=true
echo "-w varWatchdogEnabled is set to true (default), Watchdog will check every $varWatchdogTime min to see if dynamicd is still running"
else
varWatchdogEnabled=false
echo "-w varWatchdogEnabled is set to false, Watchdog will be disabled"
fi
;;
c)
if [ "$( echo "${OPTARG}" | tr '[A-Z]' '[a-z]' )" = true ]; then
varCompile=true
echo "-c varCompile is set to true (default), We will compile the code"
else
varCompile=false
echo "-c varCompile is set to false, We will not compile"
varAutoUpdate=false
echo " varAutoUpdate is also set to false because it requires compiling"
fi
;;
v)
myTemp=${OPTARG}
if [ "$( echo "${myTemp}" | tr '[A-Z]' '[a-z]' )" = mhz ]; then
varVultrLabelmHz=true
echo "-v has set an option to show the server's mHz on the label"
else
varVultrAPIKey=${myTemp}
echo "-v has set varVultrAPIKey=${varVultrAPIKey}"
fi
;;
b)
myTemp=${OPTARG}
if [ "$( echo "${myTemp}" | tr '[A-Z]' '[a-z]' )" = bootstrap ]; then
varQuickBlockchainDownload=false
varQuickBootstrap=true
echo "-b has set the bootstrap download only configuration"
elif [ "$( echo "${myTemp}" | tr '[A-Z]' '[a-z]' )" = blockchain ]; then
varQuickBlockchainDownload=true
varQuickBootstrap=false
echo "-b has set the bootstrap download only configuration"
elif [ "$( echo "${myTemp}" | tr '[A-Z]' '[a-z]' )" = none ]; then
varQuickBlockchainDownload=false
varQuickBootstrap=false
echo "-b We will not use a bootstrap or a blockchain download"
else
echo "-b ${myTemp} is not a valid option"
fi
;;
m)
if [ "$( echo "${OPTARG}" | tr '[A-Z]' '[a-z]' )" = false ]; then
varMining0ForNo1ForYes=0
echo "-m Mining has been set to false. We will disable mining."
else
varMining0ForNo1ForYes=1
echo "-m Mining has been set to true. We will be mining."
fi
;;
t)
myTemp=${OPTARG}
if [ "$( echo "${myTemp}" | tr '[A-Z]' '[a-z]' )" = testnet ]; then
# TestNet Ports
DefaultDynode_rpcport=${TestNetDynode_rpcport}
DefaultDynode_port=${TestNetDynode_port}
DefaultDynode_DHT_uTP_a=${TestNetDynode_DHT_uTP_a}
DefaultDynode_DHT_uTP_b=${TestNetDynode_DHT_uTP_b}
DefaultDynode_DHT_uTP_c=${TestNetDynode_DHT_uTP_c}
DefaultDynode_DHT_uTP_d=${TestNetDynode_DHT_uTP_d}
DefaultDynode_DHT_uTP_e=${TestNetDynode_DHT_uTP_e}
DefaultDynode_DHT_uTP_f=${TestNetDynode_DHT_uTP_f}
DefaultDynode_DHT_uTP_g=${TestNetDynode_DHT_uTP_g}
DefaultDynode_DHT_uTP_h=${TestNetDynode_DHT_uTP_h}
# P2P
DefaultP2P_Port=${TestNetP2P_Port}
Is_TestNet=true
echo "-t Changing variables to TestNet"
else
echo "-t Unknown attribute =${myTemp}"
fi
;;
h)
echo ""
echo "Help:"
echo "This script, $0 , can use the following attributes:"
echo " -s Scrape address requires an attribute Ex. -s $donationAddress"
echo " -d Dynode Pairing key. if you populate this it will setup a Dynode. ex -d ReplaceMeWithOutputFrom_dynamic-cli_dynode_genkey"
echo " You can also pre-enable a dynode by using the following: -d unknown"
echo " -y Dynode Label, a human readable label for your Dynode. Useful with the -v option."
echo " -a Auto Updates. Turns auto updates (on by default) on or off, ex -a true"
echo " -r Auto Repair. Turn auto repair on (default) or off, ex -r true"
echo " -l System Lockdown. Secure the instance. True to lock down your system. ex -l true"
echo " -w Watchdog. The watchdog restarts processes if they fail. true for on, false for off."
echo " -c Compile. Compile the code, default is true. If you set it to false it will also turn off AutoUpdate"
echo " -v Vultr API. see http://www.vultr.com/?ref=6923885 If you are using Vultr as an API service, this will change the label to update the last watchdog status"
echo " -b bootstrap or blockchain. Download an external bootstrap, blockchain or none, ex\"-b bootstrap\""
echo " -m Mining. enables or disables mining. true for on, false for off. Off by default. ex\"-m true\" to enable mining"
echo " -t Various test attributes (in development)"
echo " -h Display Help then exit."
echo ""
echo "Example 1: Just set up a simple miner"
echo "sudo sh $0 -s $donationAddress"
echo ""
echo "Example 2: Setup a remote Dynode"
echo "sudo sh $0 -s $donationAddress -d ReplaceMeWithOutputFrom_dynamic-cli_dynode_genkey"
echo ""
echo "Example 3: Setup a remote Dynode that does not mine. Great for VPS's that will ban high CPU usage"
echo "sudo sh $0 -s $donationAddress -d ReplaceMeWithOutputFrom_dynamic-cli_dynode_genkey -m false"
echo ""
echo "Example 4: Run a miner, but don't compile (auto update will be turned off by default), useful for low RAM VPS's that don't allow for SWAP files"
echo "sudo sh $0 -s $donationAddress -c false"
echo ""
echo "Example 5: Turn off auto update on a Dynode, you will be required to manually update if a new version comes along"
echo "sudo sh $0 -s $donationAddress -d ReplaceMeWithOutputFrom_dynamic-cli_dynode_genkey -a false"
echo ""
echo "PLEASE REMEMBER TO USE THE \"-s\" attribute. If you don't then you will be donating and not scraping to your address."
echo ""
echo ""
exit 1
;;
\?) echo "Invalid Option Tag: -$OPTARG";;
:) echo "Option -$OPTARG requires an argument. Using Default Values and continuing.";;
esac
done
echo "-------------------------------------------"
echo "==============================================================="
echo "SCRAPE ADDRESS: $myScrapeAddress"
echo "==============================================================="
echo "System Information:"
cat /etc/*release | grep -v URL
echo "If you found this script useful please contribute. Feedback is appreciated"
echo "==============================================================="
# Detect the number of CPU Threads that this machine has
if [ "$varMiningProcessorAutoDetect" = true ]; then
echo "Explicitly using the number of CPUs in the system rather than relying on -1"
#varMiningProcessorLimit=$(lscpu --json | jq -r '.lscpu[] | select(.field == "CPU(s):") | .data') # Linux 17.10 and above only. No json in 16.04
varMiningProcessorLimit=$(echo $(lscpu | grep -m 1 "CPU(s):" | cut -d' ' -f 8-))
if [ "$varMiningProcessorLimit" = "" ]; then
echo "no auto CPU detection, using -1"
varMiningProcessorLimit=-1
varMiningProcessorAutoDetect=false
echo "We will use $varMiningProcessorLimit processors, -1 = wallet will maximize"
else
echo "We will use $varMiningProcessorLimit processors"
fi
fi
### Prep your VPS (Increase Swap Space and update) ###
if [ "$varExpandSwapFile" = true ]; then
cd $varUserDirectory
# This will expand your swap file. It is not necessary if your VPS has more than 4G of ram, but it wont hurt to have
echo "Expanding the swap file for optimization with low RAM VPS..."
echo "sudo fallocate -l 4G /swapfile"
sudo fallocate -l 4G /swapfile
echo "sudo chmod 600 /swapfile"
sudo chmod 600 /swapfile
echo "sudo mkswap /swapfile"
sudo mkswap /swapfile
echo "sudo swapon /swapfile"
sudo swapon /swapfile
# the following command will append text to fstab to make sure your swap file stays there even after a reboot.
varSwapFileLine=$(cat /etc/fstab | grep "/swapfile none swap sw 0 0")
if [ "varSwapFileLine" = "" ]; then
echo "Adding swap file line to /etc/fstab"
sudo echo "/swapfile none swap sw 0 0" >> /etc/fstab
else
echo "Swap file line is already in /etc/fstab"
fi
echo "Swap file expanded."
echo "Current Swap File Status:"
echo "sudo swapon -s"
sudo swapon -s
echo ""
echo "Let's check the memory"
echo "free -m"
free -m
echo ""
echo "Ok, now let's check the swapieness"
echo "cat /proc/sys/vm/swappiness"
cat /proc/sys/vm/swappiness
echo ""
echo "Desktops usually have a swapieness of 60 or so, VPS's are usually lower. It should not matter for this application. It is just a curiosity."
echo "End of Swap File expansion"
echo "-------------------------------------------"
fi
# Ensure that your system is up to date and fully patched
echo ""
echo "Updating OS and packages..."
echo "sleeping for 60 seconds, this is because some VPS's are not fully up if you use this as a startup script"
sleep 60
echo "sudo apt-get -y update"
sudo apt-get -y update
# fix for "A new version (/tmp/grub.BBz9nuWKdP) of configuration file /etc/default/grub is available, but the version installed currently has been locally modified."
echo "DEBIAN_FRONTEND=noninteractive apt-get upgrade -q -y -u -o Dpkg::Options::=\"--force-confdef\""
DEBIAN_FRONTEND=noninteractive apt-get upgrade -q -y -u -o Dpkg::Options::="--force-confdef"
echo "OS and packages updated."
echo ""
#Install any utilities you need for the script
echo ""
echo "Installing the JSON parser jq"
sudo apt-get -y install jq
echo "Installing the unzip utility"
sudo apt-get -y install unzip
echo "Installing the unrar utility"
sudo apt-get -y install unrar
echo "Installing nano"
sudo apt-get -y install nano
echo ""
## make the directories we are going to use
echo "Make the directories we are going to use"
mkdir -pv $varDynamicBinaries
mkdir -pv $varScriptsDirectory
mkdir -pv $varBackupDirectory
## Create Scripts ##
echo "-------------------------------------------"
echo "Create the scripts we are going to use: "
echo "--"
### Script #1: Stop dynamicd ###
# Filename dynStopDynamicd.sh
cd $varScriptsDirectory
echo "Creating The Stop dynamicd Script: dynStopDynamicd.sh"
echo '#!/bin/sh' > dynStopDynamicd.sh
echo "# This file was generated. $(date +%F_%T) Version: $varVersion" >> dynStopDynamicd.sh
echo "# This script is here to force stop or force kill dynamicd" >> dynStopDynamicd.sh
echo "echo \"\$(date +%F_%T) Stopping the dynamicd if it already running \"" >> dynStopDynamicd.sh
echo "PID=\`ps -eaf | grep dynamicd | grep -v grep | awk '{print \$2}'\`" >> dynStopDynamicd.sh
echo "if [ \"\" != \"\$PID\" ]; then" >> dynStopDynamicd.sh
echo " if [ -e ${varDynamicBinaries}dynamic-cli ]; then" >> dynStopDynamicd.sh
echo " sudo timeout --preserve-status -k 45s 40s ${varDynamicBinaries}dynamic-cli stop" >> dynStopDynamicd.sh
echo " echo \"\$(date +%F_%T) Stop sent, waiting 30 seconds\"" >> dynStopDynamicd.sh
echo " sleep 30" >> dynStopDynamicd.sh
echo " fi" >> dynStopDynamicd.sh
echo "# At this point we should be stopped. Let's recheck and kill if we need to. " >> dynStopDynamicd.sh
echo " PID=\`ps -eaf | grep dynamicd | grep -v grep | awk '{print \$2}'\`" >> dynStopDynamicd.sh
echo " if [ \"\" != \"\$PID\" ]; then" >> dynStopDynamicd.sh
echo " echo \"\$(date +%F_%T) Rouge dynamicd process found. Killing PID: \$PID\"" >> dynStopDynamicd.sh
echo " sudo kill -9 \$PID" >> dynStopDynamicd.sh
echo " sleep 5" >> dynStopDynamicd.sh
echo " echo \"\$(date +%F_%T) Dynamicd has been Killed! PID: \$PID\"" >> dynStopDynamicd.sh
echo " else" >> dynStopDynamicd.sh
echo " echo \"\$(date +%F_%T) Dynamicd has been stopped.\"" >> dynStopDynamicd.sh
echo " fi" >> dynStopDynamicd.sh
echo "else" >> dynStopDynamicd.sh
echo " echo \"\$(date +%F_%T) Dynamic is not running. No need for shutdown commands.\"" >> dynStopDynamicd.sh
echo "fi" >> dynStopDynamicd.sh
echo "# End of generated Script" >> dynStopDynamicd.sh
echo "Changing the file attributes so we can run the script"
chmod +x dynStopDynamicd.sh
echo "Created dynStopDynamicd.sh"
dynStop="${varScriptsDirectory}dynStopDynamicd.sh"
echo "--"
### Script #2: MINING START SCRIPT ###
# Filename dynMineStart.sh
cd $varScriptsDirectory
echo "Creating Mining Start script: dynMineStart.sh"
echo '#!/bin/sh' > dynMineStart.sh
echo "" >> dynMineStart.sh
echo "# This file, dynMineStart.sh, was generated. $(date +%F_%T) Version: $varVersion" >> dynMineStart.sh
echo "" >> dynMineStart.sh
if [ "$varMiningProcessorAutoDetect" = true ]; then
echo "echo \"\$(date +%F_%T) We are set to auto detect the CPU count, so we will detect the number of CPU Threads that this machine has and modify the config file\"" >> dynMineStart.sh
#Linux 17.10 or above only #echo "echo \" CPUs detected: \$(lscpu --json | jq -r '.lscpu[] | select(.field == \"CPU(s):\") | .data')\"" >> dynMineStart.sh
#Linux 17.10 or above only #echo "sed -i s/genproclimit=.*/genproclimit=\$(lscpu --json | jq -r '.lscpu[] | select(.field == \"CPU(s):\") | .data')/ $varDynamicConfigFile" >> dynMineStart.sh
echo "echo \" CPUs detected: \$(echo \$(lscpu | grep -m 1 \"CPU(s):\" | cut -d' ' -f 8- | tr -d ' '))\"" >> dynMineStart.sh
echo "sed -i \"s/genproclimit=.*/genproclimit=\$(lscpu | grep -m 1 \"CPU(s):\" | cut -d' ' -f 8- | tr -d ' ')/\" $varDynamicConfigFile" >> dynMineStart.sh
echo "" >> dynMineStart.sh
fi
echo "echo \"Some VPS servers kill your swap file by removing it from fstab. Let's Check.\"" >> dynMineStart.sh
echo "varSwapFileLine=\$(cat /etc/fstab | grep \"/swapfile \")" >> dynMineStart.sh
echo "if [ \"\$varSwapFileLine\" = \"\" ]; then" >> dynMineStart.sh
echo " echo \"Somehow, the swap file was removed. Let's fix that\"" >> dynMineStart.sh
echo " echo \"Expanding the swap file for optimization with low RAM VPS...\"" >> dynMineStart.sh
echo " echo \"sudo fallocate -l 4G /swapfile\"" >> dynMineStart.sh
echo " sudo fallocate -l 4G /swapfile" >> dynMineStart.sh
echo " echo \"sudo chmod 600 /swapfile\"" >> dynMineStart.sh
echo " sudo chmod 600 /swapfile" >> dynMineStart.sh
echo " echo \"sudo mkswap /swapfile\"" >> dynMineStart.sh
echo " sudo mkswap /swapfile" >> dynMineStart.sh
echo " echo \"sudo swapon /swapfile\"" >> dynMineStart.sh
echo " sudo swapon /swapfile" >> dynMineStart.sh
echo " echo \"Adding swap file line to /etc/fstab\"" >> dynMineStart.sh
echo " sudo echo \"/swapfile none swap sw 0 0\" >> /etc/fstab" >> dynMineStart.sh
echo "else" >> dynMineStart.sh
echo " echo \"The swap file is in /etc/fstab\"" >> dynMineStart.sh
echo "fi" >> dynMineStart.sh
echo "" >> dynMineStart.sh
echo "mySwapSizeMB=\$(swapon -s | grep -v Size | awk '{print \$3/1024}')" >> dynMineStart.sh
echo "if [ \"\${mySwapSizeMB}\" = \"\" ]; then" >> dynMineStart.sh
echo " echo \"Swap File does not seem to be on\"" >> dynMineStart.sh
echo " echo \"Enable all swaps from /etc/fstab\"" >> dynMineStart.sh
echo " echo \"sudo swapon -a\"" >> dynMineStart.sh
echo " sudo swapon -a" >> dynMineStart.sh
echo " echo \"Current Swap File Status:\"" >> dynMineStart.sh
echo " echo \"sudo swapon -s\"" >> dynMineStart.sh
echo " sudo swapon -s" >> dynMineStart.sh
echo " echo \"Let's check the memory\"" >> dynMineStart.sh
echo " echo \"free -m\"" >> dynMineStart.sh
echo " free -m" >> dynMineStart.sh
echo "else" >> dynMineStart.sh
echo " echo \"Swap file is running \${mySwapSizeMB} MB\"" >> dynMineStart.sh
echo "fi" >> dynMineStart.sh
echo "" >> dynMineStart.sh
echo "echo \"Remove ${varDynamicConfigDirectory}dncache.dat file. (This is to prevent potentially corrupted information.)\"" >> dynMineStart.sh
echo "sudo rm ${varDynamicConfigDirectory}dncache.dat" >> dynMineStart.sh
echo "" >> dynMineStart.sh
echo "echo \"\$(date +%F_%T) Starting Dynamic miner: \$(date)\"" >> dynMineStart.sh
echo "sudo ${varDynamicBinaries}dynamicd --daemon" >> dynMineStart.sh
echo "echo \"\$(date +%F_%T) Waiting 15 seconds \"" >> dynMineStart.sh
echo "sleep 15" >> dynMineStart.sh
echo "# End of generated Script" >> dynMineStart.sh
echo "Changing the file attributes so we can run the script"
chmod +x dynMineStart.sh
echo "Created dynMineStart.sh."
dynStart="${varScriptsDirectory}dynMineStart.sh"
echo "--"
### script #3: GENERATE SCRAPE SCRIPT ###
# Filename: dynScrape.sh
cd $varScriptsDirectory
echo "Creating Scrape script: dynScrape.sh"
echo '#!/bin/sh' > dynScrape.sh
echo "" >> dynScrape.sh
echo "# This file, dynScrape.sh, was generated. $(date +%F_%T) Version: $varVersion" >> dynScrape.sh
echo "" >> dynScrape.sh
echo "myBalance=\$(sudo ${varDynamicBinaries}dynamic-cli getbalance)" >> dynScrape.sh
echo "if [ \"\$myBalance\" = \"\" ] ; then" >> dynScrape.sh
echo " echo \"\$(date +%F_%T) No Response, is the daemon running, does it exist yet?\"" >> dynScrape.sh
echo "else" >> dynScrape.sh
echo " if [ \$myBalance != \"0.00000000\" ];then" >> dynScrape.sh
echo " echo \"\$(date +%F_%T) Scraping a balance of \$myBalance to $myScrapeAddress \"" >> dynScrape.sh
echo " sudo ${varDynamicBinaries}dynamic-cli sendtoaddress \"$myScrapeAddress\" \$(sudo ${varDynamicBinaries}dynamic-cli getbalance) \"\" \"\" true " >> dynScrape.sh
echo " fi" >> dynScrape.sh
echo "fi" >> dynScrape.sh
echo "# End of generated Script" >> dynScrape.sh
echo "Changing the file attributes so we can run the script"
chmod +x dynScrape.sh
echo "Created dynScrape.sh."
dynScrape="${varScriptsDirectory}dynScrape.sh"
echo "--"
### script #4: AUTO UPDATER SCRIPT ###
# Filename: dynAutoUpdater.sh
cd $varScriptsDirectory
echo "Creating Scrape script: dynAutoUpdater.sh"
echo '#!/bin/sh' > dynAutoUpdater.sh
echo "" >> dynAutoUpdater.sh
echo "# This file, dynAutoUpdater,sh, was generated. $(date +%F_%T) Version: $varVersion" >> dynAutoUpdater.sh
echo "" >> dynAutoUpdater.sh
echo "cd $varGITDynamicPath" >> dynAutoUpdater.sh
echo "if [ \"\`git log --pretty=%H ...refs/heads/master^ | head -n 1\`\" = \"\`git ls-remote $varRemoteRepository -h refs/heads/master |cut -f1\`\" ] ; then" >> dynAutoUpdater.sh
echo " echo \"GitCheck \$(date +%F_%T) : We are up to date.\"" >> dynAutoUpdater.sh
echo "else" >> dynAutoUpdater.sh
echo " echo \"GitCheck \$(date +%F_%T) : Changes to the repository, Preparing to update.\"" >> dynAutoUpdater.sh
echo "" >> dynAutoUpdater.sh
echo " # 1. Download the new source code from the repository if it has been updated" >> dynAutoUpdater.sh
echo " echo \"GitCheck \$(date +%F_%T) : Remove old repository, we need to do a clean clone for the next version comparison to work. Do not git pull.\"" >> dynAutoUpdater.sh
echo " rm -fdr $varGITDynamicPath" >> dynAutoUpdater.sh
echo " mkdir -pv $varGITDynamicPath" >> dynAutoUpdater.sh
echo " cd $varUserDirectory" >> dynAutoUpdater.sh
echo " echo \"GitCheck \$(date +%F_%T) : Downloading the source code\"" >> dynAutoUpdater.sh
echo " sudo git clone $varRemoteRepository" >> dynAutoUpdater.sh
echo "" >> dynAutoUpdater.sh
echo " # 2. Compile the new code" >> dynAutoUpdater.sh
echo " echo \"GitCheck \$(date +%F_%T) : Compile the source code\"" >> dynAutoUpdater.sh
echo " cd $varGITDynamicPath" >> dynAutoUpdater.sh
echo " echo \"Check if we can optimize mining using the ssse3, avx2, and avx512f instruction sets\"" >> dynAutoUpdater.sh
echo " ConfigParameters=\" --without-gui --disable-gpu \"" >> dynAutoUpdater.sh
echo " CPPFLAGS=-march=native" >> dynAutoUpdater.sh
echo " varssse3=\$(grep ssse3 /proc/cpuinfo)" >> dynAutoUpdater.sh
echo " if [ \"\$varssse3\" = \"\" ]; then" >> dynAutoUpdater.sh
echo " echo \"ssse3 not found, normal compile, no ssse3 optimizations\"" >> dynAutoUpdater.sh
echo " else" >> dynAutoUpdater.sh
echo " ConfigParameters=\"\${ConfigParameters} --enable-ssse3 \"" >> dynAutoUpdater.sh
echo " fi" >> dynAutoUpdater.sh
echo " varavx2=\$(grep avx2 /proc/cpuinfo)" >> dynAutoUpdater.sh
echo " if [ \"\$varavx2\" = \"\" ]; then" >> dynAutoUpdater.sh
echo " echo \"avx2 not found, normal compile, no avx2 optimizations\"" >> dynAutoUpdater.sh
echo " else" >> dynAutoUpdater.sh
echo " ConfigParameters=\"\${ConfigParameters} --enable-avx2 \"" >> dynAutoUpdater.sh
echo " fi" >> dynAutoUpdater.sh
echo " varavx512f=\$(grep avx512f /proc/cpuinfo)" >> dynAutoUpdater.sh
echo " if [ \"\$varavx512f\" = \"\" ]; then" >> dynAutoUpdater.sh
echo " echo \"avx512f not found, normal compile, no avx512f optimizations\"" >> dynAutoUpdater.sh
echo " else" >> dynAutoUpdater.sh
echo " ConfigParameters=\"\${ConfigParameters} --enable-avx512f \"" >> dynAutoUpdater.sh
echo " fi" >> dynAutoUpdater.sh
echo " sudo ./autogen.sh && sudo ./configure \$ConfigParameters CPPFLAGS=\" -march=native \" && sudo make" >> dynAutoUpdater.sh
echo " echo \"GitCheck \$(date +%F_%T) : Compile Finished.\"" >> dynAutoUpdater.sh
echo "" >> dynAutoUpdater.sh
echo " # 3. Scrape if there are any funds before we stop" >> dynAutoUpdater.sh
echo " echo \"GitCheck \$(date +%F_%T) : Scrape if there are any funds before we stop.\"" >> dynAutoUpdater.sh
echo " sudo ${dynScrape}" >> dynAutoUpdater.sh
echo "" >> dynAutoUpdater.sh
echo " # 4. Stop the running daemon" >> dynAutoUpdater.sh
echo " echo \"GitCheck \$(date +%F_%T) : Stop the running daemon.\"" >> dynAutoUpdater.sh
echo " sudo ${dynStop}" >> dynAutoUpdater.sh
echo "" >> dynAutoUpdater.sh
echo " # 5. Replace the executable files" >> dynAutoUpdater.sh
echo " echo \"GitCheck \$(date +%F_%T) : Replace the executable files.\"" >> dynAutoUpdater.sh
echo " mkdir -pv $varDynamicBinaries" >> dynAutoUpdater.sh
echo " sudo cp -v ${varGITDynamicPath}src/dynamicd $varDynamicBinaries" >> dynAutoUpdater.sh
echo " sudo cp -v ${varGITDynamicPath}src/dynamic-cli $varDynamicBinaries" >> dynAutoUpdater.sh
echo " sudo cp -v ${varGITDynamicPath}src/dynamicd /usr/local/bin" >> dynAutoUpdater.sh
echo " sudo cp -v ${varGITDynamicPath}src/dynamic-cli /usr/local/bin" >> dynAutoUpdater.sh
echo "" >> dynAutoUpdater.sh
echo " # 6. Start the daemon" >> dynAutoUpdater.sh
echo " echo \"GitCheck \$(date +%F_%T) : Start the daemon. Mining will automatically start once synced.\"" >> dynAutoUpdater.sh
echo " sudo ${varDynamicBinaries}dynamicd --daemon" >> dynAutoUpdater.sh
echo "" >> dynAutoUpdater.sh
echo " echo \"waiting 10 seconds\"" >> dynAutoUpdater.sh
echo " sleep 10" >> dynAutoUpdater.sh
echo " echo \"GitCheck \$(date +%F_%T) : Now running the latest GIT version.\"" >> dynAutoUpdater.sh
echo "" >> dynAutoUpdater.sh
echo "fi" >> dynAutoUpdater.sh
echo "# End of generated Script" >> dynAutoUpdater.sh
echo "Changing the file attributes so we can run the script"
chmod +x dynAutoUpdater.sh
echo "Created dynAutoUpdater.sh."
dynAutoUpdater="${varScriptsDirectory}dynAutoUpdater.sh"
echo "--"
### Script #6: Watchdog, Checks to see if the process is running and restarts it if it is not. ###
# Filename dynWatchdog.sh
cd $varScriptsDirectory
echo "Creating The Stop dynamicd Script: dynWatchdog.sh"
echo '#!/bin/sh' > dynWatchdog.sh
echo "# This file, dynWatchdog.sh, was generated. $(date +%F_%T) Version: $varVersion" >> dynWatchdog.sh
echo "# This script checks to see if dynamicd is running. If it is not, then it will be restarted." >> dynWatchdog.sh
echo "PID=\`ps -eaf | grep dynamicd | grep -v grep | awk '{print \$2}'\`" >> dynWatchdog.sh
echo "if [ \"\" = \"\$PID\" ]; then" >> dynWatchdog.sh
echo " if [ -e ${varDynamicBinaries}dynamic-cli ]; then" >> dynWatchdog.sh
echo " echo \"\$(date +%F_%T) STOPPED: Wait 2 minutes. We could be in an auto-update or other momentary restart.\"" >> dynWatchdog.sh
echo " sleep 120" >> dynWatchdog.sh
echo " PID=\`ps -eaf | grep dynamicd | grep -v grep | awk '{print \$2}'\`" >> dynWatchdog.sh
echo " if [ \"\" = \"\$PID\" ]; then" >> dynWatchdog.sh
echo " echo \"\$(date +%F_%T) Starting: Attempting to start the dynamic daemon \"" >> dynWatchdog.sh
echo " sudo ${dynStart}" >> dynWatchdog.sh
echo " echo \"\$(date +%F_%T) Starting: Attempt complete. We will see if it worked the next watchdog round. \"" >> dynWatchdog.sh
echo " myVultrStatusInfo=\"Starting ...\"" >> dynWatchdog.sh
echo " else" >> dynWatchdog.sh
echo " echo \"\$(date +%F_%T) Running: Must have been some reason it was down. \"" >> dynWatchdog.sh
echo " myVultrStatusInfo=\"Running ...\"" >> dynWatchdog.sh
echo " fi" >> dynWatchdog.sh
echo " else" >> dynWatchdog.sh
echo " echo \"\$(date +%F_%T) Error the file ${varDynamicBinaries}dynamic-cli does not exist! \"" >> dynWatchdog.sh
echo " myVultrStatusInfo=\"Error: dynamic-cli does not exist!\"" >> dynWatchdog.sh
echo " fi" >> dynWatchdog.sh
echo "else" >> dynWatchdog.sh
echo " myBlockCount=\$(sudo timeout --preserve-status -k 45s 40s ${varDynamicBinaries}dynamic-cli getblockcount 2>&1)" >> dynWatchdog.sh
echo " myCLIErrorCode=\$?" >> dynWatchdog.sh
echo " if [ \"\${myCLIErrorCode}\" = \"0\" ]; then" >> dynWatchdog.sh
echo " myDynamicVersion=\"\$(sudo timeout --preserve-status -k 45s 40s ${varDynamicBinaries}dynamic-cli getinfo | jq -r '.version')\"" >> dynWatchdog.sh
echo " myHashesPerSec=\$(sudo timeout --preserve-status -k 45s 40s ${varDynamicBinaries}dynamic-cli gethashespersec)" >> dynWatchdog.sh
#echo " myNetworkDifficulty=\$(sudo timeout --preserve-status -k 45s 40s ${varDynamicBinaries}dynamic-cli getdifficulty)" >> dynWatchdog.sh
echo " myNetworkHPS=\$(sudo timeout --preserve-status -k 45s 40s ${varDynamicBinaries}dynamic-cli getnetworkhashps)" >> dynWatchdog.sh
echo " myVultrStatusInfo=\"\${myHashesPerSec} hps\"" >> dynWatchdog.sh
echo " if [ \"0 hps\" = \"\${myVultrStatusInfo}\" ]; then" >> dynWatchdog.sh
echo " myGenerate=\$(cat ${varDynamicConfigFile} | grep gen=1 )" >> dynWatchdog.sh
echo " if [ \"gen=1\" = \"\${myGenerate}\" ]; then" >> dynWatchdog.sh
echo " echo \"We should be mining, but we have 0 hps, try setgenerate true -1\"" >> dynWatchdog.sh
echo " sudo timeout --preserve-status -k 45s 40s ${varDynamicBinaries}dynamic-cli setgenerate true -1" >> dynWatchdog.sh
echo " fi" >> dynWatchdog.sh
echo " fi" >> dynWatchdog.sh
if [ "$varDynode" = 1 ]; then
echo " myMNStatus=\$(sudo timeout --preserve-status -k 45s 40s ${varDynamicBinaries}dynamic-cli dynode status | jq -r '.status')" >> dynWatchdog.sh
echo " echo \"\$(date +%F_%T) Running: Block Count: \$myBlockCount Hash Rate: \$myHashesPerSec Network HPS \$myNetworkHPS Dynode: \$myMNStatus \"" >> dynWatchdog.sh
else
echo " echo \"\$(date +%F_%T) Running: Block Count: \$myBlockCount Hash Rate: \$myHashesPerSec Network HPS \$myNetworkHPS \"" >> dynWatchdog.sh
fi
echo " elif [ \"\${myCLIErrorCode}\" = \"28\" ]; then" >> dynWatchdog.sh
echo " echo \"Loading block index...\"" >> dynWatchdog.sh
echo " myVultrStatusInfo=\"Loading block index...\"" >> dynWatchdog.sh
echo " else" >> dynWatchdog.sh
echo " echo \"\$(date +%F_%T) Unresponsive: Stop the daemon, it will restart next time\"" >> dynWatchdog.sh
echo " myVultrStatusInfo=\"Unresponsive Stopping ...\"" >> dynWatchdog.sh
echo " sudo ${dynStop}" >> dynWatchdog.sh
echo " fi" >> dynWatchdog.sh
echo "fi" >> dynWatchdog.sh
if [ "" = "$varVultrAPIKey" ]; then
echo "No Vultr API Key, skipping Vultr specific label updater"
else
myCommand="mySUBID=\$(curl -s -H 'API-Key: ${varVultrAPIKey}' https://api.vultr.com/v1/server/list?main_ip=$(hostname -I | cut -d' ' -f1) | jq -r '.[].SUBID')"
echo $myCommand
eval $myCommand
#Try 2
if [ "$mySUBID" = "" ]; then
#if you are starting a lot of servers at once, you could have flooded the API, set a random delay and try again once.
sleep $(shuf -i 1-60 -n 1)
echo "Second attempt to get the SUBID"
eval $myCommand
fi
#Try 3, three strikes you are out. It can happen but it is less likely.
if [ "$mySUBID" = "" ]; then
#if you are starting a lot of servers at once, you could have flooded the API, set a random delay and try again once.
sleep $(shuf -i 1-60 -n 1)
echo "Third attempt to get the SUBID"
eval $myCommand
fi
## if a dynode label has not been set, set it here
if [ "$varDynodeLabel" = "" ]; then
varDynodeLabel="$mySUBID"
fi
echo "Vultr SUBID=${mySUBID}"
echo "mySUBIDStr=\"'SUBID=${mySUBID}'\"" >> dynWatchdog.sh
if [ "$varVultrLabelmHz" = true ]; then
echo "myMHz=\"| \$(cat /proc/cpuinfo |grep -m 1 \"cpu MHz\"|cut -d' ' -f 3-) MHz \"" >> dynWatchdog.sh
fi
testnetLabel=""
if [ ${Is_TestNet} = true ]; then
testnetLabel="---TESTNET---"
fi
if [ "$varDynode" = 1 ]; then
echo "myLabel=\"'label=${testnetLabel}\$(date \"+%F %T\") | v${varVersionNumber}, \${myDynamicVersion} \${myMHz}| \${myVultrStatusInfo} | DYNODE ${varDynodeLabel}=\${myMNStatus} '\"" >> dynWatchdog.sh
else
echo "myLabel=\"'label=${testnetLabel}\$(date \"+%F %T\") | v${varVersionNumber}, \${myDynamicVersion} \${myMHz}| \${myVultrStatusInfo} '\"" >> dynWatchdog.sh
fi
echo "#due to API rate limiting lets go at a random time in the next 4.5 min." >> dynWatchdog.sh
echo "sleep \$(shuf -i 1-270 -n 1)" >> dynWatchdog.sh
echo "myCommand=\"curl -s -H 'API-Key: ${varVultrAPIKey}' https://api.vultr.com/v1/server/label_set --data \${mySUBIDStr} --data \${myLabel}\"" >> dynWatchdog.sh
if [ "$mySUBID" = "" ]; then
echo "#We did not find the SUBID, so we are not going to execute the API command to update the Vultr hosted label." >> dynWatchdog.sh
echo "#You can get it by running this command: mySUBID=\$(curl -H 'API-Key: ${varVultrAPIKey}' https://api.vultr.com/v1/server/list?main_ip=\$(hostname -I | cut -d' ' -f1) | jq -r '.[].SUBID')" >> dynWatchdog.sh
echo "#eval \$myCommand" >> dynWatchdog.sh
else
echo "eval \$myCommand" >> dynWatchdog.sh
fi
fi
echo "# End of generated Script" >> dynWatchdog.sh
echo "Changing the file attributes so we can run the script"
chmod +x dynWatchdog.sh
echo "Created dynWatchdog.sh"
dynWatchdog="${varScriptsDirectory}dynWatchdog.sh"
echo "--"
### Script #7: Vultr Label Update ###
# Filename vultr.sh
# Vultr Initial update
if [ "" = "$varVultrAPIKey" ]; then
echo "No Vultr API Key, skipping Vultr specific initial label"
else
cd $varScriptsDirectory
echo "Creating The Stop dynamicd Script: vultr.sh"
echo '#!/bin/sh' > vultr.sh
echo "# This file, vultr.sh, was generated. $(date +%F_%T) Version: $varVersion" >> vultr.sh
echo "# This file Updates the Vultr Label using the Vultr API-Key" >> vultr.sh
echo "" >> vultr.sh
echo "echo \"---------------------------------\"" >> vultr.sh
if [ "$mySUBID" = "" ]; then
echo "echo \"Error: No SUBID found. \"" >> vultr.sh
else
echo "mySUBIDStr=\"'SUBID=${mySUBID}'\"" >> vultr.sh
if [ "$varVultrLabelmHz" = true ]; then
echo "myMHz=\$(cat /proc/cpuinfo |grep -m 1 \"cpu MHz\"|cut -d' ' -f 3-)" >> vultr.sh
echo "myMHz=\"| \${myMHz} MHz \"" >> vultr.sh
fi
testnetLabel=""
if [ ${Is_TestNet} = true ]; then
testnetLabel="---TESTNET---"
fi
if [ "$varDynode" = 1 ]; then
echo "myLabel=\"'label=${testnetLabel}DYNODE ${varDynodeLabel} | v${varVersionNumber} | Setting Up... \${myMHz}'\"" >> vultr.sh
else
echo "myLabel=\"'label=${testnetLabel}v${varVersionNumber} | Setting Up... \${myMHz}'\"" >> vultr.sh
fi
echo "myCommand=\"curl -H 'API-Key: ${varVultrAPIKey}' https://api.vultr.com/v1/server/label_set --data \${mySUBIDStr} --data \${myLabel}\"" >> vultr.sh
echo "eval \$myCommand" >> vultr.sh
fi
echo "echo \"---------------------------------\"" >> vultr.sh
echo "#end of generated file" >> vultr.sh
echo "Changing the file attributes so we can run the script"
chmod +x vultr.sh
echo "Created vultr.sh"
vultr="${varScriptsDirectory}vultr.sh"
echo "--"
#due to API rate limiting lets go at a random time in the next 40 seconds.
echo "Waiting a random period of time, no more than 40 seconds to prevent pegging the vultr API server"
sleep $(shuf -i 1-40 -n 1)
sudo ${vultr}
fi
echo "Done creating scripts"
echo "-------------------------------------------"
### Functions ###
funcCreateDynamicConfFile ()
{
echo "---------------------------------"
echo "- Creating the configuration file."
echo "- Creating the dynamic.conf file, this replaces any existing file. "
echo "Need to crate a random password and user name. Check current entropy"
sudo cat /proc/sys/kernel/random/entropy_avail
sleep 1
Myrpcuser=$(sudo tr -d -c "a-zA-Z0-9" < /dev/urandom | sudo head -c 34)
echo "Myrpcuser=$Myrpcuser"
sleep 1
Myrpcpassword=$(sudo tr -d -c "a-zA-Z0-9" < /dev/urandom | sudo head -c $(shuf -i 30-36 -n 1))
echo "Myrpcpassword=$Myrpcpassword"
Myport=$(shuf -i 50000-65000 -n 1)
Myrpcport=$(shuf -i 1-500 -n 1)
Myrpcport=$((Myrpcport+Myport))
if [ "$varDynode" = 1 ]; then
Myrpcport=$DefaultDynode_rpcport
Myport=$DefaultDynode_port
fi
mkdir -pv $varDynamicConfigDirectory
echo "# This file was generated. $(date +%F_%T) Version: $varVersion" > $varDynamicConfigFile
echo "# Do not use special characters or spaces with username/password" >> $varDynamicConfigFile
echo "rpcuser=$Myrpcuser" >> $varDynamicConfigFile
echo "rpcpassword=$Myrpcpassword" >> $varDynamicConfigFile
echo "rpcport=$Myrpcport" >> $varDynamicConfigFile
echo "port=$Myport" >> $varDynamicConfigFile
echo "" >> $varDynamicConfigFile
if [ ${Is_TestNet} = true ]; then
echo "# Test Net: If this is on the testnet, then testnet=1" >> $varDynamicConfigFile
echo "testnet=1" >> $varDynamicConfigFile
echo "" >> $varDynamicConfigFile
fi
echo "# MINING: These are your mining variables" >> $varDynamicConfigFile
echo "# Gen can be 0 or 1. 1=mining, 0=No mining" >> $varDynamicConfigFile
echo "gen=$varMining0ForNo1ForYes" >> $varDynamicConfigFile
echo "# genproclimit sets the number of processors you want to use -1 for unbounded (all of them)" >> $varDynamicConfigFile
echo "genproclimit=$varMiningProcessorLimit" >> $varDynamicConfigFile
echo "" >> $varDynamicConfigFile
if [ "$varDynode" = 1 ]; then
if [ "$varDynodePairingKey" = "" ]; then
echo "This instance will be a dynode, but a dynode key has not been assigned. We will auto assign a dynode key later."
else
echo "# DYNODE: " >> $varDynamicConfigFile
echo "# externalip is the IP address of this machine. (the remote Dynode's IP address) " >> $varDynamicConfigFile
echo "externalip=$varDynodeExternalIP" >> $varDynamicConfigFile
echo "# dynode can be 0 or 1. 1=dynode, 0=not a dynode" >> $varDynamicConfigFile
echo "dynode=$varDynode" >> $varDynamicConfigFile
echo "# Use your local or control wallet, run the command \"Dynode genkey\" to generate a unique dynodepairingkey for each remote Dynode" >> $varDynamicConfigFile
echo "dynodepairingkey=$varDynodePairingKey" >> $varDynamicConfigFile
echo "" >> $varDynamicConfigFile
fi
fi
echo "" >> $varDynamicConfigFile
echo "# if you can't connect, you may need to add a node, check the peers list on an explorer and add some nodes here" >> $varDynamicConfigFile
echo "# addnode=<IP Address>:<PORT>" >> $varDynamicConfigFile
echo "" >> $varDynamicConfigFile
echo "# End of generated file" >> $varDynamicConfigFile
echo "- Finished creating dynamic.conf"
echo "---------------------------------"
sleep 1
}
####### Security Lockdown Function #############
#Permanent lockdown and security of the node/miner. Not implementing before we work out the bugs. (don't want to lock us out from debugging it)
#For now we are just setting up a basic firewall. We are also using random ports for miners, but Dynodes are using the default ports.
#basically you are just putting up a firewall with three open ports, SSH dynamic port, and dynamic RPC port.
funcLockdown ()
{
echo "---------------------------------"
echo "-Basic lockdown and security of the node and or miner."
#echo "-Permanent lockdown and security of the node and or miner."
#echo "-Remove SSH Access, Usually on Port 22. This will lock you out as well."
mysshPort=22
#edit /etc/ssh/sshd_config to remove the line or change the line that says Port 22
# it is suggested that you use a port between 49152 and 65535 MySSHport=$(shuf -i 49152-65535 -n 1)
# note: To check is a port is in use netstat -an | grep “port”
# Save the file and return to the console
# At this point the sshd_config file has been changed, but the SSH service needs to be restarted in order for those changes to take effect.
# sudo service ssh restart
# When you connect back to your VPS via an SSH client, be sure to change the port to the one you specified in your sshd_config file. While you are more secure because you changed the port and you have a really secure password, an attacker can still find your port and attempt to break your password via a brute force attack. To prevent this you will need a firewall to limit the number of attempts per second, making a brute force attack impossibly long.
# Install a Firewall
# The Uncomplicated Firewall (UFW) is the default firewall configuration tool for Ubuntu.
#
# The following commands can be used to install and setup your UFW to help protect your system.
#
echo "sudo apt-get -y install ufw # this installs UFW"
sudo apt-get -y install ufw
echo "sudo ufw default deny # By default UFW will deny all connections. "
sudo ufw default deny
echo "sudo ufw allow ${mysshPort}/tcp # replace XXXXX with your SSH port chosen earlier"
sudo ufw allow $mysshPort/tcp comment "ssh port"
echo "sudo ufw limit ${mysshPort}/tcp # limits SSH connection attempts from an IP to 6 times in 30 seconds"
sudo ufw limit $mysshPort/tcp comment "ssh port limited"
testnetLabel=""
if [ ${Is_TestNet} = true ]; then
testnetLabel="---TESTNET--- "
fi
echo "sudo ufw allow ${Myport}/tcp # replace YYYYY with your dynamic port (dynamic.conf file under port=#####) BTW for Dynodes this is $DefaultDynode_port by default."
sudo ufw allow $Myport/tcp comment "${testnetLabel}Dynamic Dynode"
echo "sudo ufw allow ${Myrpcport}/tcp # replace ZZZZZ with your rpc port (dynamic.conf file under rpcport=#####) BTW for Dynodes this is $DefaultDynode_rpcport by default."
sudo ufw allow $Myrpcport/tcp comment "${testnetLabel}Dynamic Dynode RPC"
echo "sudo ufw allow ${DefaultDynode_DHT_uTP_a}/tcp # replace AAAAAA with your DHT µTP (Micro Transport Protocol) port. BTW for Dynodes this is $DefaultDynode_DHT_uTP_a by default."
sudo ufw allow $DefaultDynode_DHT_uTP_a/tcp comment "${testnetLabel}Dynamic Dynode - DHT_uTP_a"
echo "sudo ufw allow ${DefaultDynode_DHT_uTP_b}/tcp # replace BBBBBB with your DHT µTP (Micro Transport Protocol) port. BTW for Dynodes this is $DefaultDynode_DHT_uTP_b by default."
sudo ufw allow $DefaultDynode_DHT_uTP_b/tcp comment "${testnetLabel}Dynamic Dynode - DHT_uTP_b"
echo "sudo ufw allow ${DefaultDynode_DHT_uTP_c}/tcp # replace CCCCCC with your DHT µTP (Micro Transport Protocol) port. BTW for Dynodes this is $DefaultDynode_DHT_uTP_c by default."
sudo ufw allow $DefaultDynode_DHT_uTP_c/tcp comment "${testnetLabel}Dynamic Dynode - DHT_uTP_c"
echo "sudo ufw allow ${DefaultDynode_DHT_uTP_d}/tcp # replace DDDDDD with your DHT µTP (Micro Transport Protocol) port. BTW for Dynodes this is $DefaultDynode_DHT_uTP_d by default."