Bitcoin Unlimited

by pmorici
27 deployments · 10 still active · last rev. 2 months ago

Deploy a Bitcoin node. This Stackscript works with Bitcoin Classic and Bitocin Unlimited just change the URL in the script options when you are deploying to the URL of the desired version. The default is Bitcoin Unlimited.

Compatible with: Debian 8
						#!/bin/bash
# <UDF name="node_user" label="Username" default="satoshi"/>
# <UDF name="node_password" label="Password"/>
# <UDF name="bitcoin_url" label="Bitcoin URL" default="https://www.bitcoinunlimited.info/downloads/bitcoinUnlimited-0.12.1-linux64.tar.gz"/>
# <UDF name="node_type" label="Node Type" oneof="full,pruned" default="full"/>

echo 'Acquire::ForceIPv4 "true";' >> /etc/apt/apt.conf.d/99force-ipv4

apt-get -y update
apt-get -y upgrade

apt-get -y install vim
apt-get -y install sudo
apt-get -y remove nfs-common
apt-get -y remove rpcbind
apt-get -y autoremove

iptables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
iptables -A INPUT -p tcp --dport 8333 -j ACCEPT
iptables -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
iptables -A INPUT -i lo -j ACCEPT
iptables -P INPUT DROP
iptables -P FORWARD DROP

ip6tables -A INPUT -p tcp --dport 22 -m conntrack --ctstate NEW,ESTABLISHED -j ACCEPT
ip6tables -A INPUT -p tcp --dport 8333 -j ACCEPT
ip6tables -A INPUT -m conntrack --ctstate ESTABLISHED -j ACCEPT
ip6tables -A INPUT -i lo -j ACCEPT
ip6tables -P INPUT DROP
ip6tables -P FORWARD DROP

echo "iptables-persistent iptables-persistent/autosave_v4 boolean true" | debconf-set-selections
echo "iptables-persistent iptables-persistent/autosave_v6 boolean true" | debconf-set-selections
apt-get -y install iptables-persistent

echo "unattended-upgrades unattended-upgrades/enable_auto_updates boolean true" | debconf-set-selections
apt-get -y install unattended-upgrades

adduser --system --group --home /var/lib/bitcoind bitcoind

adduser --disabled-password --gecos "" $NODE_USER
echo "$NODE_USER:$NODE_PASSWORD" | chpasswd
usermod -aG sudo $NODE_USER
sed -i 's/PermitRootLogin yes/PermitRootLogin no/' /etc/ssh/sshd_config
/etc/init.d/ssh reload

wget "$BITCOIN_URL" -O bitcoin.tar.gz
tar -xzf bitcoin.tar.gz

install bitcoin*-*.*.*/bin/* /usr/local/bin/
install bitcoin*-*.*.*/include/* /usr/local/include/
cp -d bitcoin*-*.*.*/lib/* /usr/local/lib/
ldconfig

rm -rf bitcoin*

PRUNE_OPTION=""
if [ "$NODE_TYPE" == "pruned" ]
then
	PRUNE_OPTION="prune=20000"
fi

cat << EOF > /var/lib/bitcoind/bitcoin.conf
rpcuser=bitcoinrpc
rpcpassword=$(dd if=/dev/urandom bs=1 count=32 2>/dev/null | base64 -w 0 | rev | cut -b 2- | rev)
${PRUNE_OPTION}
daemon=1
pid=/var/lib/bitcoind/bitcoind.pid
datadir=/var/lib/bitcoind
EOF
chown bitcoind:bitcoind /var/lib/bitcoind/bitcoin.conf
chmod go-rwx /var/lib/bitcoind/bitcoin.conf

mkdir -p /usr/local/lib/systemd/system/
cat << EOF > /usr/local/lib/systemd/system/bitcoind.service
[Unit]
Description=Bitcoin Node / bitcoind
After=network.target

[Service]
Type=forking
User=bitcoind
ExecStart=/usr/local/bin/bitcoind -conf=/var/lib/bitcoind/bitcoin.conf
ExecStop=/usr/local/bin/bitcoin-cli -conf=/var/lib/bitcoind/bitcoin.conf stop
PIDFile=/var/lib/bitcoind/bitcoind.pid

[Install]
WantedBy=multi-user.target
EOF

systemctl enable bitcoind
systemctl start bitcoind

eval mkdir -p "~$NODE_USER/.bitcoin"
eval cp /var/lib/bitcoind/bitcoin.conf "~$NODE_USER/.bitcoin/bitcoin.conf"
eval chown -R $NODE_USER:$NODE_USER "~$NODE_USER/.bitcoin"

#
# To start bitcoind manualy you can run...
#
# sudo -u bitcoind bitcoind -conf=/var/lib/bitcoind/bitcoin.conf