Skip to content

Instantly share code, notes, and snippets.

@boris
Created February 5, 2021 16:12
Show Gist options
  • Save boris/09a7a04ab70d49646379d5393fcfda8c to your computer and use it in GitHub Desktop.
Save boris/09a7a04ab70d49646379d5393fcfda8c to your computer and use it in GitHub Desktop.
bitcoind.sh
#!/bin/bash
VER=0.21.0
ARCH="aarch64"
echo "Installing Bitcoind $VER"
setup(){
sudo mkdir /data
UUID=$(sudo blkid -s UUID -o value /dev/xvdf1)
echo "UUID=$UUID /data ext4 defaults 0 0"| sudo tee -a /etc/fstab
sudo mount -a
sudo mkdir -p /data/{bitcoin,conf}
sudo useradd bitcoin
sudo chown -R bitcoin: /data/bitcoin/
}
get_files(){
curl -s -o /tmp/SHA256SUMS.asc https://bitcoincore.org/bin/bitcoin-core-$VER/SHA256SUMS.asc
curl -s -o /tmp/bitcoin-$VER-$ARCH-linux-gnu.tar.gz https://bitcoincore.org/bin/bitcoin-core-$VER/bitcoin-$VER-$ARCH-linux-gnu.tar.gz
sha256=$(sha256sum /tmp/bitcoin-$VER-$ARCH-linux-gnu.tar.gz | awk '{print $1}')
grep -w $sha256 /tmp/SHA256SUMS.asc
if [ $? -eq 0 ]; then
tar zxf /tmp/bitcoin-$VER-$ARCH-linux-gnu.tar.gz -C /tmp
else
echo "SHA256SUMS Invalid!"
exit 1
fi
}
copy_files(){
sudo cp /tmp/bitcoin-$VER/bin/bitcoind /usr/local/bin/bitcoind
sudo cp /tmp/bitcoin-$VER/bin/bitcoin-cli /usr/local/bin/bitcoin-cli
}
config_systemd(){
echo "Creating systemd config"
sudo tee /lib/systemd/system/bitcoind.service << 'EOF'
[Unit]
Description=Bitcoin daemon
After=network.target
[Service]
ExecStart=/usr/local/bin/bitcoind -daemon -pid=/run/bitcoind/bitcoind.pid -conf=/data/conf/bitcoin.conf -datadir=/data/bitcoin
Type=forking
PIDFile=/run/bitcoind/bitcoind.pid
Restart=on-failure
User=bitcoin
Group=bitcoin
RuntimeDirectory=bitcoind
RuntimeDirectoryMode=0710
ConfigurationDirectory=bitcoin
ConfigurationDirectoryMode=0710
StateDirectory=bitcoind
StateDirectoryMode=0710
# Provide a private /tmp and /var/tmp.
PrivateTmp=true
# Mount /usr, /boot/ and /etc read-only for the process.
ProtectSystem=full
# Disallow the process and all of its children to gain
# new privileges through execve().
NoNewPrivileges=true
# Use a new /dev namespace only populated with API pseudo devices
# such as /dev/null, /dev/zero and /dev/random.
PrivateDevices=true
# Deny the creation of writable and executable memory mappings.
MemoryDenyWriteExecute=true
[Install]
WantedBy=multi-user.target
EOF
echo "Reloading systemd"
sudo systemctl daemon-reload
sudo systemctl enable bitcoind
}
config_bitcoind(){
echo "Creating Bitcoind config"
sudo tee /data/conf/bitcoin.conf << 'EOF'
datadir=/data/bitcoin
rpcuser=<USER>
rpcpassword=<PASSWORD>
rpcbind=<NODE_IP>:8332
rpcallowip=<NETWORK>
rpcthreads=16
listen=1
maxconnections=10
txindex=1
upnp=0
maxmempool=1024
maxtxfee=0.95
deprecatedrpc=estimatefee
EOF
echo "CHECK:
- rpcuser definition!
- rpcpassword definition!
- rpcallowip definition!
"
}
clean(){
sudo rm -rf /tmp/bitcoin-$VER*
}
setup
get_files
copy_files
config_systemd
config_bitcoind
clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment