Skip to content

Instantly share code, notes, and snippets.

@ruanbekker
Created June 23, 2021 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ruanbekker/3c368a7db0f489a1bab4c5fb47ddd6f2 to your computer and use it in GitHub Desktop.
Save ruanbekker/3c368a7db0f489a1bab4c5fb47ddd6f2 to your computer and use it in GitHub Desktop.
Install Bitcoin Core Testnet on Linux Script
#!/usr/bin/env bash
# Note:
# I use this script to bootstrap testnet nodes, if you are using the mainnet,
# I STRONGLY recommend to set rpcallowip to localhost
# environment variables
export ARCH=x86_64
export BITCOIN_VERSION=0.21.1
export BITCOIN_URL=https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/bitcoin-${BITCOIN_VERSION}-${ARCH}-linux-gnu.tar.gz
export BITCOIN_SIGNATURE=01EA5486DE18A882D4C2684590C8019E36C2E964
export BITCOIN_DATA=/data
# add user, groups
sudo groupadd -r bitcoin
sudo useradd -r -m -g bitcoin -s /bin/bash bitcoin
# update and install dependencies
sudo apt update && sudo apt install ca-certificates gnupg gpg wget -qq --no-install-recommends -y
# get bitcoin core
cd /tmp
wget https://bitcoincore.org/bin/bitcoin-core-${BITCOIN_VERSION}/SHA256SUMS.asc
wget -qO bitcoin-${BITCOIN_VERSION}-${ARCH}-linux-gnu.tar.gz "${BITCOIN_URL}"
gpg --keyserver hkp://keyserver.ubuntu.com --recv-keys ${BITCOIN_SIGNATURE}
gpg --verify SHA256SUMS.asc
grep bitcoin-${BITCOIN_VERSION}-${ARCH}-linux-gnu.tar.gz SHA256SUMS.asc > SHA256SUM
sha256sum -c SHA256SUM
sudo tar -xzvf bitcoin-${BITCOIN_VERSION}-${ARCH}-linux-gnu.tar.gz -C /usr/local --strip-components=1 --exclude=*-qt
sudo rm -rf /tmp/*
sudo mkdir "$BITCOIN_DATA"
sudo chown -R bitcoin:bitcoin "$BITCOIN_DATA"
sudo ln -sfn "$BITCOIN_DATA" /home/bitcoin/.bitcoin
sudo chown -h bitcoin:bitcoin /home/bitcoin/.bitcoin
# create bitcoin config
cat > "bitcoin.conf.tmp" << EOF
datadir=/home/bitcoin/.bitcoin
printtoconsole=1
rpcallowip=::/0
rpcuser=${BITCOIN_RPC_USER:-bitcoin}
rpcpassword=${BITCOIN_RPC_PASSWORD:-$(openssl rand -hex 26)}
testnet=1
prune=1000
[test]
rpcport=18332
EOF
# create systemd unit file
cat > bitcoind.service << EOF
[Unit]
Description=Bitcoin Core Testnet
After=network.target
[Service]
User=bitcoin
Group=bitcoin
WorkingDirectory=/home/bitcoin
Type=simple
ExecStart=/usr/local/bin/bitcoind -conf=/home/bitcoin/.bitcoin/bitcoin.conf
[Install]
WantedBy=multi-user.target
EOF
# move config and set permissions
sudo mv bitcoin.conf.tmp "$BITCOIN_DATA/bitcoin.conf"
sudo chown bitcoin:bitcoin "$BITCOIN_DATA/bitcoin.conf"
sudo chown -R bitcoin "$BITCOIN_DATA"
sudo ln -sfn "$BITCOIN_DATA" /home/bitcoin/.bitcoin
sudo chown -R bitcoin:bitcoin /home/bitcoin/.bitcoin
# move systemd unit file and start bitcoin core
sudo mv bitcoind.service /etc/systemd/system/bitcoind.service
sudo systemctl daemon-reload
sudo systemctl enable bitcoind
sudo systemctl restart bitcoind
sleep 5
sudo systemctl status bitcoind
# view config
cat /home/bitcoin/.bitcoin/bitcoin.conf | grep -E '(rpcuser|rpcpassword|rpcport)'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment