Code Monkey home page Code Monkey logo

nodebuilder's Introduction

Bitcoin Core Node Builder

Run a secure Bitcoin Core node with ease.

Copy-paste the following command into Terminal:

sh -c "$(curl -fsSL https://github.com/bitcoin-tools/nodebuilder/raw/v1.5.0/nodebuilder)"

Table of Contents

Usage

As mentioned above, start the script from the command line. Open Terminal and run:

sh -c "$(curl -fsSL https://github.com/bitcoin-tools/nodebuilder/raw/v1.4.0/nodebuilder)"

Or download the script to your local system, set permissions, and run it:

wget https://github.com/bitcoin-tools/nodebuilder/raw/v1.4.0/nodebuilder
chmod u+x nodebuilder
./nodebuilder

(Optional) Docker Container

A nodebuilder Docker container can either run on Ubuntu (default) or on an alternative Linux distribution: Alpine, Amazon, Arch, Debian, Fedora, Manjaro, openSUSE, and Red Hat.

To the Ubuntu base image, clone the repository and build the default container.

git clone https://github.com/bitcoin-tools/nodebuilder
cd nodebuilder/docker/
docker build .

To use an alternative base image, clone the repository and build a different container. For example, to run nodebuilder on Alpine Linux, run:

docker build -f Dockerfile_alpine .

(Optional) Command-Line Arguments

nodebuilder supports optional arguments to override the default semi-automated settings:

Short Long Version Description
-b --bitcoin-version Specify the Bitcoin version. Requires one argument, for example: -b 26.0
-c --compile Build Bitcoin from source. Requires no arguments.
-h --help Display the help message. Overrides all other arguments.
-p --prune Set a prune value in MiB. Requires one argument, for example: -p 50000
-t --test Run unit tests on functions.
-u --unattended Run in non-interactive mode. Requires no arguments.

You can set multiple options. Here are two ways to compile Bitcoin 26.0 unattended with a 50000 MiB prune:

./nodebuilder -b 26.0 -c -p 50000 -u
./nodebuilder --bitcoin-version 26.0 --compile --prune 50000 --unattended

Prerequisites

  1. An active internet connection (of course)
  2. A POSIX-compatible operating system
  3. curl, which the script will attempt to automatically install or you can install with a package manager

This POSIX-compliant script installs a minimal number of runtime dependencies that aren't defined in POSIX.

What Does This Script Do?

The script performs the following actions:

  1. Update the system (including reboot, if required) and install dependencies.
  2. Either download, validate, and extract Bitcoin Core or build directly from the source code.
  3. Set a prune for Bitcoin Core based on the disk free space.
  4. Create shortcuts for Bitcoin Core on the desktop and the "Show Applications" list.
  5. Start Bitcoin Core.
  6. Prevent the system from sleeping, suspending, and hibernating.
  7. Display relevant info while the initial block download proceeds, such as the percent synced, blocks left to sync, current chain tip date, and the free disk space remaining.
  8. After the initial block download completes, tell the user that the script has finished and end the script.

Which Parts of My System Does This Script Touch?

This script modifies the following in your file system:

  • Any files related to installing system updates and dependencies
  • The downloaded Bitcoin Core and validation files:
    • <temporary_directory>/compile_bitcoin/
    • <temporary_directory>/bitcoin-<version>-<architecture>-linux-gnu.tar.gz
    • <temporary_directory>/SHA256SUMS
    • <temporary_directory>/SHA256SUMS.asc
    • <temporary_directory>/guix.sigs/
  • The validated Bitcoin Core tarball and PGP keys:
    • ~/Downloads/bitcoin-<version>-<architecture>-linux-gnu.tar.gz
    • ~/Downloads/guix.sigs/
  • The installed Bitcoin Core executable binaries, headers, libraries, and manual pages, respectively, are installed into:
    • /usr/local/bin/{bitcoind,bitcoin-cli,bitcoin-qt,bitcoin-tx,bitcoin-util,bitcoin-wallet,test_bitcoin}
    • /usr/local/include/bitcoinconsensus.h
    • /usr/local/lib/{libbitcoinconsensus.so,libbitcoinconsensus.so.0,libbitcoinconsensus.so.0.0.0} on Linux
    • /usr/local/lib/libbitcoinconsensus.0.dylib on macOS
    • /usr/local/man/man1/{bitcoind.1,bitcoin-qt.1,bitcoin-cli.1,bitcoin-tx.1,bitcoin-util.1,bitcoin-wallet.1}
  • An entry in the Show Applications menu and also on the desktop:
    • ~/Desktop/bitcoin_core.desktop on Linux
    • ~/.local/share/applications/bitcoin_core.desktop on Linux
  • The Bitcoin Core configuration file:
    • ~/.bitcoin/bitcoin.conf on Linux
    • ~/Library/Application Support/Bitcoin/bitcoin.conf on macOS
  • Any files modified by Bitcoin Core, such as the blockchain, unspent transaction, and peer data.

How Do I Uninstall Everything?

An automated solution is in the backlog. For now, here are a series of manual steps to follow:

  • Uninstalling runtime dependencies can be be tricky. This script installs a minimal number of dependencies like curl, gzip, sudo, and tar as a defensive security posture. For advanced users, if you compiled Bitcoin from source by either using the -c/--compile optional argument or by running on Alpine Linux, please also review the build dependencies that were installed.

  • To remove the downloaded Bitcoin Core installation and verification files, open the Files or Finder application, go to Downloads, and remove any files starting with bitcoin-. Also remove the directory named guix.sigs.

    • Or do it in Terminal with rm ~/Downloads/bitcoin-*.tar.gz && rm -r ~/Downloads/guix.sigs/.
  • To remove the installed executable binaries, headers, libraries, and manual pages, open the Files or Finder application, go to /usr/local/bin, and remove bitcoind, bitcoin-cli, bitcoin-qt, bitcoin-util, bitcoin-wallet, and test_bitcoin. Then go to /usr/local/include and remove bitcoinconsensus.h. Then go to /usr/local/lib and remove libbitcoinconsensus.so, libbitcoinconsensus.so.0, libbitcoinconsensus.so.0.0.0 on Linux or libbitcoinconsensus.0.dylib on macOS. Then go to /usr/local/man/man1 and remove bitcoind.1, bitcoin-qt.1, bitcoin-cli.1, bitcoin-tx.1, bitcoin-util.1, and bitcoin-wallet.1.

    • Or do it in Terminal with rm /usr/local/bin/{bitcoind,bitcoin-cli,bitcoin-qt,bitcoin-tx,bitcoin-util,bitcoin-wallet,test_bitcoin} /usr/local/include/bitcoinconsensus.h /usr/local/lib/{libbitcoinconsensus.so,libbitcoinconsensus.so.0,libbitcoinconsensus.so.0.0.0} /usr/local/man/man1/{bitcoind.1,bitcoin-qt.1,bitcoin-cli.1,bitcoin-tx.1,bitcoin-util.1,bitcoin-wallet.1} on Linux or rm /usr/local/bin/{bitcoind,bitcoin-cli,bitcoin-qt,bitcoin-tx,bitcoin-util,bitcoin-wallet,test_bitcoin} /usr/local/include/bitcoinconsensus.h /usr/local/lib/libbitcoinconsensus.0.dylib /usr/local/man/man1/{bitcoind.1,bitcoin-qt.1,bitcoin-cli.1,bitcoin-tx.1,bitcoin-util.1,bitcoin-wallet.1} on macOS. If the command fails, your user doesn't have proper privileges. Try adding sudo to the front of the command.
  • To remove the shortcut files on Linux, go to the Desktop and remove the bitcoin_core.desktop file. Then go to ~/.local/share/applications and remove bitcoin_core.desktop.

    • Or do it in Terminal with rm ~/Desktop/bitcoin_core.desktop ~/.local/share/applications/bitcoin_core.desktop on Linux.
  • If you want to keep your synced blocks and chainstate data, open the Files or Finder application, go to the data directory at ~/.bitcoin on Linux or ~/Library/Application Support/Bitcoin on macOS, and either backup the blocks and chainstate directories to an external drive or move those directories somewhere else on your computer. (The next step will remove everything else from the Bitcoin Core data directory.)

    • Also open bitcoin.conf and make note of your prune value, in MiB (1024^2 bytes). Perhaps save that line (and only that line) to a text file wherever you copy/move the blocks and chainstate directories to. Any future Bitcoin Core nodes you run must have a prune setting less than or equal to this value, or you'll have to re-sync the chain.
  • To remove the data directory, open the Files or Finder application, go to the ~ on Linux or ~/Library/Application Support on macOS, and delete the data directory named .bitcoin on Linux or Bitcoin on macOS. You need to enable the "Show Hidden Files" option in the Files or Finder settings.

    • Or do it in Terminal with rm -r ~/.bitcoin/ on Linux or rm -r ~/Library/Application\ Support/Bitcoin/ on macOS.

If you have any questions or ideas on how this section can be improved, please open an issue.

Acknowledgements

Inspiration for this project came from these Open Source projects:

Contributing

Please open an issue for any bug reports or feature requests. You can see the list of open issues here.

If you plan to submit a pull request, please first look over our automated and manual test procedures.

License

This project is licensed under the terms of the MIT No Attribution / MIT-0 license.

nodebuilder's People

Contributors

bitcoin-tools avatar renovate-bot avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

22388o

nodebuilder's Issues

bug: cannot create directory, permission denied

...
  Extracting Bitcoin Core... ok.
  Running the unit tests... ok.
  Installing Bitcoin Core... mkdir: cannot create directory '/usr/local/share/man/man1': Permission denied
user1@comp1: $ mkdir -p /usr/local/share/man/man1
mkdir: cannot create directory '/usr/local/share/man/man1/': Permission denied
user1@comp1: $ sudo mkdir -p /usr/local/share/man/man1
user1@comp1: $ 

bug: err command not found

Seems to be a regressoin.

This happens when running into an error while checking for internet:

user1@comp1:~/Documents/GitHub/nodebuilder$ ./nodebuilder 
./nodebuilder: line 77: err: command not found
\E[6n
user1@comp1:~/Documents/GitHub/nodebuilder$ ^C
user1@comp1:~/Documents/GitHub/nodebuilder$ ^C
user1@comp1:~/Documents/GitHub/nodebuilder$ shellcheck nodebuilder 
user1@comp1:~/Documents/GitHub/nodebuilder$ bash -x nodebuilder 
+ set -o errexit
+ set -o nounset
+ set -o pipefail
+ trap handle_exit EXIT
+ trap 'handle_error ${LINENO:-}' ERR
+ target_bitcoin_version=26.0
++ uname -m
+ target_bitcoin_architecture=x86_64
+ case "$(uname -s)" in
++ uname -s
+ target_bitcoin_operating_system=linux-gnu
++ mktemp -d
+ temp_directory=/tmp/tmp.5redc0oxE7
+ bitcoin_core_data_dir=/home/user1/.bitcoin
+ user_data_dir=/home/user1/.local/share
+ shortcut_image_source=https://github.com/bitcoin-tools/nodebuilder/raw/master/data/bitcoin.png
+ shortcut_image_file=/home/user1/.local/share/images/bitcoin.png
+ timeout --preserve-status 0.1 nc -z 1.1.1.1 53
+ timeout --preserve-status 0.1 nc -z 8.8.8.8 53
+ timeout --preserve-status 0.5 nc -z bitcoincore.org 443
+ err 'ERROR: Check for active internet failed.'
nodebuilder: line 77: err: command not found
++ handle_error 77
++ ensure_cursor_is_on_column_one
++ printf %s '\E[6n'
\E[6n++ read -rsdR cursor_position
+++ handle_exit
+++ '[' -n /tmp/tmp.5redc0oxE7 ']'
+++ rm -rf -- /tmp/tmp.5redc0oxE7/

CI warning Node.js 16 actions are deprecated

Node.js 16 actions are deprecated. Please update the following actions to use Node.js 20: actions/upload-artifact@v3. For more information see: https://github.blog/changelog/2023-09-22-github-actions-transitioning-from-node-16-to-node-20/.

Distinguish between being run in a terminal vs run inside another script

This will be helpful as the project evolves to allow other projects to use the nodebuilder repo as a submodule.

Such as "install Bitcoin and perform the IBD, then afterwards run this other code that uses Bitcoin RPC calls."

Here's the contents of test_script_for_childparent.sh:

#!/bin/bash

echo "state\$PPID is $(ps -o stat= -p $PPID)"
echo "state\$\$ is $(ps -o stat= -p $$)"

Here's what happens when you run it:

user1@comp1:~/Desktop$ ./test_script_for_childparent.sh 
state$PPID is Ss
state$$ is S+
user1@comp1:~/Desktop$ ./test_script_for_childparent.sh &
[1] 10955
user1@comp1:~/Desktop$ state$PPID is Ss+
state$$ is S
[1]+  Done                    ./test_script_for_childparent.sh

Here's the contents of test_script_launcher.sh:

#!/bin/bash

/bin/bash -c "./test_script_for_childparent.sh"

Here's what happens when you run it:

user1@comp1:~/Desktop$ ./test_script_launcher.sh 
state$PPID is S+
state$$ is S+
user1@comp1:~/Desktop$ ./test_script_launcher.sh &
[1] 10967
user1@comp1:~/Desktop$ state$PPID is S
state$$ is S

[1]+  Done                    ./test_script_launcher.sh

Increase internet timeouts by 10x

During check for internet, increase the timeouts 10x from 0.1 -> 1 and 0.5 -> 5.

user1@comp1:~$ timeout --preserve-status 10 nc -z 1.1.1.1 53
user1@comp1:~$ echo $?
0
user1@comp1:~$ timeout --preserve-status 0.1 nc -z 1.1.1.1 53
user1@comp1:~$ echo $?
143
user1@comp1:~$ timeout --preserve-status 0.1 nc -z 1.1.1.1 53 && echo ok
user1@comp1:~$ timeout --preserve-status 1 nc -z 1.1.1.1 53 && echo ok
ok

bug: printf isn't printing line breaks with \n

This is the output to the user.

Syncing the block headers (second pass).\nHeaders synced:     747559\nChain sync size:    0 MiB\nDisk free space:    18 GiB\n\nSynchronizing can take weeks on a slow connection.\n

Replace echo -e and echo -n with printf

Inconsistent Behavior Across Different Systems

Another issue you might encounter is inconsistent behavior of the echo command across different systems. This is because the behavior of echo can vary depending on the system and the shell. For instance, some versions of echo support the ‘-e’ option, while others don’t.

If you’re writing a script that will be run on different systems, it might be better to use printf instead of echo, as printf has more consistent behavior.

Taken from https://ioflood.com/blog/bash-echo-newline/

Updated hardcoded archival node variable

Increase the hard-coded value for archival_node_required_disk_in_gib (line 256).

The sweet spot is about 50 to 100 GB more than the size of blocks/ + chainstate/.

Back in June 2023, that sum was 522. Now, it's 586.

user1@comp1:~$ du -hd1 .bitcoin/
576G	.bitcoin/blocks
9.9G	.bitcoin/chainstate
586G	.bitcoin/

Bring it back into the sweet spot.

Check if binary sha256sum is on PATH

Something like this:

if command -v sha256sum >/dev/null; then
   sha256sum_cmd="sha256sum"
elif command -v shasum >/dev/null; then
   sha256sum_cmd="shasum -a 256"
else
   >&2 echo "Either 'sha256sum' or 'shasum' must on PATH."
   >&2 echo "Exiting..."
   exit 1
fi

Taken from this GitHub commit

On macOS, clean up this error with `/proc/1/cgroup`

. ok.
  Removing temporary files... ok.
Creating application shortcuts... grep: /proc/1/cgroup: No such file or directory
/bin/bash: line 266: [: : integer expression expected
ok.
Starting Bitcoin Core... grep: /proc/1/cgroup: No such file or directory
/bin/bash: line 383: [: : integer expression expected
ok.

and

Disk free space:    58 GiB
grep: /proc/1/cgroup: No such file or directory
/bin/bash: line 464: [: : integer expression expected
Synchronizing can take weeks on a slow connection.

CI is failing due to restart required

From CI job https://github.com/bitcoin-tools/nodebuilder/actions/runs/7501247007/job/20421542028:

+ echo -n 'Performing a system upgrade... '
+ sudo NEEDRESTART_MODE=a apt-get -qq dist-upgrade --assume-yes
+ '[' -f /var/run/reboot-required ']'
++ cat /var/run/reboot-required.pkgs
+ echo -en '\nREBOOT REQUIRED to upgrade the following:\nlibc6\n\nPRESS ANY KEY to reboot or press Ctrl+C to exit... '
Performing a system upgrade... 
REBOOT REQUIRED to upgrade the following:
libc6

+ read -rsn1
+ echo Rebooting.
+ sudo reboot
PRESS ANY KEY to reboot or press Ctrl+C to exit... Rebooting.
+ exit 0
+ handle_exit
+ '[' -n /tmp/tmp.m1PIsurix2 ']'
+ rm -rf -- /tmp/tmp.m[1](https://github.com/bitcoin-tools/nodebuilder/actions/runs/7501247007/job/20421542028?pr=3#step:10:1)PIsurix[2](https://github.com/bitcoin-tools/nodebuilder/actions/runs/7501247007/job/20421542028?pr=3#step:10:2)/

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.