Basics for myNode Image creation and new device setup

This commit is contained in:
Taylor Helsper 2019-06-25 23:15:07 -05:00
parent d2205ea275
commit e76cf03d35
14 changed files with 391 additions and 189 deletions

View File

@ -12,17 +12,30 @@ rootfs_auto:
# Start file server to allow downloads to devices
.PHONY: start_file_server
start_file_server:
@python3 -m http.server --directory ./out
@/bin/bash scripts/start_http_server.sh
.PHONY: stop_file_server
stop_file_server:
@/bin/bash scripts/stop_http_server.sh
# Download base Linux images
out/linux_base_images/raspi.zip:
@mkdir -p out/linux_base_images/
@wget http://downloads.raspberrypi.org/raspbian/images/raspbian-2019-04-09/2019-04-08-raspbian-stretch.zip -O out/linux_base_images/raspi.zip
out/linux_base_images/rock64_armbian.7z:
@mkdir -p out/linux_base_images/
@wget https://dl.armbian.com/rock64/Debian_stretch_default.7z -O out/linux_base_images/rock64_armbian.7z
download_linux_base_images: out/linux_base_images/raspi.zip out/linux_base_images/rock64_armbian.7z
# Download Linux images
out/linux_images/raspi_raspbian.zip:
@mkdir -p out/linux_images/
@wget https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2019-06-24/2019-06-20-raspbian-buster-lite.zip -O out/linux_images/raspi_raspbian.zip
out/linux_images/rock64_debian.7z:
@mkdir -p out/linux_images/
@wget https://dl.armbian.com/rock64/Debian_stretch_default.7z -O out/linux_images/rock64_debian.7z
download_linux_images: out/linux_images/raspi_raspbian.zip out/linux_images/rock64_debian.7z
# Download base myNode images
out/base_images/raspi_base.img.gz:
@mkdir -p out/base_images/
@wget http://mynodebtc.com/device/mynode_images/raspi_base.img.gz -O out/base_images/raspi_base.img.gz
out/base_images/rock64_base.img.gz:
@mkdir -p out/base_images/
@wget http://mynodebtc.com/device/mynode_images/rock64_base.img.gz -O out/base_images/rock64_base.img.gz
download_base_images: download_linux_images out/base_images/raspi_base.img.gz out/base_images/rock64_base.img.gz
# Download latest nyNode images
@ -32,9 +45,20 @@ out/mynode_images/raspi_standard_final.img.gz:
out/mynode_images/rock64_standard_final.img.gz:
@mkdir -p out/mynode_images/
@wget http://mynodebtc.com/device/mynode_images/rock64_standard_final.img.gz -O out/mynode_images/rock64_standard_final.img.gz
download_mynode_images: out/mynode_images/raspi_standard_final.img.gz out/mynode_images/rock64_standard_final.img.gz
download_mynode_images: download_base_images out/mynode_images/raspi_standard_final.img.gz out/mynode_images/rock64_standard_final.img.gz
# Setup of New Device
.PHONY: setup_new_rock64
setup_new_rock64: start_file_server download_base_images rootfs
@cp -f setup/setup_rock64.sh out/setup_rock64.sh
@/bin/bash scripts/setup_new_rock64.sh
.PHONY: setup_new_raspi
setup_new_raspi: start_file_server download_base_images rootfs
@cp -f setup/setup_raspi.sh out/setup_raspi.sh
@/bin/bash scripts/setup_new_raspi.sh
# TODO: Make images programmatically
.PHONY: images
images: rootfs
@ -54,7 +78,7 @@ release: rootfs release.sh
# Clean build files
.PHONY: clean
clean:
clean: stop_file_server
@rm -rf out/
@rm -rf out/
@rm -rf release.sh

View File

@ -45,6 +45,7 @@ Each myNode device comes with a number of wonderful features:
## Suported Devices
We currently support images for the following devices:
- Raspberry Pi 3B+
- Raspberry Pi 4B+ - Coming Soon!
- Rock64
## Running myNode
@ -52,6 +53,7 @@ You can run myNode on your own device in just a few easy steps!
1. Download an Image
* Raspberry Pi 3B+ | http://mynodebtc.com/device/base_images/raspi_standard_final.img.gz
* Raspberry Pi 4B+ | Coming soon...
* Rock64 | http://mynodebtc.com/device/base_images/rock64_standard_final.img.gz
2. Flash Image onto SD Card
* Download Etcher | https://www.balena.io/etcher/
@ -76,6 +78,14 @@ Once you are running myNode, you can easily modify and update the software yours
6. Test your changes!
7. Submit Pull Request to share your updates!
## Convert new device to run myNode
1. Run make command for your device. Ex:
-- make setup_new_rock64
-- make setup_new_raspi
3. Follow Instructions
2. Reboot Device
4. Congratulations! You're running a new myNode device!
## Screenshots
![](images/2.png)
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

5
scripts/get_local_ip.py Normal file
View File

@ -0,0 +1,5 @@
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
print(s.getsockname()[0])
s.close()

3
scripts/setup_new_raspi.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
echo "TODO"

53
scripts/setup_new_rock64.sh Executable file
View File

@ -0,0 +1,53 @@
#!/bin/bash
LOCAL_IP=$(python ./scripts/get_local_ip.py)
echo ""
echo "Finished updating rootfs and other files!"
echo ""
clear
echo "Step 1: "
echo " Flash SD Card with Rock64: out/base_images/rock64_base.img.gz"
echo " OR"
echo " If you would rather create your own base image, follow the"
echo " manual instructions in setup/setup_image_rock64.txt"
echo ""
echo "Press a key when complete..."
read -n 1
clear
echo "Step 2: "
echo " Insert SD Card into Rock64 and boot the device"
echo ""
echo "Press a key when complete..."
read -n 1
clear
echo "Step 3: "
echo " Login to device with username 'admin' and password 'bolt'"
echo " Run the following commands. Use bolt at password prompts."
echo " wget http://${LOCAL_IP}:8000/setup_rock64.sh -O setup_rock64.sh"
echo " chmod +x setup_rock64.sh"
echo " sudo ./setup_rock64.sh ${LOCAL_IP}"
echo ""
echo "Press a key when complete..."
read -n 1
clear
echo "Step 4:"
echo " Login to device with username 'admin' and password 'bolt'"
echo " Run the following commands. Use bolt at password prompts."
echo " "
echo "Press a key when complete..."
read -n 1
clear
echo "Step 5:"
echo " Reboot your device."
echo ""
echo "Press a key when complete..."
read -n 1
echo ""
echo "Congratulations! Your device is now ready!"

20
scripts/start_http_server.sh Executable file
View File

@ -0,0 +1,20 @@
#!/bin/bash
start_server () {
echo "Starting HTTP Server on port 8000..."
python3 -m http.server --directory ./out > /dev/null &
PID=$!
echo $PID > ./out/file_server_pid
sleep 1
}
if [ -f ./out/file_server_pid ]; then
PID=$(cat ./out/file_server_pid)
if ps -p $PID > /dev/null; then
echo "HTTP Server appears to already be running"
else
start_server
fi
else
start_server
fi

10
scripts/stop_http_server.sh Executable file
View File

@ -0,0 +1,10 @@
#!/bin/bash
if [ -f ./out/file_server_pid ]; then
PID=$(cat ./out/file_server_pid)
if ps -p $PID > /dev/null; then
echo "Stopping HTTP Server ($PID)..."
kill $PID
sleep 1
fi
fi

View File

@ -1,46 +0,0 @@
###
### Setup myNode Free
### Start with <device>_free_layer_2.img
###
##################################################################
# Log in as admin
# Copy myNode Free rootfs on top of existing image
sudo scp -r taylorhelsper@192.168.86.115:~/GitHub/myNode/out/rootfs_free/* /
sync
# Setup myNode Startup Script
sudo systemctl enable ufw
sudo systemctl enable mynode
sudo systemctl enable quicksync
sudo systemctl enable bandwidth
sudo systemctl enable www
sudo systemctl enable drive_check
sudo systemctl enable torrent_check
sudo systemctl enable bitcoind.service
sudo systemctl enable lnd.service
sudo systemctl enable lnd_unlock.service
sudo systemctl enable lnd_admin_files
sudo systemctl daemon-reload
# Delete junk
sudo rm -rf /home/admin/download
sudo rm -rf /home/admin/.bash_history
sudo rm -rf /home/bitcoin/.bash_history
sudo rm -rf /root/.bash_history
sudo rm -rf /root/.ssh/known_hosts
sudo rm -rf /etc/resolv.conf
sudo rm -rf /tmp/*
sync
### MAKE IMAGE NOW ###
# This prevents auto gen files like certs to be part of the base image
# Must make sure image can boot after this point and fully come up
# Reboot again
sudo reboot

View File

@ -1,67 +0,0 @@
###
### Setup myNode Free
### Start with <device>_start.img
###
###
### Setup Base OS
###
# Update OS
sudo apt-get update
sudo apt-get -y upgrade
# Install other tools
sudo apt-get -y install htop git curl bash-completion jq dphys-swapfile lsof libzmq3-dev
sudo apt-get -y install build-essential python-dev python-pip python3-dev python3-pip
sudo apt-get -y install transmission-cli fail2ban ufw tclsh zlib1g-dev libffi-dev file
sudo apt-get -y install toilet ncdu toilet-fonts avahi-daemon figlet libsecp256k1-dev
sudo apt-get -y install inotify-tools libssl-dev
# Install other things without recommendation
sudo apt-get -y install --no-install-recommends expect
# Add bitcoin user
sudo useradd -m -s /bin/bash bitcoin
# Install python tools (run twice, some broken deps may cause install failures on first try for line 3)
sudo pip install setuptools
sudo pip install wheel
sudo pip install speedtest-cli transmissionrpc flask python-bitcoinrpc prometheus_client requests
sudo pip install python-pam python-bitcoinlib psutil
sudo pip install grpcio grpcio-tools googleapis-common-protos
# Update python3 to 3.7.2
mkdir -p /tmp/download
cd /tmp/download
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz
tar xf Python-3.7.2.tar.xz
cd Python-3.7.2
./configure
make -j4
sudo make install
cd ~
# Install python3 specific tools
sudo pip3 install wheel setuptools
sudo pip3 install bitstring lnd-grpc pycoin aiohttp connectrum python-bitcoinlib python-bitcointx libsecp256k1 requests
# Remove existing MOTD login info
sudo rm -rf /etc/motd
sudo rm -rf /etc/update-motd.d/*
# Reboot
sudo reboot
######################
### MAKE IMAGE NOW ###
######################

View File

@ -1,63 +0,0 @@
###
### Setup myNode Free
### Start with <device>_free_layer_1.img
###
##################################################################
# Log in as admin
# More pip install on top of base image
sudo pip3 install requests
# Install Bitcoin
mkdir -p /tmp/download
cd /tmp/download
ARCH="arm-linux-gnueabihf"
uname -a | grep aarch64
if [ $? = 0 ]; then
ARCH="aarch64-linux-gnu"
fi
BTC_UPGRADE_URL=https://bitcoin.org/bin/bitcoin-core-0.18.0/bitcoin-0.18.0-$ARCH.tar.gz
BTC_UPGRADE_URL_FILE=/home/bitcoin/.mynode/.btc_url
wget $BTC_UPGRADE_URL -O bitcoin.tar.gz
tar -xvf bitcoin.tar.gz
mv bitcoin-* bitcoin
sudo install -m 0755 -o root -g root -t /usr/local/bin bitcoin/bin/*
bitcoind --version
sudo su - bitcoin
ln -s /mnt/hdd/mynode/bitcoin /home/bitcoin/.bitcoin
ln -s /mnt/hdd/mynode/lnd /home/bitcoin/.lnd
exit
mkdir /home/admin/.bitcoin
sudo mkdir -p /home/bitcoin/.mynode/
echo $BTC_UPGRADE_URL | sudo tee $BTC_UPGRADE_URL_FILE
sudo chown -R bitcoin:bitcoin /home/bitcoin/.mynode/
# Install Lightning
mkdir -p /tmp/download
cd /tmp/download
LND_UPGRADE_URL=https://github.com/lightningnetwork/lnd/releases/download/v0.6.1-beta/lnd-linux-armv7-v0.6.1-beta.tar.gz
LND_UPGRADE_URL_FILE=/home/bitcoin/.mynode/.lnd_url
wget $LND_UPGRADE_URL -O lnd.tar.gz
tar -xzf lnd.tar.gz
mv lnd-* lnd
sudo install -m 0755 -o root -g root -t /usr/local/bin lnd/*
sudo ln -s /bin/ip /usr/bin/ip
lnd --version
echo $LND_UPGRADE_URL | sudo tee $LND_UPGRADE_URL_FILE
cd ~
sudo chown -R bitcoin:bitcoin /home/bitcoin/.mynode/
sync
### MAKE IMAGE NOW ###
# This prevents auto gen files like certs to be part of the base image
# Must make sure image can boot after this point and fully come up
# Reboot again
sudo reboot

View File

@ -45,8 +45,16 @@ chmod +x install.sh
sudo ./install.sh
cd ~
# Sync
sync
######################
### MAKE IMAGE NOW ###
######################
# Final results
# - Image with SSH access
# - Root user disabled
# - Default user admin with password bolt
# - Default user admin with password bolt

View File

@ -20,4 +20,11 @@ sudo sed -i 's/rock64/myNode/g' /etc/hosts
# Overclock
sudo sed -i "s/MAX_SPEED=.*/MAX_SPEED=1510000/" /etc/default/cpufrequtils
sudo systemctl restart cpufrequtils
sudo systemctl restart cpufrequtils
# Sync
sync
######################
### MAKE IMAGE NOW ###
######################

0
setup/setup_raspi.sh Executable file
View File

238
setup/setup_rock64.sh Executable file
View File

@ -0,0 +1,238 @@
###
### Setup myNode on Rock64
### Run with "sudo"
###
set -x
set -e
if [ "$#" != "1" ]; then
echo "Usage: $0 <ip address>"
exit 1
fi
SERVER_IP=$1
# Update OS
apt-get update
apt-get -y upgrade
# Install other tools (run section multiple times to make sure success)
apt-get -y install htop git curl bash-completion jq dphys-swapfile lsof libzmq3-dev
apt-get -y install build-essential python-dev python-pip python3-dev python3-pip
apt-get -y install transmission-cli fail2ban ufw tclsh bluez python-bluez redis-server
apt-get -y install mongodb-server clang hitch zlib1g-dev libffi-dev file toilet ncdu
apt-get -y install toilet-fonts avahi-daemon figlet libsecp256k1-dev
apt-get -y install inotify-tools libssl-dev
# Install other things without recommendation
apt-get -y install --no-install-recommends expect
# Add bitcoin users
useradd -m -s /bin/bash bitcoin || true
# Install python tools (run twice, some broken deps may cause install failures on first try for line 3)
pip install setuptools
pip install wheel
pip install speedtest-cli transmissionrpc flask python-bitcoinrpc redis prometheus_client requests
pip install python-pam python-bitcoinlib psutil
pip install grpcio grpcio-tools googleapis-common-protos
# Update python3 to 3.7.2
mkdir -p /tmp/download
cd /tmp/download
wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tar.xz
tar xf Python-3.7.2.tar.xz
cd Python-3.7.2
./configure
make -j4
sudo make install
cd ~
# Install python3 specific tools (run multiple times to make sure success)
pip3 install wheel setuptools
pip3 install bitstring lnd-grpc pycoin aiohttp connectrum python-bitcoinlib
# Install Rust (Interactive)
curl https://sh.rustup.rs -sSf | sh -- -y
# Install node
curl -sL https://deb.nodesource.com/setup_11.x | bash -
apt-get install -y nodejs
# Install node packages
npm install -g pug-cli browserify uglify-js babel-cli
# Remove existing MOTD login info
rm -rf /etc/motd
rm -rf /etc/update-motd.d/*
#########################################################
# Install Bitcoin
mkdir -p /tmp/download
cd /tmp/download
ARCH="arm-linux-gnueabihf"
uname -a | grep aarch64
if [ $? = 0 ]; then
ARCH="aarch64-linux-gnu"
fi
BTC_UPGRADE_URL=https://bitcoin.org/bin/bitcoin-core-0.18.0/bitcoin-0.18.0-$ARCH.tar.gz
BTC_UPGRADE_URL_FILE=/home/bitcoin/.mynode/.btc_url
wget $BTC_UPGRADE_URL -O bitcoin.tar.gz
tar -xvf bitcoin.tar.gz
mv bitcoin-* bitcoin
install -m 0755 -o root -g root -t /usr/local/bin bitcoin/bin/*
bitcoind --version
sudo -u bitcoin ln -s /mnt/hdd/mynode/bitcoin /home/bitcoin/.bitcoin
sudo -u bitcoin ln -s /mnt/hdd/mynode/lnd /home/bitcoin/.lnd
mkdir /home/admin/.bitcoin
mkdir -p /home/bitcoin/.mynode/
echo $BTC_UPGRADE_URL | sudo tee $BTC_UPGRADE_URL_FILE
chown -R bitcoin:bitcoin /home/bitcoin/.mynode/
# Install Lightning
mkdir -p /tmp/download
cd /tmp/download
mkdir -p /home/bitcoin/.mynode/
LND_UPGRADE_URL=https://github.com/lightningnetwork/lnd/releases/download/v0.6.1-beta/lnd-linux-armv7-v0.6.1-beta.tar.gz
LND_UPGRADE_URL_FILE=/home/bitcoin/.mynode/.lnd_url
wget $LND_UPGRADE_URL -O lnd.tar.gz
tar -xzf lnd.tar.gz
mv lnd-* lnd
install -m 0755 -o root -g root -t /usr/local/bin lnd/*
ln -s /bin/ip /usr/bin/ip
lnd --version
echo $LND_UPGRADE_URL | sudo tee $LND_UPGRADE_URL_FILE
cd ~
chown -R bitcoin:bitcoin /home/bitcoin/.mynode/
# Setup "install" location for some apps
mkdir -p /opt/mynode
chown -R bitcoin:bitcoin /opt/mynode
# Install LND Hub
cd /opt/mynode
sudo -u bitcoin git clone https://github.com/BlueWallet/LndHub.git
cd LndHub
sudo -u bitcoin npm install
sudo -u bitcoin ln -s /home/bitcoin/.lnd/tls.cert tls.cert
sudo -u bitcoin ln -s /home/bitcoin/.lnd/data/chain/bitcoin/mainnet/admin.macaroon admin.macaroon
# Install electrs (only build to save new version, not included in overlay)
#cd /home/admin/download
#wget https://github.com/romanz/electrs/archive/v0.7.0.tar.gz
#tar -xvf v0.7.0.tar.gz
#cd electrs-0.7.0
#cargo build --release
#sudo install -g root -o root target/release/electrs /usr/bin/electrs
#cd ~
# Install RTL
cd /opt/mynode
sudo -u bitcoin wget https://github.com/ShahanaFarooqui/RTL/archive/v0.3.3.tar.gz -O RTL.tar.gz
sudo -u bitcoin tar -xvf RTL.tar.gz
sudo -u bitcoin rm RTL.tar.gz
sudo -u bitcoin mv RTL-* RTL
cd RTL
sudo -u bitcoin npm install
# Install LND Admin
cd /opt/mynode
sudo -u bitcoin wget https://github.com/janoside/lnd-admin/archive/v0.10.12.tar.gz -O lnd-admin.tar.gz
sudo -u bitcoin tar -xvf lnd-admin.tar.gz
sudo -u bitcoin rm lnd-admin.tar.gz
sudo -u bitcoin mv lnd-* lnd-admin
cd lnd-admin
sudo -u bitcoin npm install
# Install Bitcoin RPC Explorer
cd /opt/mynode
sudo -u bitcoin wget https://github.com/janoside/btc-rpc-explorer/archive/v1.0.3.tar.gz -O btc-rpc-explorer.tar.gz
sudo -u bitcoin tar -xvf btc-rpc-explorer.tar.gz
sudo -u bitcoin rm btc-rpc-explorer.tar.gz
sudo -u bitcoin mv btc-rpc-* btc-rpc-explorer
cd btc-rpc-explorer
sudo -u bitcoin npm install
# Install LND Connect
mkdir -p /tmp/download
cd /tmp/download
wget https://github.com/LN-Zap/lndconnect/releases/download/v0.1.0/lndconnect-linux-armv7-v0.1.0.tar.gz -O lndconnect.tar.gz
tar -xvf lndconnect.tar.gz
rm lndconnect.tar.gz
mv lndconnect-* lndconnect
install -m 0755 -o root -g root -t /usr/local/bin lndconnect/*
#########################################################
# Copy myNode rootfs
rm -rf /tmp/rootfs.tar.gz
rm -rf /tmp/upgrade/
wget http://${SERVER_IP}/mynode_rootfs_rock64.tar.gz -O /tmp/rootfs.tar.gz
tar -xvf /tmp/rootfs.tar.gz -C /tmp/upgrade/
# Install files
cp -rf /tmp/upgrade/out/rootfs_*/* /
sleep 1
sync
sleep 1
# Setup myNode Startup Script
systemctl daemon-reload
systemctl enable mynode
systemctl enable quicksync
systemctl enable torrent_check
systemctl enable firewall
systemctl enable bandwidth
systemctl enable www
systemctl enable drive_check
systemctl enable bitcoind
systemctl enable lnd
systemctl enable lnd_unlock
systemctl enable lnd_backup
systemctl enable lnd_admin_files
systemctl enable lndconnect
systemctl enable redis-server
systemctl enable mongodb
#systemctl enable electrs # DISABLED BY DEFAULT
#systemctl enable lndhub # DISABLED BY DEFAULT
#systemctl enable btc_rpc_explorer # DISABLED BY DEFAULT
systemctl enable tls_proxy
systemctl enable rtl
systemctl enable lnd_admin
# Delete junk
rm -rf /home/admin/download
rm -rf /home/admin/.bash_history
rm -rf /home/bitcoin/.bash_history
rm -rf /root/.bash_history
rm -rf /root/.ssh/known_hosts
rm -rf /etc/resolv.conf
rm -rf /tmp/*
sync
### MAKE IMAGE NOW ###
# This prevents auto gen files like certs to be part of the base image
# Must make sure image can boot after this point and fully come up