forked from wareck/okcash_node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_node.sh
executable file
·842 lines (778 loc) · 26.2 KB
/
build_node.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
#!/bin/bash
set -e
Version=6.2
Release=01/08/2022
author=wareck@gmail.com
#Okcash headless RPI Working (sync enable, staking enable)
#Best results found and last version use for this script are :
#Boost 1.67 / Openssl 1.0.2r / DB 4.8-30-NC / OkCash git current release (v6.9.0.5)
#download external config:
source config.txt
AutoStart=YES
### Main Code ###
# check size of card:
SOC=`df | grep /dev/root | awk '{print $4'}`
if [ $Bootstrap = "YES" ] && ! [ -f .pass ]
then
if [ $SOC -le "3000000" ]; then RemoveTarball=YES ;fi
fi
if [ -f /boot/dietpi.txt ]
then
LSB=$(cat /etc/debian_version)
img_v="\e[93mDietpi\e[0m"
DietPi_="YES"
else
LSB=$(cat /etc/debian_version)
OSV=$(sed 's/\..*//' /etc/debian_version)
DietPi_="NO"
if [ $OSV = 8 ];then img_v="Jessie";fi
if [ $OSV = 9 ];then img_v="Strecth"; fi
if [ $OSV = 10 ];then img_v="Buster"; fi
if [ $OSV = 11 ];then img_v="Bullseye"; fi
fi
if [ -f /proc/device-tree/model ]
then
ident=$(tr -d '\0' < /proc/device-tree/model)
else
ident=""
img_v="Unknown"
fi
MyUser=$USER
MyDir=$PWD
echo $MyUser>/tmp/node_user
Dw=0 #daemon working flag
echo -e "\e[93mOkcash Headless Node builder v$Version ($Release)\e[0m"
echo -e "Author : wareck@gmail.com"
sleep 2
echo -e "\n\e[97mConfiguration:\e[0m"
echo -e "--------------"
echo -e -n "Download Bootstrap.dat : "; if [ $Bootstrap = "YES" ];then echo -e "[\e[92m YES \e[0m]"; else echo -e "[\e[91m NO \e[0m]";fi
echo -e -n "Raspberry Optimisation : "; if [ $Raspi_optimize = "YES" ];then echo -e "[\e[92m YES \e[0m]"; else echo -e "[\e[91m NO \e[0m]";fi
echo -e -n "Node message banner : "; if [ $Banner = "YES" ];then echo -e "[\e[92m YES \e[0m]"; else echo -e "[\e[91m NO \e[0m]";fi
echo -e -n "Okcash autostart at boot : "; if [ $AutoStart = "YES" ];then echo -e "[\e[92m YES \e[0m]"; else echo -e "[\e[91m NO \e[0m]";fi
echo -e -n "Website Frontend : "; if [ $Website = "YES" ];then echo -e "[\e[92m YES \e[0m]"; else echo -e "[\e[91m NO \e[0m]";fi
echo -e -n "Firewall enable : "; if [ $Firewall = "YES" ];then echo -e "[\e[92m YES \e[0m]"; else echo -e "[\e[91m NO \e[0m]";fi
echo -e -n "Keep sources after build : "; if [ $RemoveTarball = "NO" ];then echo -e "[\e[92m YES \e[0m]"; else echo -e "[\e[91m NO \e[0m]";fi
echo -e -n "Reboot when finish build : "; if [ $Reboot = "YES" ];then echo -e "[\e[92m YES \e[0m]"; else echo -e "[\e[91m NO \e[0m]";fi
if [ $Website = "YES" ] && [ ! $Website_port = "80" ]
then
echo -e -n "Html port number $Website_port : \e[38;5;0166mHidden \e[0m"
fi
sleep 1
if [ $Okcash_DEV = "YES" ]
then
wget -q -c https://raw.githubusercontent.com/okcashpro/okcash/master/okcash.pro -O /tmp/okcash.pro
OKcash_v="`cat /tmp/okcash.pro | grep VERSION | awk '{print$3}' | awk '{print $1}' | grep -v '{'`"
rm /tmp/okcash.pro
Comment="(Source from github dev)"
else
OKcash_v=6.9.0.5
Comment="(Release)"
fi
echo -e "\n\e[97mSoftware Release:\e[0m"
echo -e "-----------------"
echo $ident
echo -e "Raspbian Image : v$LSB ($img_v)"
echo -e "Boost : $Boost_v"
echo -e "OpenSSL : $OpenSSL_v"
echo -e "DB Berkeley : $DB_v"
echo -e "Miniupnpc : $Miniupnpc_v"
echo -e "Okcash : $OKcash_v $Comment"
sleep 2
if [ $Bootstrap = "YES" ]
then
echo -e "\n\e[97mBootstrap:\e[0m"
echo -e "----------"
bt_version="`curl -s http://wareck.free.fr/crypto/okcash/bootstrap/bootstrap_v.txt | awk 'NR==1 {print$3;exit}'`"
bt_parts="`curl -s http://wareck.free.fr/crypto/okcash/bootstrap/bootstrap_v.txt | awk 'NR==2 {print$2; exit}'`"
bt_size="`curl -s http://wareck.free.fr/crypto/okcash/bootstrap/bootstrap_v.txt | awk 'NR==3 {print$3; exit}'`"
echo -e "Boostrap.dat : $bt_version ($bt_parts files)"
fi
if [ $Bootstrap = "YES" ] && ! [ -f .pass ]
then
if [ $SOC -le 37 ]
then
echo ""
echo "Due to bootstrap file size increase a lot last month"
echo "Your sdcard is now too small to keep source code."
echo "Option KeepSourceAfterInstall was automaticaly set to NO"
echo "Use a bigger scdard to keep sourcefiles on card after compilation"
echo ""
fi
fi
if ps -ef | grep -v grep | grep okcashd >/dev/null
then
echo -e "\n\e[38;5;166mOKcash daemon is working => shutdown and will restart after install...\e[0m"
okcashd stop | true
sudo /etc/init.d/cron stop >/dev/null
sudo killall -9 okcashd | true
Dw=1
sudo /etc/init.d/cron stop 2>/dev/null || true
if [ "`systemctl is-active watchdog.service`" = "active" ]
then
echo -e "\n\e[93mStopping okcashd watchdog:\e[0m"
sudo systemctl stop watchdog >/dev/null
echo -e "Done."
fi
fi
sleep 1
function prereq_ {
echo -e "\n\e[95mSystem Check:\e[0m"
update_me=0
ntp_i=""
pv_i=""
gcc_i=""
xz_i=""
p7zip_i=""
pwgen_i=""
swap_i=""
xxd=""
echo -e -n "Check PV : "
if ! [ -x "$(command -v pv)" ];then echo -e "[\e[91m NO \e[0m]" && pv_i="pv" && update_me=1;else echo -e "[\e[92m YES \e[0m]";fi
if [ $DietPi_ = "NO" ]
then
echo -e -n "Check NTPD : "
if ! [ -x "$(command -v ntpd)" ];then echo -e "[\e[91m NO \e[0m]" && ntp_i="ntp" && update_me=1;else echo -e "[\e[92m YES \e[0m]";fi
fi
echo -e -n "Check P7ZIP : "
if ! [ -x "$(command -v 7z)" ];then echo -e "[\e[91m NO \e[0m]" && p7zip_i="p7zip-full libbz2-dev liblzma-dev libzip-dev zlib1g-dev" && update_me=1;else echo -e "[\e[92m YES \e[0m]";fi
echo -e -n "Check PWGEN : "
if ! [ -x "$(command -v pwgen)" ];then echo -e "[\e[91m NO \e[0m]" && pwgen_i="pwgen" && update_me=1;else echo -e "[\e[92m YES \e[0m]";fi
if ! [ -x "$(command -v xxd)" ]; then xxd_i="xxd" && update_me=1;fi
if ! [ -x "$(command -v htop)" ];then htop_i="htop" && update_me=1;fi
if ! [[ -f .pass || -x "$(command -v dphys-swapfile)" ]];then swap_i="dphys-swapfile" && update_me=1 ;fi
if [ $Bootstrap = "YES" ]
then
echo -e -n "Check MegaDownload : "
if ! [ -x "$(command -v megadown)" ]
then echo -e "[\e[91m NO \e[0m]"
curl -LJO --silent https://github.com/wareck/megadown/releases/download/v1.0/megadown.tar.bz2
tar xfj megadown.tar.bz2
sudo mv megadown /usr/local/bin
rm megadown.tar.bz2
else
echo -e "[\e[92m YES \e[0m]";fi
fi
sleep 1
if [ $update_me = 1 ]
then
echo -e "\n\e[95mRaspberry update:\e[0m"
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install aptitude -y
sudo apt install pv python-dev build-essential $htop_i $ntp_i $pwgen_i $p7zip_i $swap_i $xxd_i -y
sudo sed -i -e "s/# set const/set const/g" /etc/nanorc
fi
sleep 5
}
function Download_Extract_ {
echo -e "\n\e[95mDownload/Extract Boost Library:\e[0m"
if ! [ -d $MyDir/boost_$Boost_v ]
then
wget -c -q --show-progress http://wareck.free.fr/crypto/okcash/boost_$Boost_v.tar.xz
tar xfJ boost_$Boost_v.tar.xz --checkpoint=.500
fi
echo -e "Done."
echo -e "\n\e[95mDownload/Extract OpenSSL Library:\e[0m"
if ! [ -d $MyDir/openssl-$OpenSSL_v ]
then
wget -c -q --show-progress http://wareck.free.fr/crypto/okcash/openssl-$OpenSSL_v.tar.xz
tar xfJ openssl-$OpenSSL_v.tar.xz --checkpoint=.100
fi
echo -e "Done."
echo -e "\n\e[95mDonwload/Extract Miniupnpc Library:\e[0m"
if ! [ -d $MyDir/miniupnpc-$Miniupnpc_v ]
then
wget -c -q --show-progress http://wareck.free.fr/crypto/okcash/miniupnpc-$Miniupnpc_v.tar.xz
tar xfJ miniupnpc-$Miniupnpc_v.tar.xz --checkpoint=.1
fi
echo -e "Done."
echo -e "\n\e[95mDownload/Extract db-4.8.30.NC Library:\e[0m"
if ! [ -d $MyDir/db-$DB_v ]
then
wget -c -q --show-progress http://wareck.free.fr/crypto/okcash/db-$DB_v.tar.xz
tar xfJ db-$DB_v.tar.xz --checkpoint=.100
fi
echo -e "Done."
echo -e "\n\e[95mDownload OkCash $OKcash_v Source Code:\e[0m"
if ! [ -d $MyDir/okcash ]
then
case $Okcash_DEV in
NO)
git clone -n https://github.com/okcashpro/okcash.git
cd okcash
git reset --hard e5e70de031de21ba570e6c83ae8c25dd6ef211a3
cd ..
;;
YES)
git clone https://github.com/okcashpro/okcash.git
;;
*) echo "Error";;
esac
fi
echo -e "Done."
}
function Build_Dependencies_ {
echo -e "\n\e[95mBuild Openssl $OpenSSL_v.:\e[0m"
cd openssl-$OpenSSL_v
./Configure no-zlib no-shared no-dso no-krb5 no-camellia no-capieng no-cast no-dtls1 no-gost no-gmp no-heartbeats no-idea no-jpake \
no-md2 no-mdc2 no-rc5 no-rdrand no-rfc3779 no-rsax no-sctp no-seed no-sha0 no-static_engine no-whirlpool no-rc2 no-rc4 no-ssl2 no-ssl3 linux-armv4
make depend
make -j$(nproc)
cd ..
echo -e "\n\e[95mBuild DB-$DB_v:\e[0m"
if [ -f /usr/share/man/man3/miniupnpc.3.gz ]; then sudo rm /usr/share/man/man3/miniupnpc.3.gz; fi
cd db-$DB_v
if ! [ -f db48.patch ]
then
wget -c http://wareck.free.fr/crypto/okcash/db48.patch
#patching db4.8 source for C11 compilation portability
patch --ignore-whitespace -p1 < db48.patch
fi
cd build_unix
../dist/configure --enable-cxx --disable-shared --with-pic
make -j$(nproc)
sudo make install
sudo ln -s /usr/local/BerkeleyDB.4.8/lib/libdb_cxx-4.8.so /usr/lib/ || true
cd .. && cd ..
echo -e "\n\e[95mBuild Boost $Boost_v:\e[0m"
cd boost_$Boost_v
./bootstrap.sh
sudo ./b2 --with-chrono --with-filesystem --with-program_options --with-system --with-thread --with-timer --with-test \
toolset=gcc variant=release link=static threading=multi runtime-link=static install
cd ..
echo -e "\n\e[95mBuild miniupnpc $Miniupnpc_v:\e[0m"
cd miniupnpc-$Miniupnpc_v
make -j$(nproc)
sudo make install
cd ..
echo
echo -e "\n\e[93mAll dependencies were builded...\e[0m"
if ! [ -f .pass ]
then
touch .pass >/dev/null
fi
rm *.tar.xz | true
}
function Build_Okcash_ {
echo -e "\n\e[95mBuild OkCash:\e[0m"
if ps -ef | grep -v grep | grep okcashd >/dev/null
then
sudo bash -c 'sudo /etc/init.d/cron stop'
killall -9 okcashd
sleep 1
fi
cd okcash
cd src
if ! [ -f makefile.arm.patch ]
then
cp $MyDir/files/makefile.arm.patch .
echo -e "\e[97mPatching makefile.arm \e[0m"
patch -p0 <makefile.arm.patch
fi
cd leveldb
make -j$(nproc)
make -j$(nproc) libmemenv.a
cd ..
Totalmem=$(awk '{ printf "%.1f", $2/1024/1024 ; exit}' /proc/meminfo | cut -d. -f1 )
if [ $Totalmem -gt 3 ] # low memory Raspberry reduce GCC speed and memory use, else normal compilation
then
Flag="--param ggc-min-expand=1 --param ggc-min-heapsize=32768"
else
Flag=""
fi
make -j$(nproc) -w -f makefile.arm CXXFLAGS="$Flag" \
OPENSSL_LIB_PATH=$MyDir/openssl-$OpenSSL_v OPENSSL_INCLUDE_PATH=$MyDir/openssl-$OpenSSL_v/include BDB_INCLUDE_PATH=/usr/local/BerkeleyDB.4.8/include/ \
BDB_LIB_PATH=/usr/local/BerkeleyDB.4.8/lib BOOST_LIB_PATH=/usr/local/lib/ BOOST_INCLUDE_PATH=/usr/local/include/boost/ \
MINIUPNPC_INCLUDE_PATH=/usr/include/miniupnpc MINIUPNPC_LIB_PATH=/usr/lib/
sudo cp okcashd /usr/local/bin ||true
sudo strip /usr/local/bin/okcashd ||true
}
function conf_ {
echo -e "\n\e[95mInstall okcash.conf:\e[0m"
if ! [ -f /home/$MyUser/.okcash/okcash.conf ]
then
if ! [ -d /home/$MyUser/.okcash/ ]; then mkdir /home/$MyUser/.okcash/ ; fi
touch /home/$MyUser/.okcash/okcash.conf
cat <<'EOF'>> /home/$MyUser/.okcash/okcash.conf
#Daemon and listen ON/OFF
daemon=1
listen=1
staking=1
enableaccounts=1
maxconnections=15
#Connection User and Password
rpcuser=user
rpcpassword=password
#Authorized IPs
rpcallowip=127.0.0.1
rpcport=drpc_port
port=dudp_port
#write the location for this blockchain below if not on standard directory
#datadir=/home/USER/.okcash
#Add extra Nodes
addnode=103.81.194.78
addnode=104.229.10.238
addnode=108.61.197.20
addnode=121.200.29.57
addnode=13.209.243.246
addnode=13.209.60.161
addnode=136.143.149.184
addnode=137.186.12.70
addnode=146.212.70.130
addnode=154.16.192.76
addnode=172.93.132.172
addnode=185.159.157.44
addnode=185.224.134.45
addnode=189.174.136.225
addnode=189.40.108.199
addnode=200.217.138.157
addnode=212.102.54.166
addnode=213.232.87.62
addnode=23.227.150.229
addnode=23.97.222.172
addnode=34.126.107.138
addnode=34.80.252.109
addnode=34.81.157.246
addnode=45.82.164.199
addnode=67.218.240.215
addnode=84.247.48.166
addnode=86.45.85.176
addnode=91.139.203.62
addnode=97.123.83.144
addnode=98.250.175.53
EOF
rpcu=$(pwgen -ncsB 18 1) #gen random user
rpcp=$(pwgen -ncsB 18 1) #gen random password
sed -i -e "s/rpcuser=user/rpcuser=$rpcu/g" /home/$MyUser/.okcash/okcash.conf
sed -i -e "s/rpcpassword=password/rpcpassword=$rpcp/g" /home/$MyUser/.okcash/okcash.conf
sed -i -e "s/drpc_port/$drpc_port/g" /home/$MyUser/.okcash/okcash.conf
sed -i -e "s/dudp_port/$dudp_port/g" /home/$MyUser/.okcash/okcash.conf
else
echo -e "File okcash.conf already setup."
fi
echo "Done."
}
function Bootstrap_ {
badsum=0
echo -e "\n\e[95mDownload Bootstrap $bt_version ( $bt_parts x $bt_size Mo ):\e[0m"
folder="bootstrap"
cd /home/$MyUser
LN=5 #Start line number
for i in `seq 1 $bt_parts`;
do
bootstrap_address=$(curl -s http://wareck.free.fr/crypto/okcash/bootstrap/bootstrap_v.txt | head -$LN | tail -1)
megadown $bootstrap_address
LN=$((LN+1))
done
echo -e ""
for i in `seq -w 001 $bt_parts`;
do
wget -c -q --show-progress http://wareck.free.fr/crypto/okcash/bootstrap/bootstrap.$i.md5
done
echo -e "Done."
echo -e "\n\e[95mBootstrap checksum test:\e[0m"
for i in `seq -w 001 $bt_parts`;
do
echo -e -n "Bootstrap.$i.md5 md5sum Test: " && if md5sum --status -c bootstrap.$i.md5; then echo -e "[\e[92m OK \e[0m]"; else echo -e "[\e[91m NO \e[0m]" && badsum=1 ;fi
if [ $badsum = "1" ]
then
echo -e "\e[38;5;166mBootstrap.7z error !\e[0m"
echo -e "\e[38;5;166mMaybe file damaged or not fully download\e[0m"
echo -e "\e[38;5;166mRestart build_node to try again !\e[0m"
exit
fi
done
rm bootstrap.*.md5
if [ -f ~/.okcash/blk0001.dat ]
then
echo -e "\n\e[95mClean old data before extract:\e[0m"
rm -r -f ~/.okcash/blk0001.dat
rm -r -f ~/.okcash/database
rm -r -f ~/.okcash/txleveldb
rm -r -f ~/.okcash/peers.dat
rm -r -f ~/.okcash/smsg*
rm -r -f okcashd.pid
echo "Done."
fi
echo -e "\n\e[95mExtract bootstrap.tar.xz:\e[0m"
7za x bootstrap.7z.001
sleep 3
rm bootstrap.7z.*
echo -e "Done."
}
function clean_after_install_ {
echo -e "\n\e[95mCleaning folders:\e[0m"
cd $MyDir
rm boost_$Boost_v.tar.xz || true
rm openssl-$OpenSSL_v.tar.xz ||true
rm miniupnpc-$Miniupnpc_v.tar.xz || true
rm db-4.8.30.NC.tar.xz || true
if [ -f /home/$MyUser/bootstrap.tar.xz ]; then rm /home/$MyUser/bootstrap.tar.xz || true; fi
echo -e "Remove openssl-1.0.2g"
sudo rm -r -f openssl-$OpenSSL_v || true
echo -e "Remove miniupnpc-$Miniupnpc_v."
sudo rm -r -f miniupnpc-$Miniupnpc_v || true
echo -e "Remove db-4.8.30.NC"
sudo rm -r -f db-4.8.30.NC || true
echo -e "Remove db-4.8.30"
sudo rm -r -f db-4.8.30 || true
echo -e "Remove boost_$Boost_v"
sudo rm -r -f boost_$Boost_v || true
if [ -f .pass ]; then rm .pass >/dev/null ;fi
echo "Done."
}
if ! [ -d okcash ]
then
if [ -f .pass ]; then rm .pass >/dev/null ; fi ||true #no okcash source => rebuild dependencies and okcash
fi
function install_website_ {
echo -e "\n\e[95mWebsite Frontend installation:\e[0m"
OSV=$(sed 's/\..*//' /etc/debian_version)
case $OSV in
8)
sudo apt-get install apache2 php5 php5-xmlrpc curl php5-curl -y >/dev/null;;
9)
sudo apt-get install apache2 php7.0 php7.0-xmlrpc curl php7.0-curl -y >/dev/null;;
10)
sudo apt-get install apache2 php7.3 php7.3-xmlrpc curl php7.3-curl -y >/dev/null;;
11)
sudo apt-get install apache2 php7.4 php7.4-xmlrpc php7.4-curl -y >/dev/null;;
*)
echo -e "\e[38;5;166mUnknown system, please use Raspberry Stretch , Jessie, Buster or Bullseye image...\e[0m"
exit 0
;;
esac
cd /var/www/
if ! [ -f /var/www/node_status/php/config.php ]
then
sudo bash -c 'git clone https://github.com/wareck/okcash-node-frontend.git node_status'
sudo bash -c 'sudo cp /var/www/node_status/php/config.sample.php /var/www/node_status/php/config.php'
param1=`cat /home/$MyUser/.okcash/okcash.conf | grep "rpcuser=" | awk -F "=" '{print$2}'`
param2=`cat /home/$MyUser/.okcash/okcash.conf | grep "rpcpassword=" | awk -F "=" '{print$2}'`
cat /var/www/node_status/php/config.php >> /tmp/config.php
sed -i -e "s/rpcuser/$param1/g" /tmp/config.php
sed -i -e "s/rpcpass/$param2/g" /tmp/config.php
sed -i -e "s/myport/$drpc_port/g" /tmp/config.php
if grep "USB Drive for OkCash" /etc/fstab >/dev/null
then
sed -i -e "s/DRV/\/home\/$MyUser\/.okcash/g" /tmp/config.php
else
sed -i -e "s/DRV/\/dev\/root/g" /tmp/config.php
fi
sudo bash -c 'sudo mv /tmp/config.php /var/www/node_status/php/config.php'
if [ ! -f /etc/apache2/sites-enabled/000-default.conf.old ]
then
sudo bash -c 'sudo mv /etc/apache2/sites-enabled/000-default.conf /etc/apache2/sites-enabled/000-default.conf.old'
fi
if [ ! -f /etc/apache2/sites-enabled/001-node_status.conf ]
then
cat <<'EOF'>> /tmp/001-node_status.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/node_status
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
EOF
sed -i -e "s/80/$Website_port/g" /tmp/001-node_status.conf
sudo cp /tmp/001-node_status.conf /etc/apache2/sites-enabled/001-node_status.conf
fi
cd /home/$MyUser
fi
if ! grep "curl -Ssk http://127.0.0.1/stats.php" /etc/crontab >/dev/null
then
sudo bash -c 'echo "" > /dev/null >>/etc/crontab | sudo -s'
sudo bash -c 'echo "#Okcash frontend website" > /dev/null >>/etc/crontab | sudo -s'
sudo bash -c 'form=$(cat "/tmp/node_user") && echo "*/5 * * * * $form curl -Ssk http://127.0.0.1/stats.php > /dev/null" >>/etc/crontab | sudo -s'
sudo bash -c 'form=$(cat "/tmp/node_user") && echo "*/5 * * * * $form curl -Ssk http://127.0.0.1/peercount.php > /dev/null" >>/etc/crontab | sudo -s'
fi
sudo /etc/init.d/apache2 restart >/dev/null
echo -e "Done."
}
function Raspberry-optimisation_ {
echo -e "\n\e[95mRaspberry optimisation \e[97mWatchDog and Autostart:\e[0m"
sudo apt-get install watchdog chkconfig -y >/dev/null
sudo chkconfig watchdog on >/dev/null
sudo /etc/init.d/watchdog start >/dev/null
sudo update-rc.d watchdog enable >/dev/null
if ! [ -f /home/$MyUser/scripts/watchdog_okcash.sh ]
then
if ! [ -d /home/$MyUser/scripts ];then mkdir /home/$MyUser/scripts;fi
cat <<'EOF'>> /home/$MyUser/scripts/watchdog_okcash.sh
#!/bin/bash
if ps -ef | grep -v grep | grep okcashd >/dev/null
then
exit 0
else
okcashd --printtoconsole
exit 0
fi
EOF
fi
chmod +x /home/$MyUser/scripts/watchdog_okcash.sh
echo -e "Done."
echo -e "\n\e[95mRaspberry optimisation \e[97mEnabling/tunning Watchdog:\e[0m"
sudo bash -c 'sed -i -e "s/#watchdog-device/watchdog-device/g" /etc/watchdog.conf'
sudo bash -c 'sed -i -e "s/#interval = 1/interval = 4/g" /etc/watchdog.conf'
sudo bash -c 'sed -i -e "s/#max-load-1 = 24/max-load-1 = 24/g" /etc/watchdog.conf'
sudo bash -c 'sed -i -e "s/#max-load-5 = 18/watchdog-timeout = 15/g" /etc/watchdog.conf'
sudo bash -c 'sed -i -e "s/#RuntimeWatchdogSec=0/RuntimeWatchdogSec=14/g" /etc/systemd/system.conf'
if ! [ -f /etc/modprobe.d/bcm2835_wdt.conf ]
then
sudo bash -c 'touch /etc/modprobe.d/bcm2835_wdt.conf'
sudo bash -c 'echo "alias char-major-10-130 bcm2835_wdt" /etc/modprobe.d/bcm2835_wdt.conf'
sudo bash -c 'echo "alias char-major-10-131 bcm2835_wdt" /etc/modprobe.d/bcm2835_wdt.conf'
sudo bash -c 'echo "bcm2835_wdt" >>/etc/modules'
fi
echo -e "Done."
echo -e "\n\e[95mRaspberry optimisation \e[97mWatchdog.sh & crontab:\e[0m"
if ! grep "watchdog_okcash.sh" /etc/crontab >/dev/null
then
sudo bash -c 'echo "" >>/etc/crontab | sudo -s'
sudo bash -c 'echo "#okcash watchdog" >>/etc/crontab | sudo -s'
sudo bash -c 'form=$(cat "/tmp/node_user") && echo "*/15 * * * * $form /home/$form/scripts/watchdog_okcash.sh" >>/etc/crontab'
fi
echo "Done."
if [ $DietPi_ = "NO" ]
then
echo -e "\n\e[95mRaspberry optimisation \e[97mDisable Blueutooth:\e[0m"
if ! grep "dtoverlay=pi3-disable-bt" /boot/config.txt >/dev/null
then
sudo bash -c 'echo "" >>/boot/config.txt'
sudo bash -c 'echo "# Disable internal BT" >>/boot/config.txt'
sudo bash -c 'echo "dtoverlay=pi3-disable-bt" >>/boot/config.txt'
sudo systemctl disable hciuart >/dev/null
sleep 1
fi
echo -e "Done."
fi
echo -e "\n\e[95mRaspberry optimisation \e[97mDisable Audio:\e[0m"
if grep "dtparam=audio=on" /boot/config.txt >/dev/null
then
sudo bash -c 'sed -i -e "s/dtparam=audio=on/dtparam=audio=off/g" /boot/config.txt'
fi
echo -e "Done."
echo -e "\n\e[95mRaspberry optimisation \e[97mDisable Console blank:\e[0m"
if ! grep "consoleblank=0" /boot/cmdline.txt >/dev/null
then
sudo bash -c 'sed -i -e "s/rootwait/rootwait consoleblank=0/g" /boot/cmdline.txt'
fi
echo -e "Done."
echo -e "\n\e[95mRaspberry optimisation \e[97mDisable wifi power saving:\e[0m"
if ! grep "#Disable wifi power saving" /etc/rc.local >/dev/null
then
sudo bash -c 'sed -i -e "s/exit 0//g" /etc/rc.local'
sudo bash -c 'echo "#Disable wifi power saving" >>/etc/rc.local'
sudo bash -c 'echo "/sbin/iwconfig wlan0 power off" >>/etc/rc.local'
sudo bash -c 'echo "exit 0" >>/etc/rc.local'
fi
echo -e "Done."
if [ $Ipv6 = "NO" ]
then
echo -e "\n\e[95mRaspberry optimisation \e[97mDisable ipv6:\e[0m"
if ! grep "#Disable ipv6" /etc/sysctl.conf >/dev/null
then
cp /etc/sysctl.conf /tmp
cat <<'EOF'>> /tmp/sysctl.conf
#Disable ipv6
net.ipv6.conf.all.disable_ipv6=1
net.ipv6.conf.default.disable_ipv6=1
net.ipv6.conf.lo.disable_ipv6=1
net.ipv6.conf.eth0.disable_ipv6 = 1
EOF
sudo cp /tmp/sysctl.conf /etc/sysctl.conf
fi
echo -e "Done."
fi
}
function mkswap {
if [ $DietPi_ = "NO" ]
then
echo -e "\n\e[95mRaspberry optimisation \e[97m Disable Swap:\e[0m"
sudo dphys-swapfile swapoff > /dev/null
sudo dphys-swapfile uninstall > /dev/null
sudo systemctl disable dphys-swapfile > /dev/null
if [ -f /var/swap ]; then sudo rm /var/swap ; fi
sudo apt-get purge -y dphys-swapfile > /dev/null
echo -e "Done."
fi
}
function auto_start_ {
echo -e "\n\e[95mOkcash autostart \e[0m"
if ! [ -f /etc/rc.local ]
then
cat <<'EOF'>>/tmp/rc.local
#!/bin/bash
exit 0
EOF
sudo cp /tmp/rc.local /etc/
sudo chmod +x /etc/rc.local
sudo systemctl disable rc-local
sudo systemctl disable rc.local
if ! [ -f /lib/systemd/system/rc-local.service ]
then
cat <<'EOF'>> /tmp/rc-local.service
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
# This unit gets pulled automatically into multi-user.target by
# systemd-rc-local-generator if /etc/rc.local is executable.
[Unit]
Description=/etc/rc.local Compatibility
ConditionFileIsExecutable=/etc/rc.local
After=network.target
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
RemainAfterExit=yes
GuessMainPID=no
EOF
sudo cp /tmp/rc-local.service /lib/systemd/system/rc-local.service
sudo systemctl daemon-reload
fi
else
if ! grep "#OKcash Node Start" /etc/rc.local >/dev/null
then
sudo bash -c 'sed -i -e "s/exit 0//g" /etc/rc.local'
sudo bash -c 'echo "#OKcash Node Start" >>/etc/rc.local'
sudo bash -c 'form=$(cat "/tmp/node_user") && echo -e "su - $form -c \x27okcashd --printtoconsole\x27" >>/etc/rc.local'
sudo bash -c 'echo "exit 0" >>/etc/rc.local'
fi
fi
echo -e "Done."
}
function banner_ {
if [ $DietPi_ = "NO" ]
then
echo -e "\n\e[95mInstall banner message:\e[0m"
ident=$(tr -d '\0' </proc/device-tree/model)
if [ -f /tmp/motd ]; then rm /tmp/motd ;fi
cat <<EOF>> /tmp/motd
_____ _
| | |___ _| |___
| | | | . | . | -_|
|_|___|___|___|___|
Okcash node v$Version
$ident
EOF
sudo bash -c 'mv /tmp/motd /etc/motd | sudo -s'
if grep "raspberrypi" /etc/hostname >/dev/null;then sudo sed -i -e "s/raspberrypi/Node/g" /etc/hostname ;fi
if grep "raspberrypi" /etc/hosts >/dev/null;then sudo sed -i -e "s/raspberrypi/Node/g" /etc/hosts;fi
echo -e "Done."
fi
}
function Firewall_ {
echo -e "\n\e[95mFirewall setup :\e[0m"
sudo apt-get -y install ufw libapache2-mod-security2
if [ $Website = "YES" ]
then
echo "Hidding Apache Server Name"
sudo sed -i -e "s/ServerTokens OS//g" /etc/apache2/conf-enabled/security.conf
sudo sed -i -e "s/ServerTokens Full//g" /etc/apache2/conf-enabled/security.conf
if ! grep "ServerTokens Full" /etc/apache2/conf-enabled/security.conf >/dev/null
then
sudo bash -c 'echo "ServerTokens Full" >>/etc/apache2/conf-enabled/security.conf'
fi
if ! grep "SecServerSignature Karma/2.0.1" /etc/apache2/conf-enabled/security.conf >/dev/null
then
sudo bash -c 'echo "SecServerSignature Karma/2.0.1" >>/etc/apache2/conf-enabled/security.conf'
fi
fi
if [ -f /tmp/ufw ]; then sudo rm /tmp/ufw ;fi
sudo cp /etc/default/ufw /tmp/ufw
sudo chown $USER /tmp/ufw
if [ $Ipv6 = "NO" ]
then
sudo sed -i '/IPV6=/d' /tmp/ufw
sudo echo "IPV6=no" >> /tmp/ufw
fi
sudo chmod 644 /tmp/ufw
sudo chown root:root /tmp/ufw
sudo cp /tmp/ufw /etc/default/ufw
sudo /etc/init.d/ufw restart
sleep 1
echo -e "\e[33mOpening up Port 22 TCP for SSH:\e[0m"
sudo ufw allow 22/tcp || true
echo -e "\e[33mOpening up Port $drpc_port/$dudp_port for Okcash daemon:\e[0m"
sudo ufw allow $drpc_port,$dudp_port/tcp || true
if [ $Website = "YES" ]
then
echo -e "\e[33mOpening up Port $Website_port for website frontpage:\e[0m"
sudo ufw allow $Website_port/tcp || true
fi
echo -e ""
sudo ufw status verbose || true
sudo ufw --force enable || true
echo -e "Done."
}
############
# Main loop#
############
if ! [ -f .pass ]
then
prereq_
mkswap
Download_Extract_
Build_Dependencies_
else
echo -e "\nDependencies were already builded..."
echo -e "Remove file \x22.pass\x22 to restart build..."
sleep 1
fi
if ! [[ -x "$(command -v pv)" || -x "$(command -v ntpd)" || -x "$(command -v lrzip)" || -x "$(command -v pwgen)" || -x "$(command -v htop)" ]]
then
prereq_
fi
sudo ldconfig
Build_Okcash_
conf_
if [ $Website = "YES" ];then install_website_ ;fi
if [ $RemoveTarball = "YES" ]; then clean_after_install_;fi
if [ $Raspi_optimize = "YES" ]
then
Raspberry-optimisation_
sudo /etc/init.d/cron stop >/dev/null #add this to prevent accidental restart during bootstrap download process
fi
if [ $Bootstrap = "YES" ] ; then Bootstrap_ ;fi
if [ $AutoStart = "YES" ]; then auto_start_ ;fi
if [ $Firewall = "YES" ] ; then Firewall_ ;fi
if [ $Banner = "YES" ] ; then banner_ ;fi
echo -e "\n\e[97mBuild is finished !!!\e[0m"
if [ $Raspi_optimize = "YES" ];then echo -e "\e[92mRaspberry was optimized : need to reboot ...\e[0m";fi
if [ ! $Website_port = "80" ]
then
_IP=$(hostname -I) || true
echo -e "\e[92mHtml frontend hidden use http://${_IP::-1}:$Website_port to check the webpage \e[0m"
fi
echo -e "\nwareck@gmail.com\n"
echo -e "Donate:"
echo -e "OKcash: PH3JcR9inEeNZD6gNoLDYwaPAFpgjmrbue"
echo -e "Bitcoin: 1Pu12Wimuy6n7csyHkEjZXGXnAQzKBwSBp"
echo -e "Litecoin: M84U8YggaJ7T5E3TcqgcoF2BCTaxBMbCvN"
echo -e ""
if [ $Dw = 1 ]
then
okcashd
sudo bash -c 'sudo /etc/init.d/cron restart >/dev/null'
fi
if [ $Raspi_optimize = "YES" ]
then
if [ $Reboot = "YES" ]
then
echo -e "Reboot in 10 seconds (CRTL+C to abord):"
for i in {10..1}
do
echo -e -n "$i "
sleep 1
done
echo -e "\n\n"
sudo reboot
fi
else
sleep 5
fi