Skip to content

Commit 512726a

Browse files
feat(privacy): try using torsocks for curl and git (#569)
* feat(privacy): try using torsocks for internet check * refactor: improve the whitespace * feat: wrap other curl and git commands in torsocks, except on macOS * fix: missing single-quote * fix: add shellcheck disable directives * fix: wrong spellcheck string * fix: remove whitespace * ensure the brew curl command only happens with sudo * download the files smallest to largest
1 parent 83bdb1e commit 512726a

File tree

1 file changed

+45
-12
lines changed

1 file changed

+45
-12
lines changed

nodebuilder

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ check_internet() {
1414
check_int_address=$1
1515
check_int_port="443"
1616
check_int_timeout="10"
17-
curl --silent --output /dev/null --connect-timeout "${check_int_timeout}" https://"${check_int_address}:${check_int_port}" > /dev/null
17+
# shellcheck disable=SC2015
18+
command -v torsocks > /dev/null 2>&1 && [ "$(get_os_release_type)" != 'Darwin' ] &&
19+
torsocks curl --silent --output /dev/null --retry 5 --connect-timeout "${check_int_timeout}" https://"${check_int_address}:${check_int_port}" > /dev/null ||
20+
curl --silent --output /dev/null --retry 5 --connect-timeout "${check_int_timeout}" https://"${check_int_address}:${check_int_port}" > /dev/null
1821
}
1922

2023
display_macos_warning() {
@@ -142,7 +145,9 @@ install_build_dependencies_zypper() {
142145

143146
install_runtime_dependencies_apk() {
144147
dependencies_url="https://github.com/bitcoin-tools/nodebuilder/raw/master/dependencies/runtime_dependencies_apk.txt"
145-
dependencies=$(curl --fail --silent --show-error --location --retry 5 --retry-delay 10 "${dependencies_url}")
148+
command -v torsocks > /dev/null 2>&1 &&
149+
dependencies=$(torsocks curl --fail --silent --show-error --location --retry 5 --retry-delay 10 "${dependencies_url}") ||
150+
dependencies=$(curl --fail --silent --show-error --location --retry 5 --retry-delay 10 "${dependencies_url}")
146151
if [ -n "${dependencies}" ]; then
147152
printf '%s\n' "${dependencies}" | xargs sudo apk --quiet add
148153
else
@@ -153,7 +158,9 @@ install_runtime_dependencies_apk() {
153158
install_runtime_dependencies_aptget() {
154159
check_dpkg_lock
155160
dependencies_url="https://github.com/bitcoin-tools/nodebuilder/raw/master/dependencies/runtime_dependencies_aptget.txt"
156-
dependencies=$(curl --fail --silent --show-error --location --retry 5 --retry-delay 10 "${dependencies_url}")
161+
command -v torsocks > /dev/null 2>&1 &&
162+
dependencies=$(torsocks curl --fail --silent --show-error --location --retry 5 --retry-delay 10 "${dependencies_url}") ||
163+
dependencies=$(curl --fail --silent --show-error --location --retry 5 --retry-delay 10 "${dependencies_url}")
157164
if [ -n "${dependencies}" ]; then
158165
printf '%s\n' "${dependencies}" | xargs sudo DEBIAN_FRONTEND=noninteractive apt-get -qq install --assume-yes --no-install-recommends > /dev/null
159166
else
@@ -194,7 +201,9 @@ install_runtime_dependencies_darwin() {
194201

195202
install_runtime_dependencies_dnf() {
196203
dependencies_url="https://github.com/bitcoin-tools/nodebuilder/raw/master/dependencies/runtime_dependencies_dnf.txt"
197-
dependencies=$(curl --fail --silent --show-error --location --retry 5 --retry-delay 10 "${dependencies_url}")
204+
command -v torsocks > /dev/null 2>&1 &&
205+
dependencies=$(torsocks curl --fail --silent --show-error --location --retry 5 --retry-delay 10 "${dependencies_url}") ||
206+
dependencies=$(curl --fail --silent --show-error --location --retry 5 --retry-delay 10 "${dependencies_url}")
198207
if [ -n "${dependencies}" ]; then
199208
printf '%s\n' "${dependencies}" | xargs sudo dnf --assumeyes --quiet install > /dev/null
200209
else
@@ -204,7 +213,9 @@ install_runtime_dependencies_dnf() {
204213

205214
install_runtime_dependencies_pacman() {
206215
dependencies_url="https://github.com/bitcoin-tools/nodebuilder/raw/master/dependencies/runtime_dependencies_pacman.txt"
207-
dependencies=$(curl --fail --silent --show-error --location --retry 5 --retry-delay 10 "${dependencies_url}")
216+
command -v torsocks > /dev/null 2>&1 &&
217+
dependencies=$(torsocks curl --fail --silent --show-error --location --retry 5 --retry-delay 10 "${dependencies_url}") ||
218+
dependencies=$(curl --fail --silent --show-error --location --retry 5 --retry-delay 10 "${dependencies_url}")
208219
if [ -n "${dependencies}" ]; then
209220
printf '%s\n' "${dependencies}" | xargs sudo pacman -Syu --needed --noconfirm --quiet > dev/null
210221
else
@@ -214,7 +225,9 @@ install_runtime_dependencies_pacman() {
214225

215226
install_runtime_dependencies_zypper() {
216227
dependencies_url="https://github.com/bitcoin-tools/nodebuilder/raw/master/dependencies/runtime_dependencies_zypper.txt"
217-
dependencies=$(curl --fail --silent --show-error --location --retry 5 --retry-delay 10 "${dependencies_url}")
228+
command -v torsocks > /dev/null 2>&1 &&
229+
dependencies=$(torsocks curl --fail --silent --show-error --location --retry 5 --retry-delay 10 "${dependencies_url}") ||
230+
dependencies=$(curl --fail --silent --show-error --location --retry 5 --retry-delay 10 "${dependencies_url}")
218231
if [ -n "${dependencies}" ]; then
219232
printf '%s\n' "${dependencies}" | xargs sudo zypper --non-interactive --quiet install > /dev/null
220233
else
@@ -613,7 +626,10 @@ elif [ "${compile_bitcoin:-"false"}" = "true" ] || [ "$(get_os_release_type)" =
613626
;;
614627
esac
615628
printf '%s\n %s' "ok." "Downloading Bitcoin source code... "
616-
git clone --branch "v${target_bitcoin_version}" --single-branch --depth 1 --quiet -c advice.detachedHead=false https://github.com/bitcoin/bitcoin.git "${compile_directory}"
629+
# shellcheck disable=SC2015
630+
command -v torsocks > /dev/null 2>&1 && [ "$(get_os_release_type)" != 'Darwin' ] &&
631+
torsocks git clone --branch "v${target_bitcoin_version}" --single-branch --depth 1 --quiet -c advice.detachedHead=false https://github.com/bitcoin/bitcoin.git "${compile_directory}" ||
632+
git clone --branch "v${target_bitcoin_version}" --single-branch --depth 1 --quiet -c advice.detachedHead=false https://github.com/bitcoin/bitcoin.git "${compile_directory}"
617633
cd "${compile_directory}"/
618634
printf '%s\n %s' "ok." "Analyzing hardware confgiruation... "
619635
./autogen.sh > /dev/null 2> "${stderr_compile_log_file}"
@@ -677,9 +693,18 @@ else
677693
guix_sigs_temporary_dir="${temp_directory}/guix.sigs"
678694
guix_sigs_destination_dir="${HOME}/Downloads/guix.sigs"
679695
printf ' %s' "Downloading Bitcoin Core... "
680-
curl --fail --silent --show-error --location --retry 5 --retry-delay 10 --output "${bitcoin_tarball_temporary_file}" "${bitcoin_tarball_file_source}"
681-
curl --fail --silent --show-error --location --retry 5 --retry-delay 10 --output "${bitcoin_hash_file}" "${bitcoin_hash_file_source}"
682-
curl --fail --silent --show-error --location --retry 5 --retry-delay 10 --output "${gpg_signatures_file}" "${gpg_signatures_file_source}"
696+
if command -v torsocks > /dev/null 2>&1 && [ "$(get_os_release_type)" != 'Darwin' ]; then
697+
torsocks curl --fail --silent --show-error --location --retry 5 --retry-delay 10 --output "${bitcoin_hash_file}" "${bitcoin_hash_file_source}" ||
698+
curl --fail --silent --show-error --location --retry 5 --retry-delay 10 --output "${bitcoin_hash_file}" "${bitcoin_hash_file_source}"
699+
torsocks curl --fail --silent --show-error --location --retry 5 --retry-delay 10 --output "${gpg_signatures_file}" "${gpg_signatures_file_source}" ||
700+
curl --fail --silent --show-error --location --retry 5 --retry-delay 10 --output "${gpg_signatures_file}" "${gpg_signatures_file_source}"
701+
torsocks curl --fail --silent --show-error --location --retry 5 --retry-delay 10 --output "${bitcoin_tarball_temporary_file}" "${bitcoin_tarball_file_source}" ||
702+
curl --fail --silent --show-error --location --retry 5 --retry-delay 10 --output "${bitcoin_tarball_temporary_file}" "${bitcoin_tarball_file_source}"
703+
else
704+
curl --fail --silent --show-error --location --retry 5 --retry-delay 10 --output "${bitcoin_hash_file}" "${bitcoin_hash_file_source}"
705+
curl --fail --silent --show-error --location --retry 5 --retry-delay 10 --output "${gpg_signatures_file}" "${gpg_signatures_file_source}"
706+
curl --fail --silent --show-error --location --retry 5 --retry-delay 10 --output "${bitcoin_tarball_temporary_file}" "${bitcoin_tarball_file_source}"
707+
fi
683708
printf '%s\n' "ok."
684709

685710
printf ' %s' "Validating the checksum... "
@@ -704,7 +729,10 @@ else
704729
if [ -d "${guix_sigs_destination_dir}"/ ]; then
705730
gpg --quiet --import "${guix_sigs_destination_dir}"/builder-keys/*.gpg
706731
else
707-
git clone --single-branch --depth 1 --quiet "${guix_sigs_repo}" "${guix_sigs_temporary_dir}"
732+
# shellcheck disable=SC2015
733+
command -v torsocks > /dev/null 2>&1 && [ "$(get_os_release_type)" != 'Darwin' ] &&
734+
torsocks git clone --single-branch --depth 1 --quiet "${guix_sigs_repo}" "${guix_sigs_temporary_dir}" ||
735+
git clone --single-branch --depth 1 --quiet "${guix_sigs_repo}" "${guix_sigs_temporary_dir}"
708736
gpg --quiet --import "${guix_sigs_temporary_dir}"/builder-keys/*.gpg
709737
fi
710738
gpg_good_signature_count=$(gpg --verify "${gpg_signatures_file}" 2>&1 | grep -c "^gpg: Good signature from ")
@@ -786,7 +814,12 @@ if [ "$(uname -s)" != "Darwin" ]; then
786814
shortcut_filename="bitcoin_core.desktop"
787815

788816
[ -d "$(dirname "${shortcut_image_file}")" ] || mkdir -p "$(dirname "${shortcut_image_file}")"
789-
[ -f "${shortcut_image_file}" ] || curl --silent --show-error --location --fail --output "${shortcut_image_file}" "${shortcut_image_source}"
817+
if ! [ -f "${shortcut_image_file}" ]; then
818+
# shellcheck disable=SC2015
819+
command -v torsocks > /dev/null 2>&1 && [ "$(get_os_release_type)" != 'Darwin' ] &&
820+
torsocks curl --silent --show-error --location --fail --output "${shortcut_image_file}" "${shortcut_image_source}" ||
821+
curl --silent --show-error --location --fail --output "${shortcut_image_file}" "${shortcut_image_source}"
822+
fi
790823

791824
## Create .desktop on the user's Desktop and "Show Applications" directories
792825
[ -d "${desktop_path}" ] || mkdir -p "${desktop_path}"

0 commit comments

Comments
 (0)