Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save ray-bun/0eb123a9b4cd062ae3e15a55b433cd64 to your computer and use it in GitHub Desktop.

Select an option

Save ray-bun/0eb123a9b4cd062ae3e15a55b433cd64 to your computer and use it in GitHub Desktop.
Install full Bicoin Node (bitcoind) and Lightning Network (lnd) with TOR, Balance of Satoshi (BOS) on Linux Ubuntu 21.04 x64 with 600 GB block
#!/bin/bash
#https://gist.github.com/royalgarter/834662e43944a94ba56e65b0e0408c39#file-setup_btc_prune_node_ubuntu18_do-sh
#https://stopanddecrypt.medium.com/a-complete-beginners-guide-to-installing-a-lightning-node-on-linux-2021-edition-ece227cfc35d#66eb
#https://stopanddecrypt.medium.com/a-complete-beginners-guide-to-installing-a-bitcoin-full-node-on-linux-2021-edition-46bf20fbe8ff
# Test after install bitcoin: btc getzmqnotifications
echo "run lsblk to find data disk and change devname below. Create new empty partitions and mount to /home"
devname=xvdb
#devname=sda
#devname=sdb
`parted -s /dev/$devname mklabel gpt`
sleep 3
`parted -s /dev/$devname unit mib mkpart primary 0% 100%`
sleep 3
`mkfs.ext4 /dev/${devname}1`
sleep 3
devid=`blkid -s PARTUUID -o value /dev/${devname}1`
echo "Disk ID: $devid"
echo "PARTUUID=$devid /home ext4 defaults,noatime,nofail 0 0" >> /etc/fstab
sleep 3
mount /home
echo "########### Changing to home dir"
cd /home/
echo "########### Updating Ubuntu"
apt-get -y update
echo "Install Git"
apt-get -y install git
echo "########### Create Bitcoin User, add to super user shell and change bash for the user"
username="satoshi"
useradd -m $username
usermod -aG sudo $username
chsh -s /bin/bash $username
echo "Make code dir and Clone The Bitcoin repository"
mkdir -p "/home/$username/code" && cd "/home/$username/code"
git clone https://github.com/bitcoin/bitcoin.git
cd bitcoin
echo "Install libraries"
apt-get -y install build-essential libtool autotools-dev automake pkg-config bsdmainutils python3 libevent-dev
apt-get -y install libboost-system-dev libboost-filesystem-dev libboost-test-dev libboost-thread-dev
apt-get -y install libsqlite3-dev
apt-get -y install libminiupnpc-dev
apt-get -y install libzmq3-dev
apt-get -y install libqt5gui5 libqt5core5a libqt5dbus5 qttools5-dev qttools5-dev-tools
apt-get -y install libqrencode-dev
apt-get -y install golang-go
apt-get -y install tor
apt-get -y install nodejs
apt-get -y install npm
echo "Configure Tor To Start During Boot Up"
usermod -a -G debian-tor $username
systemctl enable tor
systemctl start tor
echo "########### Creating Swap"
dd if=/dev/zero of=/swapfile bs=1M count=2048 ; mkswap /swapfile ; swapon /swapfile
echo "/swapfile swap swap defaults 0 0" >> /etc/fstab
echo "Install the Berkeley DB"
cd "/home/$username/code/bitcoin"
./contrib/install_db4.sh `pwd`
echo "Prepare for installing Bitcoin"
cd "/home/$username/code/bitcoin"
git checkout tags/v22.0
./autogen.sh
echo "More preparation"
export BDB_PREFIX="/home/$username/code/bitcoin/db4"
./configure BDB_LIBS="-L${BDB_PREFIX}/lib -ldb_cxx-4.8" BDB_CFLAGS="-I${BDB_PREFIX}/include"
echo "Compile & Install Bitcoin"
make
make install
echo "########### Creating config"
cd "/home/$username"
sudo -u $username mkdir .bitcoin
config=".bitcoin/bitcoin.conf"
sudo -u $username touch $config
randUser=`< /dev/urandom tr -dc A-Za-z0-9 | head -c30`
randPass=`< /dev/urandom tr -dc A-Za-z0-9 | head -c30`
echo "
# Needed for full validation
assumevalid=0
# Improves LND performance
# Needs to be set now if you're going to install Lightning later
txindex=1
# Allows LND to connect to the Bitcoin node via an RPC user & pass
rpcuser=$randUser
rpcpassword=$randPass
# Allows LND & Bitcoin Core to communicate via ZeroMQ
zmqpubrawblock=tcp://127.0.0.1:28332
zmqpubrawtx=tcp://127.0.0.1:28333
## Tor Settings
debug=tor
onlynet=onion
proxy=127.0.0.1:9050
bind=127.0.0.1
dnsseed=0
dns=0
## Tor v3 Seeds
addnode=kpgvmscirrdqpekbqjsvw5teanhatztpp2gl6eee4zkowvwfxwenqaid.onion
addnode=bnx4povtqynvwnui5oqm5xcxqvat3j7yzgn6mqciuyszqawhuayvyaid.onion:8333
addnode=wyg7twmf7t3pfvfpdcfd64wvjj2pkccuui7ew34ovnqung5f623b4yyd.onion
addnode=glm52zywiqrcxuwswvgjsxr5pfeggil7uci4z5tbpvb4rjyu5hwjhtid.onion
addnode=xspiicyddsdmzxsffzw6z4f22wi2iwyyufkjcaj2qr7cznxymtft5nid.onion
addnode=nqb5q6d4nhp54ziahhm2oxopqwyyulg7nrqwrcmfvwhj7y7xasaeg7ad.onion
addnode=vp4qo7u74cpckygkfoeu4vle2yqmxh7zuxqvtkazp4nbvjnxl2s3e6id.onion
addnode=ew7x2hv76f7w7irfyektnbhd42eut27ttbfgggu7lbpxsyrlfvsujuqd.onion
addnode=qxkgr5u4rmwme5jticjuuqrecw5vfc5thcqdxvbffwbqgqkdin7s7vid.onion
## Tor v2 Seeds
addnode=bitcoinostk4e4re.onion
addnode=bk7yp6epnmcllq72.onion
addnode=qg6embx5o6p4h4it.onion:8333
addnode=trjbor5uc63ghwug.onion:8333
addnode=3eznsanhteo4m2k2.onion:8333
addnode=ajjnxnxjtx6ci4cp.onion:8333
addnode=icbbaj7up3kzk4cl.onion:8333
addnode=n4n5lzeyiyi2755c.onion:8333
addnode=opw6r3lacfd4eyys.onion:8333
addnode=qdwrjk2ow3yjckne.onion:8333
addnode=wjpkhpyt2gd4jtid.onion:8333
addnode=k7ktw2e5mj4r4na5.onion:8333
addnode=zilzmq3jbzdj63md.onion:8333
addnode=4nnijtmfxeueix7s.onion:8333
addnode=s4gy4h3u5zjmpbtr.onion:8333
addnode=33vdhmzdfimfgov3.onion:8333
addnode=aipupphit3enggpj.onion:8333
" > $config
# Tor Config
echo "########### Configuring Tor For Bitcoin & Lightning"
torconfig="/etc/tor/torrc"
echo "
SOCKSPort 9050
Log notice stdout
ControlPort 9051
CookieAuthentication 1
CookieAuthFileGroupReadable 1
HiddenServiceDir /var/lib/tor/lnd/
HiddenServicePort 8080 127.0.0.1:8080
" >> $torconfig
echo "########### Changing to home dir"
cd /home/$username/
echo "############ Add an alias for easy use"
sudo -u $username echo "alias btc=\"sudo -u $username bitcoin-cli -datadir=/home/$username/.bitcoin\"" >> /home/$username/.bashrc # example use: btc getinfo
echo "############ Install Lightning"
sudo chown -R $username: /home/$username/code/
cd "/home/$username/code/"
#Download and install go
echo "export PATH=$PATH:/home/$username/go/bin:/home/$username/.npm-global/bin" >> /home/$username/.bashrc
git clone https://github.com/lightningnetwork/lnd
cd "/home/$username/code/lnd"
git checkout tags/v0.14.1-beta
sudo -u $username make install
#https://stopanddecrypt.medium.com/running-bitcoin-lightning-nodes-over-the-tor-network-2021-edition-489180297d5#d4a8
echo "########### Creating LND config"
cd "/home/$username"
sudo -u $username mkdir .lnd
config=".lnd/lnd.conf"
sudo -u $username touch $config
echo "
## LND Settings
# Lets LND know to run on top of Bitcoin (as opposed to Litecoin)
bitcoin.active=true
bitcoin.mainnet=true
# Lets LND know you are running Bitcoin Core (not btcd or Neutrino)
bitcoin.node=bitcoind
## Bitcoind Settings
# Tells LND what User/Pass to use to RPC to the Bitcoin node
bitcoind.rpcuser=$randUser
bitcoind.rpcpass=$randPass
# Allows LND & Bitcoin Core to communicate via ZeroMQ
bitcoind.zmqpubrawblock=tcp://127.0.0.1:28332
bitcoind.zmqpubrawtx=tcp://127.0.0.1:28333
## Zap Settings
# Enables LND's REST interface
# Zap mobile wallet will connect over Tor through this interface
restlisten=localhost:8080
# Tells LND to listen on all of your computer's interfaces
# This could alternatively be set to your router's subnet IP
tlsextraip=0.0.0.0
# Tells LND where to listen for RPC messages
# This could also be set to your router's subnet IP
rpclisten=0.0.0.0:10009
# Tor Settings
tor.active=true
tor.v3=true
tor.streamisolation=true
listen=localhost
" > $config
echo "Install bitcoind as a service to start on reboot"
bitcoindsystemdpath="/etc/systemd/system/bitcoind.service"
echo "
[Unit]
Description=bitcoin
After=network.target
[Service]
Type=forking
User=$username
Group=sudo
ExecStart=/usr/local/bin/bitcoind -daemonwait \
-pid=/home/$username/.bitcoin/bitcoind.pid \
-conf=/home/$username/.bitcoin/bitcoin.conf \
-datadir=/home/$username/.bitcoin
[Install]
WantedBy=multi-user.target
" > $bitcoindsystemdpath
echo "Install lnd as a service to start on reboot"
lnddsystemdpath="/etc/systemd/system/lnd.service"
echo "
[Unit]
Description=LND Lightning Daemon
Requires=bitcoind.service
After=bitcoind.service
# for use with sendmail alert
#OnFailure=systemd-sendmail@%n
[Service]
ExecStart=/home/$username/go/bin/lnd
PIDFile=/home/$username/.lnd/lnd.pid
User=$username
Group=sudo
Type=simple
KillMode=process
TimeoutSec=180
Restart=always
RestartSec=60
[Install]
WantedBy=multi-user.target
" > $lnddsystemdpath
#https://github.com/alexbosworth/run-lnd
echo "Manage debug.log file monthly"
logrotatepath="/etc/logrotate.d/bitcoin-debug"
echo "
/home/$username/.bitcoin/debug.log
{
rotate 5
copytruncate
daily
missingok
notifempty
compress
delaycompress
sharedscripts
}
" > $logrotatepath
echo "instll BOS"
npmglobalpath="/home/$username/.npm-global"
sudo -u $username mkdir $npmglobalpath
sudo -u $username npm config set prefix $npmglobalpath
npm install -g balanceofsatoshis
#generate random password
openssl rand -hex 21 > "/home/$username/.lnd/wallet_password"
echo "
#Systemd unit for Bos-Telegram Bot
#/etc/systemd/system/bos-telegram.service
[Unit]
Description=bos-telegram
Wants=lnd.service
After=lnd.service
[Service]
#Create your wallet with the generate password. Replace xxtelegramconnectioncodeherexx with your telegram connection ID
ExecStartPre=/bin/sleep 30
ExecStartPre=/home/$username/.npm-global/bin/bos unlock /home/$username/.lnd/wallet_password
ExecStart=/home/$username/.npm-global/bin/bos telegram --connect xxtelegramconnectioncodeherexx
ExecStartPost=/bin/sleep 30
User=$username
Group=sudo
Restart=always
TimeoutSec=120
RestartSec=30
StandardOutput=null
StandardError=journal
[Install]
WantedBy=multi-user.target
" > /etc/systemd/system/bos-telegram.service
echo "Start Bitcoind and LND services and reboot"
systemctl daemon-reload
systemctl enable bitcoind
systemctl enable lnd
systemctl enable bos-telegram.service
systemctl stop bitcoind
systemctl stop lnd
systemctl start bitcoind
systemctl start lnd
systemctl start bos-telegram.service
reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment