-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodebuilder
More file actions
executable file
·2072 lines (1905 loc) · 79.4 KB
/
nodebuilder
File metadata and controls
executable file
·2072 lines (1905 loc) · 79.4 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
#
# A minimally-interactive script for launching a Bitcoin Core node
set -o errexit
set -o nounset
check_dpkg_lock()
{
if fuser /var/lib/dpkg/lock > /dev/null 2>&1 || fuser /var/lib/dpkg/lock-frontend > /dev/null 2>&1; then
throw_error 'Debian package manager (dpkg) is locked by another process. Try running: ps aux | grep -i apt'
fi
}
check_internet_status()
{
ensure_curl_dependency
log_info 'Checking for internet.'
( (check_internet_to_address 1.1.1.1 ||
check_internet_to_address 1.1.0.0 ||
check_internet_to_address 9.9.9.9 ||
check_internet_to_address 9.9.9.11) &&
check_internet_to_address bitcoincore.org) ||
throw_error 'Internet checks failed.'
log_info 'Internet checks passed.'
}
check_internet_to_address()
{
check_internet_address=$1
readonly CHECK_INTERNET_PORT='443'
readonly CHECK_INTERNET_TIMEOUT_SECONDS='10'
# shellcheck disable=SC2015
command -v torsocks > /dev/null 2>&1 && [ "${TARGET_OPERATING_SYSTEM}" != 'Darwin' ] &&
torsocks curl --silent --output /dev/null --retry 2 --connect-timeout "${CHECK_INTERNET_TIMEOUT_SECONDS}" "https://${check_internet_address}:${CHECK_INTERNET_PORT}" > /dev/null ||
curl --silent --output /dev/null --retry 5 --connect-timeout "${CHECK_INTERNET_TIMEOUT_SECONDS}" "https://${check_internet_address}:${CHECK_INTERNET_PORT}" > /dev/null
}
clear_the_terminal()
{
if [ "${quiet_output}" = 'true' ] || is_running_in_ci || is_running_in_container; then
return
elif [ ! -t 1 ]; then
# stdout is not a terminal perhaps redirected or piped
return
elif command -v clear > /dev/null 2>&1; then
clear
elif command -v tput > /dev/null 2>&1; then
tput clear
else
printf '\033c'
fi
}
compile_bitcoin_from_source()
{
log_info 'Ensuring compile dependencies.'
readonly COMPILE_DIRECTORY="${TEMP_DIRECTORY}/compile_bitcoin"
readonly STDERR_COMPILE_LOG_FILE="${TEMP_DIRECTORY}/stderr_install.log"
install_build_dependencies
log_info 'Downloading Bitcoin source code.'
# shellcheck disable=SC2015
command -v torsocks > /dev/null 2>&1 &&
[ "${TARGET_KERNEL}" != 'Darwin' ] &&
torsocks git clone --branch "v${target_bitcoin_version}" --depth 1 --quiet -c advice.detachedHead=false "${BITCOIN_CORE_REPO}.git" "${COMPILE_DIRECTORY}" 2> /dev/null ||
git clone --branch "v${target_bitcoin_version}" --depth 1 --quiet -c advice.detachedHead=false "${BITCOIN_CORE_REPO}.git" "${COMPILE_DIRECTORY}" 2> /dev/null
cd "${COMPILE_DIRECTORY}"/
log_info 'Configuring the build environment.'
case "${TARGET_OPERATING_SYSTEM}" in
NetBSD)
cmake -B build \
-DWITH_ZMQ=ON \
-DCMAKE_C_COMPILER="/usr/pkg/gcc12/bin/gcc" \
-DCMAKE_CXX_COMPILER="/usr/pkg/gcc12/bin/g++" \
> /dev/null 2>&1
;;
OpenBSD)
cmake -B build \
-DBUILD_GUI=ON \
-DWITH_ZMQ=ON \
-DENABLE_IPC=OFF \
> /dev/null 2>&1
;;
gentoo)
cmake -B build \
-DWITH_ZMQ=ON \
> /dev/null 2>&1
;;
*)
if [ -f /etc/os-release ] &&
[ "$(grep "^ID=" /etc/os-release | cut -d= -f2 | tr -d '"')" = 'ol' ]; then
cmake -B build \
-DBUILD_GUI=ON \
-DWITH_ZMQ=ON \
-DENABLE_IPC=OFF \
> /dev/null 2>&1
else
cmake -B build \
-DBUILD_GUI=ON \
-DWITH_ZMQ=ON \
> /dev/null 2>&1
fi
;;
esac
log_info 'Compiling source code. Please wait.'
cmake --build build --parallel "${compile_num_jobs:-${SYS_CORES_PLUS_ONE}}" > /dev/null 2>&1
log_info 'Running compile checks. Please wait.'
ctest --test-dir build --parallel "${compile_num_jobs:-${SYS_CORES_PLUS_ONE}}" > /dev/null 2>&1
log_info "Installing Bitcoin Core ${target_bitcoin_version}."
cmake --install build > /dev/null 2>&1 || sudo cmake --install build > /dev/null
}
# TODO: use make on old releases and cmake on >= 29.0
# shellcheck disable=SC2317
compile_bitcoin_from_source_make()
{
log_info 'Ensuring compile dependencies.'
readonly COMPILE_DIRECTORY="${TEMP_DIRECTORY}/compile_bitcoin"
readonly STDERR_COMPILE_LOG_FILE="${TEMP_DIRECTORY}/stderr_install.log"
install_build_dependencies
log_info 'Downloading Bitcoin source code.'
# shellcheck disable=SC2015
command -v torsocks > /dev/null 2>&1 &&
[ "${TARGET_KERNEL}" != 'Darwin' ] &&
torsocks git clone --branch "v${target_bitcoin_version}" --depth 1 --quiet -c advice.detachedHead=false "${BITCOIN_CORE_REPO}.git" "${COMPILE_DIRECTORY}" 2> /dev/null ||
git clone --branch "v${target_bitcoin_version}" --depth 1 --quiet -c advice.detachedHead=false "${BITCOIN_CORE_REPO}.git" "${COMPILE_DIRECTORY}" 2> /dev/null
cd "${COMPILE_DIRECTORY}"/
log_info 'Analyzing hardware configuration.'
command -v autoreconf > /dev/null 2>&1 ||
throw_error "Build dependencies failed to install. Manually install 'autoconf' and try again."
./autogen.sh > /dev/null 2> "${STDERR_COMPILE_LOG_FILE}"
grep -v 'build-aux' "${STDERR_COMPILE_LOG_FILE}" >&2 || true
log_info 'Configuring the build environment.'
case "${TARGET_KERNEL}" in
Darwin)
./configure CC=clang CXX=clang++ --without-bdb --enable-suppress-external-warnings > /dev/null
;;
FreeBSD)
./configure --without-bdb --enable-suppress-external-warnings MAKE=gmake > /dev/null
;;
NetBSD)
./configure --with-gui=no --with-boost=/usr/pkg --without-bdb --enable-suppress-external-warnings MAKE=gmake > /dev/null
;;
OpenBSD)
./configure --without-bdb --enable-suppress-external-warnings MAKE=gmake > /dev/null 2>&1
;;
*)
./configure --without-bdb --enable-suppress-external-warnings > /dev/null
;;
esac
log_info 'Compiling source code. Please wait.'
case "${TARGET_KERNEL}" in
FreeBSD | NetBSD | OpenBSD)
gmake --jobs "${compile_num_jobs:-${SYS_CORES_PLUS_ONE}}" > /dev/null 2>&1
;;
*)
make --jobs "${compile_num_jobs:-${SYS_CORES_PLUS_ONE}}" > /dev/null 2>&1
;;
esac
log_info 'Running compile checks. Please wait.'
case "${TARGET_KERNEL}" in
FreeBSD | NetBSD | OpenBSD)
gmake --jobs "${compile_num_jobs:-${SYS_CORES_PLUS_ONE}}" check > /dev/null 2> "${STDERR_COMPILE_LOG_FILE}"
;;
*)
make --jobs "${compile_num_jobs:-${SYS_CORES_PLUS_ONE}}" check > /dev/null 2> "${STDERR_COMPILE_LOG_FILE}"
;;
esac
# exclude the two lines before and after 'Ran 3 tests in ' in make check's stdout
sed -n '1N;2N;/Ran 3 tests in /{N;N;d;};P;N;D' "${STDERR_COMPILE_LOG_FILE}" >&2
log_info "Installing Bitcoin Core ${target_bitcoin_version}."
case "${TARGET_KERNEL}" in
FreeBSD | NetBSD | OpenBSD)
gmake install > /dev/null 2>&1 || sudo gmake install > /dev/null
;;
*)
make install > /dev/null 2>&1 || sudo make install > /dev/null
;;
esac
cd - > /dev/null
rm "${STDERR_COMPILE_LOG_FILE}"
rm -rf "${COMPILE_DIRECTORY:?}"/
}
create_application_shortcuts()
{
log_info 'Creating application shortcuts.'
readonly DESKTOP_DIRECTORY="${HOME}/Desktop"
readonly USER_DATA_DIRECTORY="${XDG_DATA_HOME:-${HOME}/.local/share}"
readonly APPLICATIONS_DIRECTORY="${USER_DATA_DIRECTORY}/applications"
readonly SHORTCUT_IMAGE_FILE="${USER_DATA_DIRECTORY}/images/bitcoin128.png"
readonly SHORTCUT_IMAGE_SOURCE="${BITCOIN_CORE_REPO}/raw/v${target_bitcoin_version}/share/pixmaps/bitcoin128.png"
readonly SHORTCUT_FILENAME='bitcoin-qt.desktop'
readonly OLD_SHORTCUT_FILENAME='bitcoin_core.desktop'
[ -d "$(dirname "${SHORTCUT_IMAGE_FILE}")" ] || mkdir -p "$(dirname "${SHORTCUT_IMAGE_FILE}")"
if [ ! -f "${SHORTCUT_IMAGE_FILE}" ]; then
# shellcheck disable=SC2015
if command -v torsocks > /dev/null 2>&1 && [ "${TARGET_KERNEL}" != 'Darwin' ] &&
torsocks curl --fail --silent --show-error --location --retry 2 --head "${SHORTCUT_IMAGE_SOURCE}" | grep -q 'HTTP/[0-9.]* 200' ||
curl --fail --silent --show-error --location --retry 5 --head "${SHORTCUT_IMAGE_SOURCE}" | grep -q 'HTTP/[0-9.]* 200'; then
command -v torsocks > /dev/null 2>&1 && [ "${TARGET_KERNEL}" != 'Darwin' ] &&
torsocks curl --fail --silent --show-error --location --retry 2 --output "${SHORTCUT_IMAGE_FILE}" "${SHORTCUT_IMAGE_SOURCE}" ||
curl --fail --silent --show-error --location --retry 5 --output "${SHORTCUT_IMAGE_FILE}" "${SHORTCUT_IMAGE_SOURCE}"
else
throw_error "Bitcoin image file doesn't exist at ${SHORTCUT_IMAGE_SOURCE}"
fi
fi
for shortcut_directory in "${DESKTOP_DIRECTORY}" "${APPLICATIONS_DIRECTORY}"; do
[ -d "${shortcut_directory}" ] || mkdir -p "${shortcut_directory}"
[ -f "${shortcut_directory}/${OLD_SHORTCUT_FILENAME}" ] && rm "${shortcut_directory}/${OLD_SHORTCUT_FILENAME}"
done
## Create desktop entries on the user's Desktop and 'Show Applications' directories
cat << EOF | tee "${APPLICATIONS_DIRECTORY}/${SHORTCUT_FILENAME}" > "${DESKTOP_DIRECTORY}/${SHORTCUT_FILENAME}"
[Desktop Entry]
Encoding=UTF-8
Version=1.0
Name=Bitcoin Core
Comment=Connect to the Bitcoin P2P Network
Comment[de]=Verbinde mit dem Bitcoin peer-to-peer Netzwerk
Comment[fr]=Connectez-vous au réseau peer-to-peer de Bitcoin
Comment[tr]=Bitcoin eşler arası ağına bağlan
Comment[es]=Conéctate a la red de Bitcoin de pares a pares
Comment[zh]=连接到比特币点对点网络
Comment[ja]=ビットコインのピア・ツー・ピアネットワークに接続
Comment[ko]=비트코인 피어 투 피어 네트워크에 연결
Comment[ru]=Подключитесь к сети Bitcoin с одноранговыми узлами
Comment[pt]=Conecte-se à rede ponto a ponto do Bitcoin
Comment[it]=Collegati alla rete peer-to-peer di Bitcoin
Comment[nl]=Verbind met het Bitcoin peer-to-peer netwerk
Comment[ar]=اتصل بشبكة بيتكوين نظير إلى نظير
Comment[pl]=Połącz z siecią typu peer-to-peer Bitcoin
Comment[sv]=Anslut till Bitcoin nätverket för peer-to-peer
Comment[hi]=बिटकॉइन पीयर-टू-पीयर नेटवर्क से कनेक्ट करें
Exec=${LAUNCH_BITCOIN_CORE_COMMAND}
Terminal=false
Type=Application
Icon=${SHORTCUT_IMAGE_FILE}
MimeType=x-scheme-handler/bitcoin;
Categories=Office;Finance;P2P;Network;Qt;
SingleMainWindow=true
StartupNotify=true
StartupWMClass=Bitcoin-Qt
EOF
chmod u+x "${APPLICATIONS_DIRECTORY}/${SHORTCUT_FILENAME}"
chmod u+x "${DESKTOP_DIRECTORY}/${SHORTCUT_FILENAME}"
## Make the desktop shortcut trusted
if is_running_in_ci || is_running_in_container; then
:
elif command -v gio > /dev/null 2>&1 &&
gio set "${DESKTOP_DIRECTORY}/${SHORTCUT_FILENAME}" 'metadata::trusted' true 2> /dev/null; then
:
else
log_warning "If the desktop shortcut is failing, please open an issue at ${NODEBUILDER_REPO}."
fi
}
display_macos_warning()
{
log_warning 'macOS has an unpatched security vulnerability called GoFetch.'
log_warning 'Avoid security-critical actions, such as securing significant funds.'
if [ "${unattended:-false}" = 'false' ] && ! is_running_in_ci; then
log_info 'PRESS ENTER to continue or press Ctrl+C to exit.'
read -r _
fi
}
bitcoin_tarball_download()
{
log_info 'Downloading Bitcoin Core.'
if command -v torsocks > /dev/null 2>&1 && [ "${TARGET_KERNEL}" != 'Darwin' ]; then
torsocks curl --fail --silent --show-error --location --retry 2 --output "${BITCOIN_HASH_FILE}" "${BITCOIN_HASH_FILE_SOURCE}" ||
curl --fail --silent --show-error --location --retry 5 --output "${BITCOIN_HASH_FILE}" "${BITCOIN_HASH_FILE_SOURCE}"
torsocks curl --fail --silent --show-error --location --retry 2 --output "${GPG_SIGNATURES_FILE}" "${GPG_SIGNATURES_FILE_SOURCE}" ||
curl --fail --silent --show-error --location --retry 5 --output "${GPG_SIGNATURES_FILE}" "${GPG_SIGNATURES_FILE_SOURCE}"
torsocks curl --fail --silent --show-error --location --retry 2 --output "${BITCOIN_TARBALL_TEMPORARY_PATH}" "${BITCOIN_TARBALL_FILE_SOURCE}" ||
curl --fail --silent --show-error --location --retry 5 --output "${BITCOIN_TARBALL_TEMPORARY_PATH}" "${BITCOIN_TARBALL_FILE_SOURCE}"
else
curl --fail --silent --show-error --location --retry 5 --output "${BITCOIN_HASH_FILE}" "${BITCOIN_HASH_FILE_SOURCE}"
curl --fail --silent --show-error --location --retry 5 --output "${GPG_SIGNATURES_FILE}" "${GPG_SIGNATURES_FILE_SOURCE}"
curl --fail --silent --show-error --location --retry 5 --output "${BITCOIN_TARBALL_TEMPORARY_PATH}" "${BITCOIN_TARBALL_FILE_SOURCE}"
fi
}
bitcoin_tarball_download_validate()
{
case "${target_bitcoin_version}" in
*rc*)
target_bitcoin_version_without_rc="${target_bitcoin_version%rc*}"
target_bitcoin_version_rc_number="${target_bitcoin_version##*rc}"
BITCOIN_SOURCE="https://bitcoincore.org/bin/bitcoin-core-${target_bitcoin_version_without_rc}/test.rc${target_bitcoin_version_rc_number}"
;;
*)
BITCOIN_SOURCE="https://bitcoincore.org/bin/bitcoin-core-${target_bitcoin_version}"
;;
esac
readonly BITCOIN_SOURCE
readonly BITCOIN_TARBALL_FILE_SOURCE="${BITCOIN_SOURCE}/${BITCOIN_TARBALL_FILENAME}"
readonly BITCOIN_HASH_FILENAME='SHA256SUMS'
readonly BITCOIN_HASH_FILE_SOURCE="${BITCOIN_SOURCE}/${BITCOIN_HASH_FILENAME}"
readonly GPG_SIGNATURES_FILENAME='SHA256SUMS.asc'
readonly GPG_SIGNATURES_FILE_SOURCE="${BITCOIN_SOURCE}/${GPG_SIGNATURES_FILENAME}"
readonly GPG_GOOD_SIGNATURES_REQUIRED='7'
readonly GUIX_SIGS_REPO='https://github.com/bitcoin-core/guix.sigs'
readonly BITCOIN_TARBALL_TEMPORARY_PATH="${TEMP_DIRECTORY}/${BITCOIN_TARBALL_FILENAME}"
readonly BITCOIN_HASH_FILE="${TEMP_DIRECTORY}/${BITCOIN_HASH_FILENAME}"
readonly GPG_SIGNATURES_FILE="${TEMP_DIRECTORY}/${GPG_SIGNATURES_FILENAME}"
readonly GUIX_SIGS_TEMPORARY_DIRECTORY="${TEMP_DIRECTORY}/guix.sigs"
readonly GUIX_SIGS_DESTINATION_DIRECTORY="${HOME}/Downloads/guix.sigs"
bitcoin_tarball_download
bitcoin_tarball_validate
}
bitcoin_tarball_download_extract_test_install()
{
readonly BITCOIN_CORE_EXTRACT_DIR="${TEMP_DIRECTORY}/bitcoin-core"
readonly BITCOIN_INSTALL_BIN_SOURCE="${BITCOIN_CORE_EXTRACT_DIR}/bin"
readonly BITCOIN_INSTALL_LIB_SOURCE="${BITCOIN_CORE_EXTRACT_DIR}/lib"
readonly BITCOIN_INSTALL_LIBEXEC_SOURCE="${BITCOIN_CORE_EXTRACT_DIR}/libexec"
readonly BITCOIN_INSTALL_INCLUDE_SOURCE="${BITCOIN_CORE_EXTRACT_DIR}/include"
readonly BITCOIN_INSTALL_MAN_SOURCE="${BITCOIN_CORE_EXTRACT_DIR}/share/man/man1"
readonly BITCOIN_INSTALL_DESTINATION='/usr/local'
readonly BITCOIN_INSTALL_BIN_DESTINATION="${BITCOIN_INSTALL_DESTINATION}/bin"
readonly BITCOIN_INSTALL_LIB_DESTINATION="${BITCOIN_INSTALL_DESTINATION}/lib"
readonly BITCOIN_INSTALL_INCLUDE_DESTINATION="${BITCOIN_INSTALL_DESTINATION}/include"
readonly BITCOIN_INSTALL_MAN_DESTINATION="${BITCOIN_INSTALL_DESTINATION}/share/man/man1"
readonly BITCOIN_TARBALL_FILENAME="bitcoin-${target_bitcoin_version}-${TARGET_ARCHITECTURE}-${TARGET_BITCOIN_TARBALL_OS}.tar.gz"
readonly BITCOIN_TARBALL_DESTINATION_PATH="${HOME}/Downloads/${BITCOIN_TARBALL_FILENAME}"
[ -f "${BITCOIN_TARBALL_DESTINATION_PATH}" ] || bitcoin_tarball_download_validate
bitcoin_tarball_extract
bitcoin_tarball_test
bitcoin_tarball_install
log_info 'Removing installation files.'
rm -r "${BITCOIN_CORE_EXTRACT_DIR:?}/"
rm -r "${TEMP_DIRECTORY:?}/"
log_info 'Bitcoin Core installation complete.'
}
bitcoin_tarball_extract()
{
log_info 'Extracting Bitcoin Core.'
[ -d "${BITCOIN_CORE_EXTRACT_DIR}"/ ] || mkdir "${BITCOIN_CORE_EXTRACT_DIR}"
tar -xzf "${BITCOIN_TARBALL_DESTINATION_PATH}" -C "${BITCOIN_CORE_EXTRACT_DIR}"/ --strip-components=1
}
bitcoin_tarball_install()
{
log_info "Installing Bitcoin Core ${target_bitcoin_version}."
# install the libraries
if [ -d "${BITCOIN_INSTALL_LIB_SOURCE}" ]; then
[ -d "${BITCOIN_INSTALL_LIB_DESTINATION}" ] ||
mkdir -p "${BITCOIN_INSTALL_LIB_DESTINATION}" 2> /dev/null ||
sudo mkdir "${BITCOIN_INSTALL_LIB_DESTINATION}" ||
throw_error "Unable to create directory ${BITCOIN_INSTALL_LIB_DESTINATION}."
case "${TARGET_KERNEL}" in
Linux)
sudo cp \
"${BITCOIN_INSTALL_LIB_SOURCE}/libbitcoinconsensus.so.0.0.0" \
"${BITCOIN_INSTALL_LIB_DESTINATION}/libbitcoinconsensus.so.0.0.0"
(cd "${BITCOIN_INSTALL_LIB_DESTINATION}"/ && {
sudo ln -s -f libbitcoinconsensus.so.0.0.0 libbitcoinconsensus.so.0 || {
sudo rm -f libbitcoinconsensus.so.0
sudo ln -s libbitcoinconsensus.so.0.0.0 libbitcoinconsensus.so.0
}
})
(cd "${BITCOIN_INSTALL_LIB_DESTINATION}"/ && {
sudo ln -s -f libbitcoinconsensus.so.0.0.0 libbitcoinconsensus.so || {
sudo rm -f libbitcoinconsensus.so
sudo ln -s libbitcoinconsensus.so.0.0.0 libbitcoinconsensus.so
}
})
PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/sbin' \
ldconfig -n "${BITCOIN_INSTALL_LIB_DESTINATION}"
;;
Darwin)
sudo cp \
"${BITCOIN_INSTALL_LIB_SOURCE}/libbitcoinconsensus.0.dylib" \
"${BITCOIN_INSTALL_LIB_DESTINATION}/libbitcoinconsensus.0.dylib"
(cd "${BITCOIN_INSTALL_LIB_DESTINATION}"/ && {
sudo ln -s -f libbitcoinconsensus.0.dylib libbitcoinconsensus.dylib || {
sudo rm -f libbitcoinconsensus.dylib
sudo ln -s libbitcoinconsensus.0.dylib libbitcoinconsensus.dylib
}
})
sudo update_dyld_shared_cache
;;
*)
throw_error "Unsupported OS. Please use the --compile option."
;;
esac
fi
# install the binaries
[ -d "${BITCOIN_INSTALL_BIN_DESTINATION}" ] ||
mkdir -p "${BITCOIN_INSTALL_BIN_DESTINATION}" 2> /dev/null ||
sudo mkdir "${BITCOIN_INSTALL_BIN_DESTINATION}" ||
throw_error "Unable to create directory ${BITCOIN_INSTALL_BIN_DESTINATION}."
for bitcoin_executable in bitcoind bitcoin-qt bitcoin-cli bitcoin-tx bitcoin-util bitcoin-wallet; do
if [ "${TARGET_KERNEL}" = 'Darwin' ] && [ "${TARGET_ARCHITECTURE}" = 'arm64' ] &&
! is_arm64_test_bitcoin_signed "${target_bitcoin_version}"; then
codesign -s - "${BITCOIN_INSTALL_BIN_SOURCE}/${bitcoin_executable}"
fi
sudo install -c \
"${BITCOIN_INSTALL_BIN_SOURCE}/${bitcoin_executable}" \
"${BITCOIN_INSTALL_BIN_DESTINATION}/"
done
# install the header files
if [ -d "${BITCOIN_INSTALL_INCLUDE_SOURCE}" ]; then
[ -d "${BITCOIN_INSTALL_INCLUDE_DESTINATION}" ] ||
mkdir -p "${BITCOIN_INSTALL_INCLUDE_DESTINATION}" 2> /dev/null ||
sudo mkdir "${BITCOIN_INSTALL_INCLUDE_DESTINATION}" ||
throw_error "Unable to create directory ${BITCOIN_INSTALL_INCLUDE_DESTINATION}."
sudo install -c -m 644 \
"${BITCOIN_INSTALL_INCLUDE_SOURCE}/bitcoinconsensus.h" \
"${BITCOIN_INSTALL_INCLUDE_DESTINATION}/"
fi
# install the binary man pages
[ -d "${BITCOIN_INSTALL_MAN_DESTINATION}" ] ||
mkdir -p "${BITCOIN_INSTALL_MAN_DESTINATION}" 2> /dev/null ||
sudo mkdir -p "${BITCOIN_INSTALL_MAN_DESTINATION}" ||
throw_error "Unable to create directory ${BITCOIN_INSTALL_MAN_DESTINATION}."
for man_page in bitcoind.1 bitcoin-qt.1 bitcoin-cli.1 bitcoin-tx.1 bitcoin-util.1 bitcoin-wallet.1; do
sudo install -c -m 644 "${BITCOIN_INSTALL_MAN_SOURCE}/${man_page}" "${BITCOIN_INSTALL_MAN_DESTINATION}/"
done
}
get_oldest_version()
{
readonly FIRST_VERSION="$1"
readonly SECOND_VERSION="$2"
[ "$#" -ne 2 ] &&
throw_error "Invalid use of get_most_recent_version."
printf '%s\n%s' "${FIRST_VERSION}" "${SECOND_VERSION}" | sort -V | head -1
}
is_arm64_test_bitcoin_signed()
{
BITCOIN_VERSION_TO_COMPARE="$1"
ARM64_SIGNED_BINARY_VERSION='28.2'
[ "$#" -ne 1 ] &&
throw_error "Invalid use of is_arm64_test_bitcoin_signed."
# test_bitcoin binary is already signed on Bitcoin Core 28.2 and later
if [ "$(get_oldest_version "${BITCOIN_VERSION_TO_COMPARE}" "${ARM64_SIGNED_BINARY_VERSION}")" \
= "${ARM64_SIGNED_BINARY_VERSION}" ]; then
return 0
else
return 1
fi
}
bitcoin_tarball_test()
{
log_info 'Running the unit tests.'
# only sign test_bitcoin if on arm64 and target version is before 28.2
if [ "${TARGET_ARCHITECTURE}" = 'arm64' ] &&
! is_arm64_test_bitcoin_signed "${target_bitcoin_version}"; then
codesign -s - "${BITCOIN_INSTALL_LIBEXEC_SOURCE}"/test_bitcoin
fi
UNIT_TEST_RESPONSE="$("${BITCOIN_INSTALL_LIBEXEC_SOURCE}"/test_bitcoin 2>&1)"
readonly UNIT_TEST_RESPONSE
case "${UNIT_TEST_RESPONSE}" in
*'No errors detected'*) ;;
*)
printf '\n%s\n' "${UNIT_TEST_RESPONSE}"
throw_error 'Unit tests failed.'
;;
esac
}
bitcoin_tarball_validate()
{
bitcoin_tarball_validate_checksum
GPG_GOOD_SIGNATURE_COUNT="$(bitcoin_tarball_validate_count_signatures)"
readonly GPG_GOOD_SIGNATURE_COUNT
if [ "${GPG_GOOD_SIGNATURE_COUNT}" -lt "${GPG_GOOD_SIGNATURES_REQUIRED}" ]; then
throw_error "INVALID SIGNATURES. The download has failed. This script cannot continue due to security concerns. Please review the temporary file ${TEMP_DIRECTORY}/${GPG_SIGNATURES_FILE}."
fi
log_info "Found ${GPG_GOOD_SIGNATURE_COUNT} good signatures."
[ -d "$(dirname "${BITCOIN_TARBALL_DESTINATION_PATH}")" ] ||
mkdir -p "$(dirname "${BITCOIN_TARBALL_DESTINATION_PATH}")"
mv "${BITCOIN_TARBALL_TEMPORARY_PATH}" "${BITCOIN_TARBALL_DESTINATION_PATH}"
if [ ! -d "${GUIX_SIGS_DESTINATION_DIRECTORY}/" ]; then
mkdir -p "${GUIX_SIGS_DESTINATION_DIRECTORY}"
mv "${GUIX_SIGS_TEMPORARY_DIRECTORY}" "${GUIX_SIGS_DESTINATION_DIRECTORY}"
fi
[ -f "${BITCOIN_HASH_FILE}" ] && rm "${BITCOIN_HASH_FILE}"
[ -f "${GPG_SIGNATURES_FILE}" ] && rm "${GPG_SIGNATURES_FILE}"
}
bitcoin_tarball_validate_checksum()
{
cd "${TEMP_DIRECTORY}"/
case "${TARGET_KERNEL}" in
Darwin)
if command -v shasum > /dev/null; then
SHA256_CHECK="$(grep "${BITCOIN_TARBALL_FILENAME}" "${BITCOIN_HASH_FILENAME}" | shasum -a 256 --check 2> /dev/null)"
elif command -v sha256sum > /dev/null; then
SHA256_CHECK="$(grep "${BITCOIN_TARBALL_FILENAME}" "${BITCOIN_HASH_FILENAME}" | sha256sum --check 2> /dev/null)"
else
throw_error "Either sha256sum or shasum must be installed. Please open an issue at ${NODEBUILDER_REPO}."
fi
;;
*)
if command -v sha256sum > /dev/null; then
SHA256_CHECK="$(grep "${BITCOIN_TARBALL_FILENAME}" "${BITCOIN_HASH_FILENAME}" | sha256sum --check 2> /dev/null)"
elif command -v shasum > /dev/null; then
SHA256_CHECK="$(grep "${BITCOIN_TARBALL_FILENAME}" "${BITCOIN_HASH_FILENAME}" | shasum -a 256 --check 2> /dev/null)"
else
throw_error "Either sha256sum or shasum must be installed. Please open an issue at ${NODEBUILDER_REPO}."
fi
;;
esac
readonly SHA256_CHECK
cd - > /dev/null
case "${SHA256_CHECK}" in
*'OK'*) ;;
*)
throw_error "INVALID CHECKSUM. The download has failed. This script cannot continue due to security concerns. Please review the temporary file ${TEMP_DIRECTORY}/${BITCOIN_HASH_FILE}."
;;
esac
log_info 'Validated the checksum.'
}
bitcoin_tarball_validate_count_signatures()
{
if [ -d "${GUIX_SIGS_DESTINATION_DIRECTORY}"/ ]; then
gpg --quiet --import "${GUIX_SIGS_DESTINATION_DIRECTORY}"/builder-keys/*.gpg
else
# shellcheck disable=SC2015
command -v torsocks > /dev/null 2>&1 && [ "${TARGET_KERNEL}" != 'Darwin' ] &&
torsocks git clone --depth 1 --quiet "${GUIX_SIGS_REPO}.git" "${GUIX_SIGS_TEMPORARY_DIRECTORY}" ||
git clone --depth 1 --quiet "${GUIX_SIGS_REPO}.git" "${GUIX_SIGS_TEMPORARY_DIRECTORY}"
gpg --quiet --import "${GUIX_SIGS_TEMPORARY_DIRECTORY}"/builder-keys/*.gpg
fi
SIGNATURE_COUNT="$(gpg --verify "${GPG_SIGNATURES_FILE}" 2>&1 | grep -c '^gpg: Good signature from ')" &&
readonly SIGNATURE_COUNT
pgrep '^gpg-agent$' > /dev/null && gpgconf --kill gpg-agent
pgrep '^keyboxd$' > /dev/null && gpgconf --kill keyboxd
printf '%s\n' "${SIGNATURE_COUNT}"
}
ensure_curl_dependency()
{
if command -v dnf > /dev/null 2>&1; then
sudo dnf install --allowerasing --assumeyes curl > /dev/null
elif ! command -v curl > /dev/null 2>&1; then
log_info 'Ensuring curl depencency.'
case "${TARGET_OPERATING_SYSTEM}" in
alpine)
sudo apk --quiet add --no-cache curl
;;
debian | ubuntu)
sudo apt-get install -y curl > /dev/null
;;
fedora* | rhel | centos* | rocky | ol)
sudo dnf install --allowerasing --assumeyes curl > /dev/null
;;
gentoo)
emerge --jobs "${compile_num_jobs:-${SYS_CORES_COUNT}}" --load-average "${compile_num_jobs:-${SYS_CORES_PLUS_ONE}}" --quiet --quiet-build --quiet-fail net-misc/curl
;;
arch | endeavouros | garuda | manjaro)
sudo pacman -Syu --needed --noconfirm curl > /dev/null
;;
suse | sles | *opensuse*)
sudo zypper --non-interactive --quiet install curl > /dev/null
;;
Darwin)
throw_error "Please install the 'curl' dependency."
;;
FreeBSD)
sudo pkg install -y curl > /dev/null
;;
NetBSD)
ensure_netbsd_pkgin_dependency
sudo pkgin update > /dev/null
sudo pkgin -y install curl > /dev/null
;;
OpenBSD)
sudo pkg_add curl > /dev/null
;;
*)
if command -v apk > /dev/null; then
sudo apk --quiet add --no-cache curl
elif command -v apt-get > /dev/null; then
sudo apt-get -qq install -y curl > /dev/null
elif command -v dnf > /dev/null; then
sudo dnf install --allowerasing --assumeyes curl > /dev/null
elif command -v pacman > /dev/null; then
sudo pacman -Syu --needed --noconfirm curl > /dev/null
elif command -v zypper > /dev/null; then
sudo zypper --non-interactive --quiet install curl > /dev/null
else
throw_error "Package manager was not found. Please report an issue at ${NODEBUILDER_REPO}."
fi
;;
esac
fi
command -v curl > /dev/null 2>&1 || throw_error "Unable to install 'curl'. Please report this error at ${NODEBUILDER_REPO}."
}
ensure_netbsd_pkgin_dependency()
{
hash pkgin 2> /dev/null ||
pkg_add "https://cdn.netbsd.org/pub/pkgsrc/packages/NetBSD/${TARGET_ARCHITECTURE}/${TARGET_OPERATING_SYSTEM_RELEASE}/All/pkgin" > /dev/null
}
ensure_sudo_dependency()
{
if ! command -v sudo > /dev/null 2>&1; then
log_info 'Ensuring sudo depencency.'
case "${TARGET_OPERATING_SYSTEM}" in
alpine)
apk --quiet add --no-cache sudo
;;
debian | ubuntu)
apt-get install -y sudo > /dev/null
;;
fedora* | rhel | centos* | rocky | ol)
dnf install --allowerasing --assumeyes sudo > /dev/null
;;
gentoo)
emerge --sync --quiet
emerge --jobs "${compile_num_jobs:-${SYS_CORES_COUNT}}" --load-average "${compile_num_jobs:-${SYS_CORES_PLUS_ONE}}" --quiet --quiet-build --quiet-fail app-admin/sudo
;;
arch | endeavouros | garuda | manjaro)
pacman -Syu --needed --noconfirm sudo > /dev/null
;;
suse | sles | *opensuse*)
zypper --non-interactive --quiet install sudo > /dev/null
;;
FreeBSD)
pkg install -y sudo > /dev/null
;;
NetBSD)
ensure_netbsd_pkgin_dependency
pkgin update > /dev/null
pkgin -y install sudo > /dev/null
;;
OpenBSD)
pkg_add sudo-- > /dev/null
;;
*)
if command -v apk > /dev/null; then
apk --quiet add --no-cache sudo
elif command -v apt-get > /dev/null; then
apt-get -qq install -y sudo > /dev/null
elif command -v dnf > /dev/null; then
dnf install sudo > /dev/null
elif command -v pacman > /dev/null; then
pacman -Syu --needed --noconfirm sudo > /dev/null
elif command -v zypper > /dev/null; then
zypper --non-interactive --quiet install sudo > /dev/null
else
throw_error "Package manager was not found. Please report an issue at ${NODEBUILDER_REPO}."
fi
;;
esac
fi
# shellcheck disable=SC2230
command -v sudo > /dev/null 2>&1 ||
hash sudo 2> /dev/null ||
which sudo > /dev/null ||
throw_error "Unable to install 'sudo'. Please report this error at ${NODEBUILDER_REPO}."
}
ensure_xargs_dependency()
{
if ! command -v xargs > /dev/null 2>&1; then
log_info 'Ensuring xargs depencency.'
case "${TARGET_OPERATING_SYSTEM}" in
alpine)
sudo apk --quiet add --no-cache findutils
;;
debian | ubuntu)
apt-get install -y findutils > /dev/null
;;
fedora* | rhel | centos* | rocky | ol)
dnf install --allowerasing --assumeyes findutils > /dev/null
;;
gentoo)
emerge --sync --quiet
emerge --jobs "${compile_num_jobs:-${SYS_CORES_COUNT}}" --load-average "${compile_num_jobs:-${SYS_CORES_PLUS_ONE}}" --quiet --quiet-build --quiet-fail sys-apps/findutils
;;
arch | endeavouros | garuda | manjaro)
pacman -Syu --needed --noconfirm findutils > /dev/null
;;
suse | sles | *opensuse*)
zypper --non-interactive --quiet install findutils > /dev/null
;;
FreeBSD)
sudo pkg install -y findutils > /dev/null
;;
NetBSD)
sudo pkgin update > /dev/null
sudo pkgin install findutils
;;
OpenBSD)
sudo pkg_add findutils > /dev/null
;;
*)
if command -v apk > /dev/null; then
sudo apk --quiet add --no-cache findutils
elif command -v apt-get > /dev/null; then
apt-get -qq install -y findutils > /dev/null
elif command -v dnf > /dev/null; then
dnf install findutils > /dev/null
elif command -v pacman > /dev/null; then
pacman -Syu --needed --noconfirm findutils > /dev/null
elif command -v zypper > /dev/null; then
zypper --non-interactive --quiet install findutils > /dev/null
else
[ -f /etc/os-release ] && cat /etc/os-release
[ -f /etc/lsb-release ] && cat /etc/lsb-release
throw_error "Package manager was not found. Please report an issue at ${NODEBUILDER_REPO}."
fi
;;
esac
command -v xargs > /dev/null 2>&1 ||
throw_error "Unable to install 'xargs'. Report this error at ${NODEBUILDER_REPO}."
fi
}
get_directory_size_in_mib()
{
if [ $# -ne 1 ]; then
throw_error 'get_directory_size_in_mib() requires 1 argument.'
fi
readonly directory_to_check="$1"
if [ -d "${directory_to_check}/" ]; then
BLOCKSIZE=1M du -d0 "${directory_to_check}" | cut -f1
else
printf '0\n'
fi
}
get_free_space_in_mib()
{
BLOCKSIZE=1M df "${BITCOIN_DATA_DIRECTORY}" | awk 'NR==2 {print $4}'
}
get_log_timestamp()
{
date +'%Y-%m-%dT%H:%M:%S'
}
get_memory_metric_in_mib()
{
metric_to_query="$1"
awk -v metric="${metric_to_query}" \
-v kib_mib_factor="${KIB_TO_MIB}" \
'$0 ~ metric { printf "%d \n", $2 / kib_mib_factor }' /proc/meminfo
}
get_operating_system()
{
case "${TARGET_KERNEL}" in
Darwin | FreeBSD | NetBSD | OpenBSD)
printf '%s\n' "${TARGET_KERNEL}"
;;
*)
OS_RELEASE_ID="$(grep '^ID=' /etc/os-release | cut -d= -f2)"
readonly OS_RELEASE_ID
OS_RELEASE_ID_LIKE="$(grep '^ID_LIKE=' /etc/os-release | cut -d= -f2)"
readonly OS_RELEASE_ID_LIKE
if [ -n "${OS_RELEASE_ID}" ] || [ -n "${OS_RELEASE_ID_LIKE}" ]; then
printf '%s\n' "${OS_RELEASE_ID_LIKE:-${OS_RELEASE_ID}}"
else
throw_error 'Failed to determine OS release type'
fi
;;
esac
}
# shellcheck disable=SC2317
handle_exit()
{
if [ -n "${TEMP_DIRECTORY:-}" ] && [ -d "${TEMP_DIRECTORY}" ]; then
rm -rf -- "${TEMP_DIRECTORY:?}"/
fi
}
# shellcheck disable=SC2317
handle_sigint()
{
log_warning 'Detected Ctrl+C. Exiting.'
handle_exit
exit 0
}
install_build_dependencies()
{
case "${TARGET_OPERATING_SYSTEM}" in
alpine)
install_build_dependencies_apk
;;
debian | ubuntu)
install_build_dependencies_aptget
;;
fedora* | rhel | centos* | rocky | ol)
install_build_dependencies_dnf
;;
gentoo)
install_build_dependencies_emerge
;;
arch | endeavouros | garuda | manjaro)
install_build_dependencies_pacman
;;
suse | sles | *opensuse*)
install_build_dependencies_zypper
;;
Darwin)
install_build_dependencies_darwin
;;
FreeBSD)
install_build_dependencies_freebsd
;;
NetBSD)
install_build_dependencies_netbsd
;;
OpenBSD)
install_build_dependencies_openbsd
;;
*)
install_build_command_function=''
for package_manager in \
apk \
apt-get \
dnf \
emerge \
pacman \
zypper; do
if command -v "${package_manager}" > /dev/null; then
install_build_command_function="install_build_dependencies_$(echo "${package_manager}" | tr -d '-')"
break
fi
done
if [ -n "${install_build_command_function}" ]; then
"${install_build_command_function}"
else
log_warning 'Unable to determine build dependencies. Attempting to compile but might see errors.'
fi
;;
esac
}
install_build_dependencies_apk()
{
readonly BUILD_DEPENDENCIES_URL="${DEPENDENCIES_BASE_URL}/build_dependencies_apk.txt"
command -v torsocks > /dev/null 2>&1 &&
dependencies=$(torsocks curl --fail --silent --show-error --location --retry 2 "${BUILD_DEPENDENCIES_URL}") ||
dependencies=$(curl --fail --silent --show-error --location --retry 5 "${BUILD_DEPENDENCIES_URL}")
[ -z "${dependencies:-}" ] && throw_error "The list of dependencies is empty."
printf '%s\n' "${dependencies}" | tr -d '\r' | xargs apk --quiet add --no-cache |
grep -v 'ICU with non-English locales' -A2 -B1 || true
}
install_build_dependencies_aptget()
{
readonly BUILD_DEPENDENCIES_URL="${DEPENDENCIES_BASE_URL}/build_dependencies_aptget.txt"
command -v torsocks > /dev/null 2>&1 &&
dependencies=$(torsocks curl --fail --silent --show-error --location --retry 2 "${BUILD_DEPENDENCIES_URL}") ||
dependencies=$(curl --fail --silent --show-error --location --retry 5 "${BUILD_DEPENDENCIES_URL}")
[ -z "${dependencies:-}" ] && throw_error "The list of dependencies is empty."
sudo apt-get -qq update
printf '%s\n' "${dependencies}" | tr -d '\r' | xargs sudo DEBIAN_FRONTEND=noninteractive apt-get -qq install --assume-yes --no-install-recommends > /dev/null 2>&1
# TODO: Remove gcc-12 installation on next line when Ubuntu updates the default version of gcc to support C++ 20 features. Bitcoin Core requires gcc with support for C++ 20 features.
sudo DEBIAN_FRONTEND=noninteractive apt-get -qq install --assume-yes --no-install-recommends gcc-12 > /dev/null 2>&1
}
install_build_dependencies_darwin()
{
readonly BUILD_DEPENDENCIES_URL="${DEPENDENCIES_BASE_URL}/build_dependencies_darwin.txt"
#TODO: wrap this command with torsocks-curl with curl fallback
sudo printf '' && NONINTERACTIVE=1 /bin/bash -c "$(curl --fail --silent --show-error --location --retry 5 \
https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" > /dev/null 2>&1
command -v torsocks > /dev/null 2>&1 &&
dependencies=$(torsocks curl --fail --silent --show-error --location --retry 2 "${BUILD_DEPENDENCIES_URL}") ||
dependencies=$(curl --fail --silent --show-error --location --retry 5 "${BUILD_DEPENDENCIES_URL}")
[ -z "${dependencies:-}" ] && throw_error "The list of dependencies is empty."
printf '%s\n' "${dependencies}" | tr -d '\r' | xargs brew install --quiet > /dev/null 2>&1
}
install_build_dependencies_dnf()
{
readonly BUILD_DEPENDENCIES_URL="${DEPENDENCIES_BASE_URL}/build_dependencies_dnf.txt"
OS_MAJOR_VERSION_ID="$(grep "^VERSION_ID=" /etc/os-release | cut -d= -f2 | tr -d '"' | cut -d. -f1)"
readonly OS_MAJOR_VERSION_ID
case "$(grep "^ID=" /etc/os-release | cut -d= -f2 | tr -d '"')" in
amzn)
throw_error "Building from source on Amazon Linux is unsupported."
;;
fedora) ;;
rhel)
sudo subscription-manager identity > /dev/null 2>&1 ||
throw_error "Register your RHEL subscription with 'sudo subscription-manager subscribe'."
sudo dnf config-manager --enable "rhel-${OS_MAJOR_VERSION_ID}-for-${TARGET_ARCHITECTURE}-appstream-rpms" ||
throw_error "Failed to enable EPEL release rhel-${OS_MAJOR_VERSION_ID}-for-${TARGET_ARCHITECTURE}-appstream-rpms."
;;
*)
dnf list installed epel-release > /dev/null 2>&1 ||
sudo dnf --assumeyes install "https://dl.fedoraproject.org/pub/epel/epel-release-latest-${OS_MAJOR_VERSION_ID}.noarch.rpm" > /dev/null 2>&1
;;
esac
command -v torsocks > /dev/null 2>&1 &&
dependencies=$(torsocks curl --fail --silent --show-error --location --retry 2 "${BUILD_DEPENDENCIES_URL}") ||
dependencies=$(curl --fail --silent --show-error --location --retry 5 "${BUILD_DEPENDENCIES_URL}")
[ -z "${dependencies:-}" ] && throw_error "The list of dependencies is empty."
# TODO: install capnp on Oracle Linux
[ "$(grep "^ID=" /etc/os-release | cut -d= -f2 | tr -d '"')" = 'ol' ] &&
dependencies="$(echo "${dependencies}" | sed '/capnp/d')"
printf '%s\n' "${dependencies}" | tr -d '\r' | xargs sudo dnf install --assumeyes > /dev/null
}
install_build_dependencies_emerge()
{
readonly BUILD_DEPENDENCIES_URL="${DEPENDENCIES_BASE_URL}/build_dependencies_emerge.txt"
printf '\n'
command -v torsocks > /dev/null 2>&1 &&
dependencies=$(torsocks curl --fail --silent --show-error --location --retry 2 "${BUILD_DEPENDENCIES_URL}") ||
dependencies=$(curl --fail --silent --show-error --location --retry 5 "${BUILD_DEPENDENCIES_URL}")
[ -z "${dependencies:-}" ] && throw_error 'The list of dependencies is empty.'
if ! printf '%s\n' "${dependencies}" | tr -d '\r' | xargs emerge --autounmask-write \
--jobs "${compile_num_jobs:-${SYS_CORES_COUNT}}" --load-average "${compile_num_jobs:-${SYS_CORES_PLUS_ONE}}" --quiet --quiet-build --quiet-fail; then
etc-update --automode -5
emerge --update --jobs "${compile_num_jobs:-${SYS_CORES_COUNT}}" --load-average "${compile_num_jobs:-${SYS_CORES_PLUS_ONE}}" --quiet --quiet-build --quiet-fail --deep --newuse @world
# Run the install command again
printf '%s\n' "${dependencies}" | tr -d '\r' | xargs emerge --autounmask-write \
--jobs "${compile_num_jobs:-${SYS_CORES_COUNT}}" --load-average "${SYS_CORES_PLUS_ONE}" --quiet --quiet-build --quiet-fail
fi
}
install_build_dependencies_freebsd()
{
readonly BUILD_DEPENDENCIES_URL="${DEPENDENCIES_BASE_URL}/build_dependencies_freebsd.txt"
command -v torsocks > /dev/null 2>&1 &&
dependencies=$(torsocks curl --fail --silent --show-error --location --retry 2 "${BUILD_DEPENDENCIES_URL}") ||
dependencies=$(curl --fail --silent --show-error --location --retry 5 "${BUILD_DEPENDENCIES_URL}")
[ -z "${dependencies:-}" ] && throw_error "The list of dependencies is empty."
printf '%s\n' "${dependencies}" | tr -d '\r' | xargs sudo pkg install --yes > /dev/null 2>&1
}
install_build_dependencies_netbsd()
{
readonly BUILD_DEPENDENCIES_URL="${DEPENDENCIES_BASE_URL}/build_dependencies_netbsd.txt"
command -v torsocks > /dev/null 2>&1 &&
dependencies=$(torsocks curl --fail --silent --show-error --location --retry 2 "${BUILD_DEPENDENCIES_URL}") ||
dependencies=$(curl --fail --silent --show-error --location --retry 5 "${BUILD_DEPENDENCIES_URL}")
[ -z "${dependencies:-}" ] && throw_error "The list of dependencies is empty."
printf '%s\n' "${dependencies}" | tr -d '\r' | xargs sudo pkgin -y install > /dev/null
# TODO: Remove gcc-12 installation on next line when NetBSD updates the default version of gcc to support C++ 20 features. Bitcoin Core requires gcc with support for C++ 20 features.
sudo pkgin -y install gcc12 && export PATH="/usr/pkg/gcc12/bin:${PATH}"
}
install_build_dependencies_openbsd()
{
readonly BUILD_DEPENDENCIES_URL="${DEPENDENCIES_BASE_URL}/build_dependencies_openbsd.txt"
command -v torsocks > /dev/null 2>&1 &&
dependencies=$(torsocks curl --fail --silent --show-error --location --retry 2 "${BUILD_DEPENDENCIES_URL}" | tr -d '\r') ||
dependencies=$(curl --fail --silent --show-error --location --retry 5 "${BUILD_DEPENDENCIES_URL}" | tr -d '\r')
[ -z "${dependencies:-}" ] && throw_error "The list of dependencies is empty."
for package in ${dependencies}; do
if [ "${package}" = 'sqlite3' ]; then
sudo pkg_add "${package}" > /dev/null
else
package_latest_version="$(pkg_info -Q "${package}" | grep "^${package}\-" | grep -v "${package}\-[A-Za-z0-9]*\-" | sort -V | tail -1)"
if [ -z "${package_latest_version}" ]; then
throw_error "Package '${package}' was not found in pkg_info."
elif [ "$(echo "${package_latest_version}" | cut -d' ' -f2)" != '(installed)' ]; then
sudo pkg_add "${package_latest_version}" > /dev/null