Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working standup scripts #15

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions Scripts/scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Bitcoin Standup Scripts - Blockchain Commons

Contributor: jodobear 20-07-03

**DISCLAIMER:** It is not a good idea to store large amounts of Bitcoin on a VPS, ideally you should use this as a watch-only wallet. This script is a work-in-progress and has not been widely tested. The creators are not responsible for loss of funds. If you are not familiar with running a node or how Bitcoin works then we urge you to use this in testnet so that you can use it as a learning tool.


## Usage

The script is inteded for a fresh bitcoin setup. Re-running the script on an already setup server is intended only for advanced users.

It downloads Bitcoin Core over Tor. You can specify any path for the blockchain data and Electrs data.

To run this script you need to be logged in as root, and enter in the commands listed below:

(The $ or # represents a terminal commmand prompt, do not actually type in a $ or #.)

1. Give the root user a password, enter the following command and set a password:
$ sudo passwd

2. Switch to the root user:
$ sudo su

3. Edit config for your node setup using your favourite text editor:
# nano ss.conf

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be helpful to say. "You must change [A], and you will probably want to change [B] and [C], but look at the whole file.

Copy link
Author

@jodobear jodobear Oct 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the following:

You must modify USERPASS else, your server will be unprotected and provide values for all the variables under VPS if installing on a VPS and set to true. Do note that the script defaults to testnet full node. Make appropriate changes.

4. Source the script:
# source ss_00_main.sh

5. Display help:
# source ss_00_main.sh -h

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be an extra step. (This implies that you need to source the script, then get the help.)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed to source ss_01_help.sh

This script can be installed on any Debian based system. By default this script will:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
This script can be installed on any Debian based system. By default this script will:
This script can be installed on any Debian based system. The [Debian base system](https://www.debian.org/doc/debian-policy/ch-binary.html#base-system) installs the following packages which this script assumes are [standard](https://wiki.debian.org/tasksel#A.22standard.22_task):
<pre>
$ aptitude search ~pimportant ~prequired ~pimportant -F%p
adduser
apt
apt-utils
base-files
base-passwd
bash
bsdmainutils
bsdutils
coreutils
cpio
cron
dash
debconf
debconf-i18n
debian-archive-keyring
debianutils
diffutils
dmidecode
dpkg
e2fslibs
e2fsprogs
fdisk
findutils
gdbm-l10n
gpgv
grep
gzip
hostname
ifupdown
init
init-system-helpers
iproute2
iptables
iputils-ping
isc-dhcp-client
isc-dhcp-common
kmod
less
libapt-inst2.0
libapt-pkg5.0
libc-bin
libcomerr2
libpam-modules
libpam-modules-bin
libpam-runtime
libss2
libudev1
login
logrotate
mawk
mount
nano
ncurses-base
ncurses-bin
netbase
passwd
perl-base
procps
readline-common
rsyslog
sed
sensible-utils
systemd
systemd-sysv
sysvinit-utils
tar
tasksel
tasksel-data
tzdata
udev
util-linux
vim-common
vim-tiny
whiptail
</pre>
By default this script will:


- Update the OS
- Set Automatic Updates On
- Create User: standup
- Install UFW, haveguard, gnupg2, git & make
- Install Tor
- Install Bitcoin Core on mainnet with txindex=1 if setting up unpruned node.
- Setup Bitcoin Core as systemd service and to start at reboot or after a crash.
- Start Bitcoin Core

Optionally you can install:
---------------------------
- Install c-lightning or LND
- Install Esplora
- Install BTCPay**

** Work-in-progress

QR Code:
--------
Upon completion of the script there will be a QR code saved to /qrcode.png which you can open and scan:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see anything that installs a qrcode.png right now.

ls -lagh /qrcode.png

ls: cannot access '/qrcode.png': No such file or directory

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. I definitely missed that one


1. Install fim:
$ sudo apt-get install fim
2. Then, display the QR code in terminal (as root):
# fim -a qrcode.png

It is highly recommended to add a Tor V3 pubkey for cookie authentication so that even if your QR code is compromised an attacker would not be able to access your node.

It is recommended to delete the /qrcode.png.
Additionally, unless you face installation issues and need to assisstance delete /standup.log, and /standup.err


## TODO

1. Conclude the Esplora `dist` [issue](https://github.com/Blockstream/esplora/issues/156)
2. Find solution to BTCPay Server corrupting blockchain directory when creating a softlink.
3. Check implementation & test FastSync.
4. C-lightning HTTP plugin.
5. Explore HWI.
124 changes: 124 additions & 0 deletions Scripts/scripts/ss.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
################################################
# Blockchain Commons Standup Script Config file
################################################

# To setup a bitcoin server using standup scripts set the following
# environment variables accordingly by uncommenting and/or setting
# appropriate values.

# contributor: jodobear

###########################
# system
###########################
# Prompt user befor continuing with the installation. Gives the user
# a chance to check the configuration before installing. Set it to
# true to remove the prompt
NOPROMPT=false
# Set password for user "standup". Good practice to use at least 8
# character long password.
# Don't ignore this.
USERPASSWORD=


###########################
# vps
###########################
# If you are using a VPS, set it to true and set the HOSTNAME, FQDN &
# REGION variables.
VPS=false
# the name for your server
HOSTNAME=
# the domain name(website) where you will host/access the server.
# if you are going to access it locally then you can just use your hostname and add .local like so: hostname.local
FQDN=
# the region in which the server is hosted. Required for timezone settings
REGION=
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to give an example of this, or tell users where to go to get the right format.

Copy link
Author

@jodobear jodobear Oct 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the following:

FQDN : e.g. myawesomedomain.com

REGION : e.g. UCT, GMT, Pacific, America/New_York, Europe/Madrid, Asia/Kolkata

Copy link

@matthiasdebernardini matthiasdebernardini Dec 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

debian comes with curl, so the commands below might be useful if you don't know the codes by heart

curl https://ipinfo.io/ip

curl https://json.geoiplookup.io/<Public_IP>

Although this would probably only work with a VPS (unless they have a static IP)



###########################
# Tor & SSH
###########################
# set a Tor public key if you have one.
TOR_PUBKEY=
# set an SSH key if you have one.
SSH_KEY=
# set a comma seperated set of white listed IPs that can SSH into the server.
SYS_SSH_IP=


###########################
# bitcoind
###########################
# The bitcoin network you want bitcoind to start with. Valid choices:
# mainnet, testnet or regtest
NETWORK=mainnet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest we default this to testnet, to force someone to purposefully change it to choose to engage with real funds.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

# specify location where you want to create your bitcoin data directory.
# by defaut it will be /home/standup.
# Do NOT add `/.bitcoin/` it will be created by the script
# This is helpful to reduce costs and/or security
BTC_DATA_DIR=/home/standup
# Integer value to specify level of prune node. Minimum value is 550.
PRUNE=
# If you want to speed up the Initial Block Download then set it to true.
# Currently not implemented. It will use snapshot hosted by btcpayserver.
# Documentation: https://github.com/btcpayserver/btcpayserver-docker/tree/master/contrib/FastSync
# DISCLAIMER: It is always better to let your node validate blocks from the
# beginning. This script uses blockchain data signed by BTCPay Server.
# Trust at your own risk.
# FASTSYNC=false
# Choose to install HWI: Hardware Wallet Interface
# HWI=false


###########################
# lightning
###########################
# Choose your lightning network installation. By default the script will
# not install lightning. Valid options: c-lightning, lnd or empty
LIGHTNING=
# Set alias of your lightning node
LN_ALIAS=StandUp


###########################
# c-lightning options
###########################
# http-plugin
# CLN_HTTP_PLUGIN=flase
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

false?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hasn't been implemented, hence set to false

# password for http communication
# HTTP_PASS=


###########################
# services
###########################
# set to true if you want to install an esplora server
ESPLORA=false
# set to true if you want to install btcpay server
# BTCPAYSERVER=false


###########################
# Esplora
###########################
# enable lightnode? Uses ~50% disk space but, costs ~50% more time for lookups. Good for personal use.
LIGHTMODE=false
# If available RAM is more than 2Gb, set this to `false` for faster sync
LIMIT_BATCH_SIZE=true
# electrs database directory
ELECTRS_DB=/home/standup/electrs_db
# If Esplora is running on a remote machine than Electrs, then set the IP of that machine or to allow requests from everywhere copy and paste this: \'*\'
CORS=localhost
# Enable NoScript prerender server?
# PRERENDER_ASSETS=flase


###########################
# BTCPAY Server
###########################
# the domain name where you will host your BTCPay Server.
# BTCPAY_HOST=
# set the lightning network implementation for your BTCPay Server,
# options: clightning or lnd
# BTCPAY_LN=
124 changes: 124 additions & 0 deletions Scripts/scripts/ss.conf.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
################################################
# Blockchain Commons Standup Script Config file
################################################

# To setup a bitcoin server using standup scripts set the following
# environment variables accordingly by uncommenting and/or setting
# appropriate values.

# contributor: jodobear

###########################
# system
###########################
# Prompt user befor continuing with the installation. Gives the user
# a chance to check the configuration before installing. Set it to
# true to remove the prompt
NOPROMPT=false
# Set password for user "standup". Good practice to use at least 8
# character long password.
# Don't ignore this.
USERPASSWORD=


###########################
# vps
###########################
# If you are using a VPS, set it to true and set the HOSTNAME, FQDN &
# REGION variables.
VPS=false
# the name for your server
HOSTNAME=
# the domain name(website) where you will host/access the server.
# if you are going to access it locally then you can just use your hostname and add .local like so: hostname.local
FQDN=
# the region in which the server is hosted. Required for timezone settings
REGION=


###########################
# Tor & SSH
###########################
# set a Tor public key if you have one.
TOR_PUBKEY=
# set an SSH key if you have one.
SSH_KEY=
# set a comma seperated set of white listed IPs that can SSH into the server.
SYS_SSH_IP=


###########################
# bitcoind
###########################
# The bitcoin network you want bitcoind to start with. Valid choices:
# mainnet, testnet or regtest
NETWORK=mainnet
# specify location where you want to create your bitcoin data directory.
# by defaut it will be /home/standup.
# Do NOT add `/.bitcoin/` it will be created by the script
# This is helpful to reduce costs and/or security
BTC_DATA_DIR=/home/standup
# Integer value to specify level of prune node. Minimum value is 550.
PRUNE=
# If you want to speed up the Initial Block Download then set it to true.
# Currently not implemented. It will use snapshot hosted by btcpayserver.
# Documentation: https://github.com/btcpayserver/btcpayserver-docker/tree/master/contrib/FastSync
# DISCLAIMER: It is always better to let your node validate blocks from the
# beginning. This script uses blockchain data signed by BTCPay Server.
# Trust at your own risk.
# FASTSYNC=false
# Choose to install HWI: Hardware Wallet Interface
# HWI=false


###########################
# lightning
###########################
# Choose your lightning network installation. By default the script will
# not install lightning. Valid options: c-lightning, lnd or empty
LIGHTNING=
# Set alias of your lightning node
LN_ALIAS=StandUp


###########################
# c-lightning options
###########################
# http-plugin
# CLN_HTTP_PLUGIN=flase
# password for http communication
# HTTP_PASS=


###########################
# services
###########################
# set to true if you want to install an esplora server
ESPLORA=false
# set to true if you want to install btcpay server
# BTCPAYSERVER=false


###########################
# Esplora
###########################
# enable lightnode? Uses ~50% disk space but, costs ~50% more time for lookups. Good for personal use.
LIGHTMODE=false
# If available RAM is more than 2Gb, set this to `false` for faster sync
LIMIT_BATCH_SIZE=true
# electrs database directory
ELECTRS_DB=/home/standup/electrs_db
# If Esplora is running on a remote machine than Electrs, then set the IP of that machine or to allow requests from everywhere copy and paste this: \'*\'
CORS=localhost
# Enable NoScript prerender server?
# PRERENDER_ASSETS=flase


###########################
# BTCPAY Server
###########################
# the domain name where you will host your BTCPay Server.
# BTCPAY_HOST=
# set the lightning network implementation for your BTCPay Server,
# options: clightning or lnd
# BTCPAY_LN=
60 changes: 60 additions & 0 deletions Scripts/scripts/ss_00.1_vps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assuming availability of coreutils, shouldn't the shebang be#!/usr/bin/env bash instead of hardcoding the location of bash?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
#!/bin/bash
#!/usr/bin/env bash


# standup script - vps hostname settings

IPADDR=""

# Check for FQDN & HOSTNAME if --vps
if "$VPS" && [[ -z "$HOSTNAME" ]] || [[ "$HOSTNAME" == "__UNDEFINED__" ]]; then
echo "
$MESSAGE_PREFIX Hostname not provided.
"
while [ -z "$HOSTNAME" ]; do
read -rp "Enter hostname of the server: " HOSTNAME
done
fi

if "$VPS" && [[ -z "$FQDN" ]] || [[ "$FQDN" == "__UNDEFINED__" ]]; then
echo "
$MESSAGE_PREFIX FQDN not provided. Please provide a domain name."
while [ -z "$FQDN" ]; do
read -rp "Enter the fqdn of the server: " FQDN
done
fi

if "$VPS" && [[ -z "$REGION" ]] || [[ "$REGION" == "__UNDEFINED__" ]]; then
echo "
$MESSAGE_PREFIX Region of the server not provided. It is required to set the timezone.
"
while [ -z "$REGION" ]; do
read -rp "Enter the region of the server: " REGION
done
fi

echo $HOSTNAME > /etc/hostname

/bin/hostname "$HOSTNAME"

# Set the variable $IPADDR to the IP address the new Linode receives.
apt-get -qq -y install net-tools
IPADDR=$(/sbin/ifconfig eth0 | awk '/inet / { print $2 }' | sed 's/addr://')

echo "$MESSAGE_PREFIX Set hostname as $FQDN ($IPADDR)"
echo "
***********************
$MESSAGE_PREFIX TODO: Put $FQDN with IP $IPADDR in your main DNS file.
***********************
"
echo "$MESSAGE_PREFIX Set Time Zone to $REGION"
echo $REGION > /etc/timezone
cp /usr/share/zoneinfo/${REGION} /etc/localtime

echo "
$MESSAGE_PREFIX Hostname, IP address and timezon are set. Put $FQDN with IP $IPADDR in your main DNS file.
"
# Add localhost aliases

echo "127.0.0.1 localhost" > /etc/hosts
echo "127.0.1.1 $FQDN $HOSTNAME" >> /etc/hosts

echo "$MESSAGE_PREFIX - Set localhost"
Loading