forked from mempool/mempool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install
executable file
·2065 lines (1724 loc) · 77.4 KB
/
install
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
#!/usr/bin/env zsh
set -e
echo -n "Initializing..."
case `uname -s` in
FreeBSD)
OS=FreeBSD
NPROC=$(sysctl hw.ncpu | awk '{print $2}')
;;
Linux)
if [ "$(grep -Ei 'debian|buntu|mint' /etc/*release)" ]; then
OS=Debian
NPROC=$(nproc --all)
else
echo "Your distribution of Linux is not yet supported by this installation script"
exit 1
fi
;;
*)
echo "Unsupported OS"
exit 1
;;
esac
########################################
##### mempool installation options #####
########################################
# tor onion and clearnet hostname
TOR_INSTALL=ON
CERTBOT_INSTALL=ON
# install 4 network daemons
BITCOIN_INSTALL=ON
BISQ_INSTALL=ON
ELEMENTS_INSTALL=ON
CLN_INSTALL=ON
# install UNFURL
UNFURL_INSTALL=ON
# configure 4 network instances
BITCOIN_MAINNET_ENABLE=ON
BITCOIN_MAINNET_MINFEE_ENABLE=ON
BITCOIN_TESTNET_ENABLE=ON
BITCOIN_SIGNET_ENABLE=ON
BITCOIN_MAINNET_LIGHTNING_ENABLE=ON
BITCOIN_TESTNET_LIGHTNING_ENABLE=ON
BITCOIN_SIGNET_LIGHTNING_ENABLE=ON
BISQ_MAINNET_ENABLE=ON
ELEMENTS_LIQUID_ENABLE=ON
ELEMENTS_LIQUIDTESTNET_ENABLE=ON
# enable lightmode and disable compaction to fit on 1TB SSD drive
BITCOIN_ELECTRS_INSTALL=ON
BITCOIN_ELECTRS_LIGHT_MODE=ON
BITCOIN_ELECTRS_COMPACTION=OFF
ELEMENTS_ELECTRS_INSTALL=ON
ELEMENTS_ELECTRS_LIGHT_MODE=ON
ELEMENTS_ELECTRS_COMPACTION=OFF
# automaitcally configure firewall
FIREWALL_CONFIGURE=ON
############
# probe OS #
############
HOSTNAME=$(hostname)
# get newest zpool if using zfs
ZPOOL=""
[ "${OS}" = FreeBSD ] && ZPOOL=$(zpool list -H|head -1|cut -f 1)
MD5=md5sum
[ "${OS}" = FreeBSD ] && MD5=md5
##################################################
##### P2P / RPC / HTTP network communication #####
##################################################
# used for bisq and firewall configuration
BITCOIN_MAINNET_P2P_HOST=127.0.0.1
BITCOIN_MAINNET_P2P_PORT=8333
# used for RPC communication
BITCOIN_MAINNET_RPC_HOST=127.0.0.1
BITCOIN_MAINNET_RPC_PORT=8332
# generate random hex string
BITCOIN_RPC_USER=$(head -150 /dev/urandom | ${MD5} | awk '{print $1}')
BITCOIN_RPC_PASS=$(head -150 /dev/urandom | ${MD5} | awk '{print $1}')
# used for firewall configuration
BITCOIN_TESTNET_P2P_HOST=127.0.0.1
BITCOIN_TESTNET_P2P_PORT=18333
# used for RPC communication
BITCOIN_TESTNET_RPC_HOST=127.0.0.1
BITCOIN_TESTNET_RPC_PORT=18332
# used for firewall configuration
BITCOIN_SIGNET_P2P_HOST=127.0.0.1
BITCOIN_SIGNET_P2P_PORT=18333
# used for RPC communication
BITCOIN_SIGNET_RPC_HOST=127.0.0.1
BITCOIN_SIGNET_RPC_PORT=18332
# generate random hex string
BITCOIN_SIGNET_RPC_USER=$(head -150 /dev/urandom | ${MD5} | awk '{print $1}')
BITCOIN_SIGNET_RPC_PASS=$(head -150 /dev/urandom | ${MD5} | awk '{print $1}')
# used by bisq to receive notifications from bitcoin about new blocks
BISQ_BLOCKNOTIFY_HOST=127.0.0.1
BISQ_BLOCKNOTIFY_PORT=5120
# used for firewall configuration
ELEMENTS_LIQUID_P2P_HOST=127.0.0.1
ELEMENTS_LIQUID_P2P_PORT=7042
# used for RPC communication
ELEMENTS_LIQUID_RPC_HOST=127.0.0.1
ELEMENTS_LIQUID_RPC_PORT=7041
# generate random hex string
ELEMENTS_RPC_USER=$(head -150 /dev/urandom | ${MD5} | awk '{print $1}')
ELEMENTS_RPC_PASS=$(head -150 /dev/urandom | ${MD5} | awk '{print $1}')
# set either socket or TCP host/port, not both
#ELECTRS_MAINNET_HTTP_SOCK=/tmp/bitcoin.mainnet.electrs
ELECTRS_MAINNET_HTTP_HOST=127.0.0.1
ELECTRS_MAINNET_HTTP_PORT=3000
# set either socket or TCP host/port, not both
#ELECTRS_LIQUID_HTTP_SOCK=/tmp/elements.liquid.electrs
ELECTRS_LIQUID_HTTP_HOST=127.0.0.1
ELECTRS_LIQUID_HTTP_PORT=3001
# set either socket or TCP host/port, not both
#ELECTRS_TESTNET_HTTP_SOCK=/tmp/bitcoin.testnet.electrs
ELECTRS_TESTNET_HTTP_HOST=127.0.0.1
ELECTRS_TESTNET_HTTP_PORT=3002
# set either socket or TCP host/port, not both
#ELECTRS_SIGNET_HTTP_SOCK=/tmp/bitcoin.testnet.electrs
ELECTRS_SIGNET_HTTP_HOST=127.0.0.1
ELECTRS_SIGNET_HTTP_PORT=3003
# set either socket or TCP host/port, not both
#ELECTRS_LIQUIDTESTNET_HTTP_SOCK=/tmp/bitcoin.testnet.electrs
ELECTRS_LIQUIDTESTNET_HTTP_HOST=127.0.0.1
ELECTRS_LIQUIDTESTNET_HTTP_PORT=3004
# set either socket or TCP host/port, not both
#MEMPOOL_MAINNET_HTTP_SOCK=/tmp/bitcoin.mainnet.mempool
MEMPOOL_MAINNET_HTTP_HOST=127.0.0.1
MEMPOOL_MAINNET_HTTP_PORT=8999
# set either socket or TCP host/port, not both
#MEMPOOL_LIQUID_HTTP_SOCK=/tmp/elements.liquid.mempool
MEMPOOL_LIQUID_HTTP_HOST=127.0.0.1
MEMPOOL_LIQUID_HTTP_PORT=8998
# set either socket or TCP host/port, not both
#MEMPOOL_TESTNET_HTTP_SOCK=/tmp/bitcoin.testnet.mempool
MEMPOOL_TESTNET_HTTP_HOST=127.0.0.1
MEMPOOL_TESTNET_HTTP_PORT=8997
# set either socket or TCP host/port, not both
#MEMPOOL_BISQ_HTTP_SOCK=/tmp/bitcoin.bisq.mempool
MEMPOOL_BISQ_HTTP_HOST=127.0.0.1
MEMPOOL_BISQ_HTTP_PORT=8996
# set either socket or TCP host/port, not both
#MEMPOOL_SIGNET_HTTP_SOCK=/tmp/bitcoin.bisq.mempool
MEMPOOL_SIGNET_HTTP_HOST=127.0.0.1
MEMPOOL_SIGNET_HTTP_PORT=8995
# set either socket or TCP host/port, not both
#MEMPOOL_LIQUIDTESTNET_HTTP_SOCK=/tmp/bitcoin.bisq.mempool
MEMPOOL_LIQUIDTESTNET_HTTP_HOST=127.0.0.1
MEMPOOL_LIQUIDTESTNET_HTTP_PORT=8994
##### OS options, should be automatically detected
case $OS in
FreeBSD)
ROOT_USER=root
ROOT_GROUP=wheel
ROOT_HOME=/root
TOR_CONFIGURATION=/usr/local/etc/tor/torrc
TOR_RESOURCES=/var/db/tor
TOR_PKG=tor
TOR_USER=_tor
TOR_GROUP=_tor
NGINX_USER=www
NGINX_GROUP=www
NGINX_ETC_FOLDER=/usr/local/etc/nginx
NGINX_CONFIGURATION=/usr/local/etc/nginx/nginx.conf
CERTBOT_PKG=py39-certbot
CLN_PKG=c-lightning
;;
Debian)
ROOT_USER=root
ROOT_GROUP=root
ROOT_HOME=/root
TOR_CONFIGURATION=/etc/tor/torrc
TOR_RESOURCES=/var/lib/tor
TOR_PKG=tor
TOR_USER=debian-tor
TOR_GROUP=debian-tor
CERTBOT_PKG=python3-certbot-nginx
NGINX_USER=www-data
NGINX_GROUP=www-data
NGINX_ETC_FOLDER=/etc/nginx
NGINX_CONFIGURATION=/etc/nginx/nginx.conf
;;
esac
# where systemd services get installed
DEBIAN_SERVICE_HOME=/etc/systemd/system
# where environment variables for services are set
DEBIAN_ENV_HOME=/etc/default
# where rc.d scripts live
FREEBSD_SERVICE_HOME=/usr/local/etc/rc.d
# mysql data folder and user/group
MYSQL_HOME=/mysql
MYSQL_USER=mysql
MYSQL_GROUP=mysql
# mempool mysql user/password
MEMPOOL_MAINNET_USER='mempool'
MEMPOOL_TESTNET_USER='mempool_testnet'
MEMPOOL_SIGNET_USER='mempool_signet'
MEMPOOL_MAINNET_LIGHTNING_USER='mempool_mainnet_lightning'
MEMPOOL_TESTNET_LIGHTNING_USER='mempool_testnet_lightning'
MEMPOOL_SIGNET_LIGHTNING_USER='mempool_signet_lightning'
MEMPOOL_LIQUID_USER='mempool_liquid'
MEMPOOL_LIQUIDTESTNET_USER='mempool_liquidtestnet'
MEMPOOL_BISQ_USER='mempool_bisq'
# generate random hex string
MEMPOOL_MAINNET_PASS=$(head -150 /dev/urandom | ${MD5} | awk '{print $1}')
MEMPOOL_TESTNET_PASS=$(head -150 /dev/urandom | ${MD5} | awk '{print $1}')
MEMPOOL_SIGNET_PASS=$(head -150 /dev/urandom | ${MD5} | awk '{print $1}')
MEMPOOL_MAINNET_LIGHTNING_PASS=$(head -150 /dev/urandom | ${MD5} | awk '{print $1}')
MEMPOOL_TESTNET_LIGHTNING_PASS=$(head -150 /dev/urandom | ${MD5} | awk '{print $1}')
MEMPOOL_SIGNET_LIGHTNING_PASS=$(head -150 /dev/urandom | ${MD5} | awk '{print $1}')
MEMPOOL_LIQUID_PASS=$(head -150 /dev/urandom | ${MD5} | awk '{print $1}')
MEMPOOL_LIQUIDTESTNET_PASS=$(head -150 /dev/urandom | ${MD5} | awk '{print $1}')
MEMPOOL_BISQ_PASS=$(head -150 /dev/urandom | ${MD5} | awk '{print $1}')
# mempool data folder and user/group
MEMPOOL_HOME=/mempool
MEMPOOL_USER=mempool
MEMPOOL_GROUP=mempool
MEMPOOL_MYSQL_CREDENTIALS="${MEMPOOL_HOME}/.mysql_credentials"
# name of Tor hidden service in torrc
MEMPOOL_TOR_HS=mempool
# bitcoin user/group
BITCOIN_USER=bitcoin
BITCOIN_GROUP=bitcoin
# bitcoin core data folder, needs about 300GB
BITCOIN_HOME=/bitcoin
# bitcoin testnet data
BITCOIN_TESTNET_DATA=${BITCOIN_HOME}/testnet3
# bitcoin testnet data
BITCOIN_SIGNET_DATA=${BITCOIN_HOME}/signet
# bitcoin electrs source/binaries
BITCOIN_ELECTRS_HOME=${BITCOIN_HOME}/electrs
# electrs database root
ELECTRS_DATA_ROOT=/electrs
# bitcoin electrs data, needs about 350GB, and uses double that during compaction
ELECTRS_MAINNET_ZPOOL=${ZPOOL}
ELECTRS_MAINNET_DATA=${ELECTRS_DATA_ROOT}/mainnet
# bitcoin testnet electrs database, only a few GB
ELECTRS_TESTNET_ZPOOL=${ZPOOL}
ELECTRS_TESTNET_DATA=${ELECTRS_DATA_ROOT}/testnet
# bitcoin signet electrs database, only a few GB
ELECTRS_SIGNET_ZPOOL=${ZPOOL}
ELECTRS_SIGNET_DATA=${ELECTRS_DATA_ROOT}/signet
# liquid electrs data, needs about 5GB
ELECTRS_LIQUID_ZPOOL=${ZPOOL}
ELECTRS_LIQUID_DATA=${ELECTRS_DATA_ROOT}/liquid
# liquid electrs data, needs about 5GB
ELECTRS_LIQUIDTESTNET_ZPOOL=${ZPOOL}
ELECTRS_LIQUIDTESTNET_DATA=${ELECTRS_DATA_ROOT}/liquidtestnet
# Core Lightning user/group
CLN_USER=cln
CLN_GROUP=cln
# Core Lightning home folder
CLN_HOME=/cln
# bisq user/group
BISQ_USER=bisq
BISQ_GROUP=bisq
# bisq home folder, needs about 1GB
BISQ_HOME=/bisq
# tor HS folder
BISQ_TOR_HS=bisq
# liquid user/group
ELEMENTS_USER=elements
ELEMENTS_GROUP=elements
# liquid home/data/blockchain folder, needs about 10GB
ELEMENTS_HOME=/elements
# electrs db top-level
ELECTRS_HOME=/electrs
# elements electrs source/binaries
ELEMENTS_ELECTRS_HOME=${ELEMENTS_HOME}/electrs
# tor HS folder
LIQUID_TOR_HS=liquid
# minfee user/group
MINFEE_USER=minfee
MINFEE_GROUP=minfee
# minfee core data folder, needs about 30GB
MINFEE_HOME=/minfee
##### git repo settings, shouldn't need changing
MEMPOOL_REPO_URL=https://github.com/mempool/mempool
MEMPOOL_REPO_NAME=mempool
MEMPOOL_REPO_BRANCH=master
MEMPOOL_LATEST_RELEASE=master
BITCOIN_REPO_URL=https://github.com/bitcoin/bitcoin
BITCOIN_REPO_NAME=bitcoin
BITCOIN_REPO_BRANCH=master
#BITCOIN_LATEST_RELEASE=$(curl -s https://api.github.com/repos/bitcoin/bitcoin/releases/latest|grep tag_name|head -1|cut -d '"' -f4)
BITCOIN_LATEST_RELEASE=v25.1
echo -n '.'
BISQ_REPO_URL=https://github.com/bisq-network/bisq
BISQ_REPO_NAME=bisq
BISQ_REPO_BRANCH=master
#BISQ_LATEST_RELEASE=$(curl -s https://api.github.com/repos/bisq-network/bisq/releases/latest|grep tag_name|head -1|cut -d '"' -f4)
BISQ_LATEST_RELEASE=master
echo -n '.'
UNFURL_REPO_URL=https://github.com/mempool/mempool
UNFURL_REPO_NAME=unfurl
UNFURL_REPO_BRANCH=master
#UNFURL_LATEST_RELEASE=$(curl -s https://api.github.com/repos/mempool/mempool/releases/latest|grep tag_name|head -1|cut -d '"' -f4)
UNFURL_LATEST_RELEASE=master
echo -n '.'
ELEMENTS_REPO_URL=https://github.com/ElementsProject/elements
ELEMENTS_REPO_NAME=elements
ELEMENTS_REPO_BRANCH=master
#ELEMENTS_LATEST_RELEASE=$(curl -s https://api.github.com/repos/ElementsProject/elements/releases/latest|grep tag_name|head -1|cut -d '"' -f4)
ELEMENTS_LATEST_RELEASE=elements-22.1.1
echo -n '.'
BITCOIN_ELECTRS_REPO_URL=https://github.com/mempool/electrs
BITCOIN_ELECTRS_REPO_NAME=electrs
BITCOIN_ELECTRS_REPO_BRANCH=mempool
BITCOIN_ELECTRS_LATEST_RELEASE=mempool
ELEMENTS_ELECTRS_REPO_URL=https://github.com/mempool/electrs
ELEMENTS_ELECTRS_REPO_NAME=electrs
ELEMENTS_ELECTRS_REPO_BRANCH=mempool
ELEMENTS_ELECTRS_LATEST_RELEASE=mempool
LIQUID_ASSET_REGISTRY_DB_URL=https://github.com/blockstream/asset_registry_db
LIQUID_ASSET_REGISTRY_DB_NAME=asset_registry_db
LIQUIDTESTNET_ASSET_REGISTRY_DB_URL=https://github.com/blockstream/asset_registry_testnet_db
LIQUIDTESTNET_ASSET_REGISTRY_DB_NAME=asset_registry_testnet_db
#######################
##### OS packages #####
#######################
# packages needed for mempool ecosystem
DEBIAN_PKG=()
DEBIAN_PKG+=(zsh vim curl screen openssl python3 dialog cron)
DEBIAN_PKG+=(build-essential git git-lfs clang cmake jq)
DEBIAN_PKG+=(autotools-dev autoconf automake pkg-config bsdmainutils)
DEBIAN_PKG+=(libevent-dev libdb-dev libssl-dev libtool autotools-dev)
DEBIAN_PKG+=(libboost-system-dev libboost-filesystem-dev libboost-chrono-dev libboost-test-dev libboost-thread-dev)
DEBIAN_PKG+=(nodejs npm mariadb-server nginx-core python3-certbot-nginx rsync ufw)
DEBIAN_PKG+=(geoipupdate)
DEBIAN_UNFURL_PKG=()
DEBIAN_UNFURL_PKG+=(cups chromium-bsu libatk1.0 libatk-bridge2.0 libxkbcommon-dev libxcomposite-dev)
DEBIAN_UNFURL_PKG+=(libxdamage-dev libxrandr-dev libgbm-dev libpango1.0-dev libasound-dev)
# packages needed for mempool ecosystem
FREEBSD_PKG=()
FREEBSD_PKG+=(zsh sudo git git-lfs screen curl wget calc neovim)
FREEBSD_PKG+=(openssh-portable py39-pip rust llvm10 jq base64 libzmq4)
FREEBSD_PKG+=(boost-libs autoconf automake gmake gcc libevent libtool pkgconf)
FREEBSD_PKG+=(nginx rsync py39-certbot-nginx mariadb1011-server keybase)
FREEBSD_PKG+=(geoipupdate redis)
FREEBSD_UNFURL_PKG=()
FREEBSD_UNFURL_PKG+=(nvidia-driver-470 chromium xinit xterm twm ja-sourcehansans-otf)
FREEBSD_UNFURL_PKG+=(zh-sourcehansans-sc-otf ko-aleefonts-ttf lohit tlwg-ttf)
#############################
##### utility functions #####
#############################
osSudo()
{
SUDO_USER=$1
shift
case $OS in
FreeBSD)
sudo -H -i -u "${SUDO_USER}" $*
;;
Debian)
sudo -H -i -u "${SUDO_USER}" $*
;;
esac
}
osPackageUpdate()
{
echo "[*] Updating OS sources"
case $OS in
FreeBSD)
pkg update
;;
Debian)
osSudo "${ROOT_USER}" DEBIAN_FRONTEND=noninteractive apt-get update -q
;;
esac
}
osPackageUpgrade()
{
echo "[*] Upgrading OS packages $*"
case $OS in
FreeBSD)
pkg upgrade -y $*
;;
Debian)
osSudo "${ROOT_USER}" DEBIAN_FRONTEND=noninteractive apt-get upgrade -qq -y $*
;;
esac
}
osPackageInstall()
{
echo "[*] Installing OS packages $*"
case $OS in
FreeBSD)
pkg install -y $*
;;
Debian)
osSudo "${ROOT_USER}" DEBIAN_FRONTEND=noninteractive apt-get install -qq -y $*
;;
esac
}
osPackageInstallAll()
{
case $OS in
FreeBSD)
osPackageInstall ${FREEBSD_PKG[@]}
;;
Debian)
osPackageInstall ${DEBIAN_PKG[@]}
;;
esac
}
# osUserCreate username home_directory main_groupname [additional_group]
osUserCreate()
{
case $OS in
FreeBSD)
# pw useradd -d /mempool -g mempool [-G additional_group] -n mampool
if [ $# -eq 3 ] ; then
osSudo "${ROOT_USER}" pw useradd -d "$2" -g "$3" -n "$1"
elif [ $# -eq 4 ]; then
osSudo "${ROOT_USER}" pw useradd -d "$2" -g "$3" -G "$4" -n "$1"
else
echo "Illegal number of parameters"
exit 1
fi
;;
Debian)
# useradd -d /mempool -g mempool [-G additional_group] mempool
if [ $# -eq 3 ] ; then
osSudo "${ROOT_USER}" useradd -d "$2" -g "$3" "$1"
elif [ $# -eq 4 ]; then
osSudo "${ROOT_USER}" useradd -d "$2" -g "$3" -G "$4" "$1"
else
echo "Illegal number of parameters"
exit 1
fi
;;
esac
}
osGroupCreate()
{
case $OS in
FreeBSD)
osSudo "${ROOT_USER}" pw groupadd $*
;;
Debian)
osSudo "${ROOT_USER}" groupadd $*
;;
esac
}
osCertbotDryRun()
{
if [ ! -z "${HOSTNAME}" ];then
case $OS in
FreeBSD)
osPackageInstall "${FREEBSD_PKG_CERTBOT}"
;;
Debian)
osPackageInstall "${DEBIAN_PKG_CERTBOT}"
;;
esac
certbot certonly --dry-run --standalone --agree-tos --register-unsafely-without-email -d "${HOSTNAME}"
fi
}
zfsCreateFilesystems()
{
zfs create -o "mountpoint=/backup" "${ZPOOL}/backup"
zfs create -o "mountpoint=/var/cache/nginx" "${ZPOOL}/cache"
zfs create -o "mountpoint=${ELEMENTS_HOME}" "${ZPOOL}/elements"
zfs create -o "mountpoint=${BITCOIN_HOME}" "${ZPOOL}/bitcoin"
zfs create -o "mountpoint=${MINFEE_HOME}" "${ZPOOL}/minfee"
zfs create -o "mountpoint=${ELECTRS_HOME}" "${ZPOOL}/electrs"
zfs create -o "mountpoint=${MEMPOOL_HOME}" "${ZPOOL}/mempool"
zfs create -o "mountpoint=${MYSQL_HOME}" "${ZPOOL}/mysql"
zfs create -o "mountpoint=${BITCOIN_ELECTRS_HOME}" "${ZPOOL}/bitcoin/electrs"
zfs create -o "mountpoint=${ELEMENTS_HOME}/liquidv1" "${ZPOOL}/elements/liquidv1"
zfs create -o "mountpoint=${ELEMENTS_ELECTRS_HOME}" "${ZPOOL}/elements/electrs"
# create /bitcoin/socket with custom ACL for electrs unix sockets
zfs create -o "mountpoint=${BITCOIN_HOME}/socket" "${ZPOOL}/bitcoin/socket"
# create /elements/socket with custom ACL for electrs unix sockets
zfs create -o "mountpoint=${ELEMENTS_HOME}/socket" "${ZPOOL}/elements/socket"
# Bitcoin Mainnet
if [ "${BITCOIN_MAINNET_ENABLE}" = ON ];then
for folder in chainstate indexes blocks
do
zfs create -o "mountpoint=${BITCOIN_HOME}/${folder}" "${ZPOOL}/bitcoin/${folder}"
done
fi
# Bitcoin Testnet
if [ "${BITCOIN_TESTNET_ENABLE}" = ON ];then
zfs create -o "mountpoint=${BITCOIN_TESTNET_DATA}" "${ZPOOL}/bitcoin/testnet"
for folder in chainstate indexes blocks
do
zfs create -o "mountpoint=${BITCOIN_TESTNET_DATA}/${folder}" "${ZPOOL}/bitcoin/testnet/${folder}"
done
fi
# Bitcoin Signet
if [ "${BITCOIN_SIGNET_ENABLE}" = ON ];then
zfs create -o "mountpoint=${BITCOIN_SIGNET_DATA}" "${ZPOOL}/bitcoin/signet"
for folder in chainstate indexes blocks
do
zfs create -o "mountpoint=${BITCOIN_SIGNET_DATA}/${folder}" "${ZPOOL}/bitcoin/signet/${folder}"
done
fi
# electrs mainnet data
if [ "${BITCOIN_MAINNET_ENABLE}" = ON ];then
zfs create -o "mountpoint=${ELECTRS_MAINNET_DATA}" "${ELECTRS_MAINNET_ZPOOL}/electrs/mainnet"
for folder in cache history txstore
do
zfs create -o "mountpoint=${ELECTRS_MAINNET_DATA}/newindex/${folder}" "${ELECTRS_MAINNET_ZPOOL}/electrs/mainnet/${folder}"
done
fi
# electrs testnet data
if [ "${BITCOIN_TESTNET_ENABLE}" = ON ];then
zfs create -o "mountpoint=${ELECTRS_TESTNET_DATA}" "${ELECTRS_TESTNET_ZPOOL}/electrs/testnet"
for folder in cache history txstore
do
zfs create -o "mountpoint=${ELECTRS_TESTNET_DATA}/newindex/${folder}" "${ELECTRS_TESTNET_ZPOOL}/electrs/testnet/${folder}"
done
fi
# electrs signet data
if [ "${BITCOIN_SIGNET_ENABLE}" = ON ];then
zfs create -o "mountpoint=${ELECTRS_SIGNET_DATA}" "${ELECTRS_SIGNET_ZPOOL}/electrs/signet"
for folder in cache history txstore
do
zfs create -o "mountpoint=${ELECTRS_SIGNET_DATA}/newindex/${folder}" "${ELECTRS_SIGNET_ZPOOL}/electrs/signet/${folder}"
done
fi
# electrs liquid data
if [ "${ELEMENTS_LIQUID_ENABLE}" = ON ];then
zfs create -o "mountpoint=${ELECTRS_LIQUID_DATA}" "${ELECTRS_LIQUID_ZPOOL}/electrs/liquid"
for folder in cache history txstore
do
zfs create -o "mountpoint=${ELECTRS_LIQUID_DATA}/newindex/${folder}" "${ELECTRS_LIQUID_ZPOOL}/electrs/liquid/${folder}"
done
fi
# electrs liquidtestnet data
if [ "${ELEMENTS_LIQUIDTESTNET_ENABLE}" = ON ];then
zfs create -o "mountpoint=${ELECTRS_LIQUIDTESTNET_DATA}" "${ELECTRS_LIQUIDTESTNET_ZPOOL}/electrs/liquidtestnet"
for folder in cache history txstore
do
zfs create -o "mountpoint=${ELECTRS_LIQUIDTESTNET_DATA}/newindex/${folder}" "${ELECTRS_LIQUIDTESTNET_ZPOOL}/electrs/liquidtestnet/${folder}"
done
fi
if [ "${CLN_INSTALL}" = ON ];then
zfs create -o "mountpoint=${CLN_HOME}" "${ZPOOL}/cln"
fi
if [ "${BISQ_INSTALL}" = ON ];then
zfs create -o "mountpoint=${BISQ_HOME}" "${ZPOOL}/bisq"
fi
}
ext4CreateDir()
{
mkdir -p "/backup" "${ELEMENTS_HOME}" "${BITCOIN_HOME}" "${MINFEE_HOME}" "${ELECTRS_HOME}" "${MEMPOOL_HOME}" "${MYSQL_HOME}" "${BITCOIN_ELECTRS_HOME}" "${ELEMENTS_HOME}/liquidv1" "${ELEMENTS_ELECTRS_HOME}"
# Bitcoin Mainnet
if [ "${BITCOIN_MAINNET_ENABLE}" = ON ];then
for folder in chainstate indexes blocks
do
mkdir -p "${BITCOIN_HOME}/${folder}"
done
fi
# Bitcoin Testnet
if [ "${BITCOIN_TESTNET_ENABLE}" = ON ];then
mkdir -p "${BITCOIN_TESTNET_DATA}"
for folder in chainstate indexes blocks
do
mkdir -p "${BITCOIN_TESTNET_DATA}/${folder}"
done
fi
# Bitcoin Signet
if [ "${BITCOIN_SIGNET_ENABLE}" = ON ];then
mkdir -p "${BITCOIN_SIGNET_DATA}"
for folder in chainstate indexes blocks
do
mkdir -p "${BITCOIN_SIGNET_DATA}/${folder}"
done
fi
# electrs mainnet data
if [ "${BITCOIN_MAINNET_ENABLE}" = ON ];then
mkdir -p "${ELECTRS_MAINNET_DATA}"
for folder in cache history txstore
do
mkdir -p "${ELECTRS_MAINNET_DATA}/newindex/${folder}"
done
fi
# electrs testnet data
if [ "${BITCOIN_TESTNET_ENABLE}" = ON ];then
mkdir -p "${ELECTRS_TESTNET_DATA}"
for folder in cache history txstore
do
mkdir -p "${ELECTRS_TESTNET_DATA}/newindex/${folder}"
done
fi
# electrs signet data
if [ "${BITCOIN_SIGNET_ENABLE}" = ON ];then
mkdir -p "${ELECTRS_SIGNET_DATA}"
for folder in cache history txstore
do
mkdir -p "${ELECTRS_SIGNET_DATA}/newindex/${folder}"
done
fi
# electrs liquid data
if [ "${ELEMENTS_LIQUID_ENABLE}" = ON ];then
mkdir -p "${ELECTRS_LIQUID_DATA}"
for folder in cache history txstore
do
mkdir -p "${ELECTRS_LIQUID_DATA}/newindex/${folder}"
done
fi
# electrs liquidtestnet data
if [ "${ELEMENTS_LIQUIDTESTNET_ENABLE}" = ON ];then
mkdir -p "${ELECTRS_LIQUIDTESTNET_DATA}"
for folder in cache history txstore
do
mkdir -p "${ELECTRS_LIQUIDTESTNET_DATA}/newindex/${folder}"
done
fi
if [ "${CLN_INSTALL}" = ON ];then
mkdir -p "${CLN_HOME}"
fi
if [ "${BISQ_INSTALL}" = ON ];then
mkdir -p "${BISQ_HOME}"
fi
}
##### Perform sanity checks before trying anything
# what OS running, what FS partitions, etc.
# how much free disk space available?
# is something listening on port 80 already?
# is nginx or apache running?
##### Determine what actually needs to be installed
# does bitcoin exist?
##########
# dialog #
##########
: ${DIALOG=dialog}
: ${DIALOG_OK=0}
: ${DIALOG_CANCEL=1}
: ${DIALOG_HELP=2}
: ${DIALOG_EXTRA=3}
: ${DIALOG_ITEM_HELP=4}
: ${DIALOG_ESC=255}
: ${SIG_OFFNE=0}
: ${SIG_HUP=1}
: ${SIG_INT=2}
: ${SIG_QUIT=3}
: ${SIG_KILL=9}
: ${SIG_TERM=15}
input=`tempfile 2>/dev/null` || input=/tmp/input$$
output=`tempfile 2>/dev/null` || output=/tmp/test$$
trap "rm -f $input $output" $SIG_OFFNE $SIG_HUP $SIG_INT $SIG_TRAP $SIG_TERM
DIALOG_ERROR=254
export DIALOG_ERROR
backtitle="Mempool Fullnode Installer"
title="Mempool Fullnode Installer"
returncode=0
#################
# dialog part 1 #
#################
$CUT >$input <<-EOF
Tor:Enable Tor v3 HS Onion:ON
Mainnet:Enable Bitcoin Mainnet:ON
Mainnet-Minfee:Enable Bitcoin Mainnet Minfee:ON
LN-Mainnet:Enable Bitcoin Mainnet Lightning:ON
LN-Testnet:Enable Bitcoin Testnet Lightning:ON
LN-Signet:Enable Bitcoin Signet Lightning:ON
Testnet:Enable Bitcoin Testnet:ON
Signet:Enable Bitcoin Signet:ON
Liquid:Enable Elements Liquid:ON
Liquidtestnet:Enable Elements Liquidtestnet:ON
CoreLN:Enable Core Lightning:ON
Bisq:Enable Bisq:ON
Unfurl:Enable Unfurl:ON
EOF
cat $input | sed -e 's/^/"/' -e 's/:/" "/g' -e 's/$/"/' >$output
cat $output >$input
$DIALOG --backtitle "${backtitle}" \
--title "${title}" "$@" \
--checklist "Toggle the features below to configure your fullnode:\n" \
20 80 10 \
--file $input 2> $output
retval=$?
tempfile=$output
if [ $retval != $DIALOG_OK ];then
echo "Installation aborted."
exit 1
fi
if grep Tor $tempfile >/dev/null 2>&1;then
TOR_INSTALL=ON
else
TOR_INSTALL=OFF
fi
if grep Mainnet $tempfile >/dev/null 2>&1;then
BITCOIN_MAINNET_ENABLE=ON
else
BITCOIN_MAINNET_ENABLE=OFF
fi
if grep Mainnet-Minfee $tempfile >/dev/null 2>&1;then
BITCOIN_MAINNET_MINFEE_ENABLE=ON
else
BITCOIN_MAINNET_MINFEE_ENABLE=OFF
fi
if grep Testnet $tempfile >/dev/null 2>&1;then
BITCOIN_TESTNET_ENABLE=ON
else
BITCOIN_TESTNET_ENABLE=OFF
fi
if grep Signet $tempfile >/dev/null 2>&1;then
BITCOIN_SIGNET_ENABLE=ON
else
BITCOIN_SIGNET_ENABLE=OFF
fi
if [ "${BITCOIN_MAINNET_ENABLE}" = ON -o "${BITCOIN_MAINNET_MINFEE_ENABLE}" = ON -o "${BITCOIN_TESTNET_ENABLE}" = ON -o "${BITCOIN_SIGNET_ENABLE}" = ON ];then
BITCOIN_INSTALL=ON
else
BITCOIN_INSTALL=OFF
fi
if grep LN-Mainnet $tempfile >/dev/null 2>&1;then
BITCOIN_MAINNET_LIGHTNING_ENABLE=ON
else
BITCOIN_MAINNET_LIGHTNING_ENABLE=OFF
fi
if grep LN-Testnet $tempfile >/dev/null 2>&1;then
BITCOIN_TESTNET_LIGHTNING_ENABLE=ON
else
BITCOIN_TESTNET_LIGHTNING_ENABLE=OFF
fi
if grep LN-Signet $tempfile >/dev/null 2>&1;then
BITCOIN_SIGNET_LIGHTNING_ENABLE=ON
else
BITCOIN_SIGNET_LIGHTNING_ENABLE=OFF
fi
if grep Liquid $tempfile >/dev/null 2>&1;then
ELEMENTS_LIQUID_ENABLE=ON
else
ELEMENTS_LIQUID_ENABLE=OFF
fi
if grep Liquidtestnet $tempfile >/dev/null 2>&1;then
ELEMENTS_LIQUIDTESTNET_ENABLE=ON
else
ELEMENTS_LIQUIDTESTNET_ENABLE=OFF
fi
if [ "${ELEMENTS_LIQUID_ENABLE}" = ON -o "${ELEMENTS_LIQUIDTESTNET_ENABLE}" = ON ];then
ELEMENTS_INSTALL=ON
else
ELEMENTS_INSTALL=OFF
fi
if grep CoreLN $tempfile >/dev/null 2>&1;then
CLN_INSTALL=ON
else
CLN_INSTALL=OFF
fi
if [ "${BITCOIN_MAINNET_ENABLE}" = ON -o "${BITCOIN_TESTNET_ENABLE}" = ON -o "${BITCOIN_SIGNET_ENABLE}" = ON ];then
BITCOIN_ELECTRS_INSTALL=ON
else
BITCOIN_ELECTRS_INSTALL=OFF
fi
if [ "${ELEMENTS_LIQUID_ENABLE}" = ON -o "${ELEMENTS_LIQUIDTESTNET_ENABLE}" = ON ];then
ELEMENTS_ELECTRS_INSTALL=ON
else
ELEMENTS_ELECTRS_INSTALL=OFF
fi
if grep Bisq $tempfile >/dev/null 2>&1;then
BISQ_INSTALL=ON
BISQ_MAINNET_ENABLE=ON
else
BISQ_INSTALL=OFF
BISQ_MAINNET_ENABLE=OFF
fi
if grep Unfurl $tempfile >/dev/null 2>&1;then
UNFURL_INSTALL=ON
else
UNFURL_INSTALL=OFF
fi
##################
## dialog part 2 #
##################
#
#$DIALOG --cr-wrap \
# --title "INPUT BOX" --clear \
# --inputbox "$@" \
#"Enter the FQDN hostname for obtaining an SSL certificate using Certbot:" 0 0 "${HOSTNAME}" 2> $tempfile
#HOSTNAME=$(cat $tempfile)
#
##################
## dialog part 3 #
##################
#
## --form text height width formheight
## [ label y x item y x flen ilen ]
# #"BISQ_BLOCKNOTIFY_HOST" 0 1 "${BISQ_BLOCKNOTIFY_HOST}" 0 30 0 0 \
#
#$DIALOG --ok-label "Submit" \
# --backtitle "$backtitle" "$@" \
# --form "Your fullnode will be installed as follows:" 0 0 0 \
# "BISQ_LATEST_RELEASE" 1 1 "${BISQ_LATEST_RELEASE}" 1 35 35 0 \
# "BISQ_REPO_BRANCH" 2 1 "${BISQ_REPO_BRANCH}" 2 35 35 0 \
# "BISQ_REPO_NAME" 3 1 "${BISQ_REPO_NAME}" 3 35 35 0 \
# "BISQ_REPO_URL" 4 1 "${BISQ_REPO_URL}" 4 35 35 0 \
# "BITCOIN_ELECTRS_LATEST_RELEASE" 5 1 "${BITCOIN_ELECTRS_LATEST_RELEASE}" 5 35 35 0 \
# "BITCOIN_ELECTRS_LIGHT_MODE" 6 1 "${BITCOIN_ELECTRS_LIGHT_MODE}" 6 35 35 0 \
# "BITCOIN_ELECTRS_REPO_BRANCH" 7 1 "${BITCOIN_ELECTRS_REPO_BRANCH}" 7 35 35 0 \
# "BITCOIN_ELECTRS_REPO_NAME" 8 1 "${BITCOIN_ELECTRS_REPO_NAME}" 8 35 35 0 \
# "BITCOIN_ELECTRS_REPO_URL" 9 1 "${BITCOIN_ELECTRS_REPO_URL}" 9 35 35 0 \
# "BITCOIN_LATEST_RELEASE" 10 1 "${BITCOIN_LATEST_RELEASE}" 10 35 35 0 \
# "BITCOIN_MAINNET_ENABLE" 11 1 "${BITCOIN_MAINNET_ENABLE}" 11 35 35 0 \
# "BITCOIN_REPO_BRANCH" 12 1 "${BITCOIN_REPO_BRANCH}" 12 35 35 0 \
# "BITCOIN_REPO_NAME" 13 1 "${BITCOIN_REPO_NAME}" 13 35 35 0 \
# "BITCOIN_REPO_URL" 14 1 "${BITCOIN_REPO_URL}" 14 35 35 0 \
# "BITCOIN_TESTNET_ENABLE" 15 1 "${BITCOIN_TESTNET_ENABLE}" 15 35 35 0 \
# "ELEMENTS_INSTALL" 16 1 "${ELEMENTS_INSTALL}" 16 35 35 0 \
# "ELEMENTS_LATEST_RELEASE" 17 1 "${ELEMENTS_LATEST_RELEASE}" 17 35 35 0 \
# "ELEMENTS_LIQUID_ENABLE" 18 1 "${ELEMENTS_LIQUID_ENABLE}" 18 35 35 0 \
# "ELEMENTS_REPO_BRANCH" 19 1 "${ELEMENTS_REPO_BRANCH}" 19 35 35 0 \
# "ELEMENTS_REPO_NAME" 20 1 "${ELEMENTS_REPO_NAME}" 20 35 35 0 \
# "ELEMENTS_REPO_URL" 21 1 "${ELEMENTS_REPO_URL}" 21 35 35 0 \
# "MEMPOOL_LATEST_RELEASE" 22 1 "${MEMPOOL_LATEST_RELEASE}" 22 35 35 0 \
# "MEMPOOL_LIQUID_HTTP_HOST" 23 1 "${MEMPOOL_LIQUID_HTTP_HOST}" 23 35 35 0 \
# "MEMPOOL_LIQUID_HTTP_PORT" 24 1 "${MEMPOOL_LIQUID_HTTP_PORT}" 24 35 35 0 \
# "MEMPOOL_MAINNET_HTTP_HOST" 25 1 "${MEMPOOL_MAINNET_HTTP_HOST}" 25 35 35 0 \
# "MEMPOOL_MAINNET_HTTP_PORT" 26 1 "${MEMPOOL_MAINNET_HTTP_PORT}" 26 35 35 0 \
# "MEMPOOL_REPO_BRANCH" 27 1 "${MEMPOOL_REPO_BRANCH}" 27 35 35 0 \
# "MEMPOOL_REPO_NAME" 28 1 "${MEMPOOL_REPO_NAME}" 28 35 35 0 \
# "MEMPOOL_REPO_URL" 29 1 "${MEMPOOL_REPO_URL}" 29 35 35 0 \
# "MEMPOOL_TESTNET_HTTP_HOST" 30 1 "${MEMPOOL_TESTNET_HTTP_HOST}" 30 35 35 0 \
# "MEMPOOL_TESTNET_HTTP_PORT" 31 1 "${MEMPOOL_TESTNET_HTTP_PORT}" 31 35 35 0 \
# "MEMPOOL_TOR_HS" 32 1 "${MEMPOOL_TOR_HS}" 32 35 35 0 \
# "HOSTNAME" 33 1 "${HOSTNAME}" 33 35 35 0 \
# "TOR_INSTALL" 34 1 "${TOR_INSTALL}" 34 35 35 0 \
# "CERTBOT_INSTALL" 35 1 "${CERTBOT_INSTALL}" 35 35 35 0 \
#2> $tempfile
#
#retval=$?
#
#if [ $retval != $DIALOG_OK ];then
# echo "Installation aborted."
# exit 1
#fi
############################
# START DOING ACTUAL STUFF #
############################
date
echo "[*] Mempool installation script for ${OS}"
###################################
# create filesystems if necessary #
###################################
case $OS in
FreeBSD)
zfsCreateFilesystems
;;
Debian)
ext4CreateDir
;;
esac
###############################
# Install all the OS packages #
###############################
osPackageUpdate
osPackageUpgrade
osPackageInstallAll
##########################
# Mempool top-level repo #
##########################
echo "[*] Creating Mempool user with Tor access"
osGroupCreate "${MEMPOOL_GROUP}"
osUserCreate "${MEMPOOL_USER}" "${MEMPOOL_HOME}" "${MEMPOOL_GROUP}"