Word towards SD card replacement support

This commit is contained in:
Taylor Helsper 2019-07-05 20:45:42 -05:00
parent 7f65bc6858
commit 87659bc96b
13 changed files with 65 additions and 29 deletions

View File

@ -9,7 +9,7 @@ After=bitcoind.service
[Service]
Type=simple
KillMode=process
EnvironmentFile=/home/bitcoin/.mynode/.btcrpc_environment
EnvironmentFile=/mnt/hdd/mynode/settings/.btcrpc_environment
ExecStartPre=/usr/bin/wait_on_bitcoin.sh
ExecStart=/usr/bin/electrs --timestamp --db-dir /mnt/hdd/mynode/electrs --electrum-rpc-addr 0.0.0.0:50001 --cookie="mynode:${BTC_RPC_PASSWORD}" --jsonrpc-import --bulk-index-threads 3 --index-batch-size 12 --daemon-rpc-addr 127.0.0.1:8332 --tx-cache-size 10000 -vv
User=bitcoin

View File

@ -2,7 +2,7 @@
set timeout 5
set f [open "/home/bitcoin/.mynode/.lndpw"]
set f [open "/mnt/hdd/mynode/settings/.lndpw"]
set pw [read $f]
set seed [lindex $argv 0];
close $f

View File

@ -2,12 +2,22 @@
# Main variables
OUTPUT_DIR="/home/bitcoin/.mynode/electrs"
HDD_DIR="/mnt/hdd/mynode/settings/electrs"
domain=myNode.local
commonname=myNode.local
mkdir -p $OUTPUT_DIR
mkdir -p $HDD_DIR
# Check for files on HDD and move to SD
if [ ! -f $OUTPUT_DIR/$domain.pem ] && [ -f $HDD_DIR/$domain.pem ]; then
cp -f $HDD_DIR/* $OUTPUT_DIR/
fi
if [ -f $OUTPUT_DIR/$domain.pem ]; then
# Verify files are stored on HDD
cp -f $OUTPUT_DIR/* $HDD_DIR/
exit 0
fi
@ -41,4 +51,6 @@ echo "Creating PEM"
cat $OUTPUT_DIR/$domain.key > $OUTPUT_DIR/$domain.pem
echo "" >> $OUTPUT_DIR/$domain.pem
cat $OUTPUT_DIR/$domain.crt >> $OUTPUT_DIR/$domain.pem
# Put copy of files of HDD
cp -f $OUTPUT_DIR/* $HDD_DIR/

View File

@ -12,11 +12,15 @@ fi
# Expand Root FS
mkdir -p /var/lib/mynode
if [ $IS_RASPI -eq 1 ]; then
if [ ! -f /var/lib/mynode/.expanded_rootfs ]; then
if [ ! -f /var/lib/mynode/.expanded_rootfs ]; then
if [ $IS_RASPI -eq 1 ]; then
raspi-config --expand-rootfs
touch /var/lib/mynode/.expanded_rootfs
fi
if [ $IS_ROCK64 = 1 ]; then
/usr/lib/armbian/armbian-resize-filesystem start
fi
fi
# Verify we are in a clean state (only raspi uses HDD swap)
@ -44,6 +48,7 @@ done
# Setup Drive
mkdir -p /mnt/hdd/mynode
mkdir -p /mnt/hdd/mynode/settings
mkdir -p /mnt/hdd/mynode/bitcoin
mkdir -p /mnt/hdd/mynode/lnd
mkdir -p /mnt/hdd/mynode/quicksync
@ -56,12 +61,13 @@ rm -rf $MYNODE_DIR/.mynode_bitcoind_synced
# Setup SD Card (if necessary)
mkdir -p /home/bitcoin/.mynode/
mkdir -p /home/admin/.bitcoin/
chown admin:admin /home/admin/.bitcoin/
rm -rf /etc/motd # Remove simple motd for update-motd.d
# Regen SSH keys
mkdir -p /home/bitcoin/.mynode/
if [ ! -f /home/bitcoin/.mynode/.gensshkeys ]; then
rm -rf /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server
@ -70,26 +76,28 @@ if [ ! -f /home/bitcoin/.mynode/.gensshkeys ]; then
touch /home/bitcoin/.mynode/.gensshkeys
fi
# Sync product key (SD preferred)
cp -f /home/bitcoin/.mynode/.product_key* /mnt/hdd/mynode/settings/
cp -f /mnt/hdd/mynode/settings/.product_key* home/bitcoin/.mynode/
# Randomize RPC password
mkdir -p /home/bitcoin/.mynode/
if [ ! -f /home/bitcoin/.mynode/.btcrpcpw ]; then
if [ ! -f /mnt/hdd/mynode/settings/.btcrpcpw ]; then
# Write random pw to .btcrpcpw
< /dev/urandom tr -dc A-Za-z0-9 | head -c${1:-24} > /home/bitcoin/.mynode/.btcrpcpw
chown bitcoin:bitcoin /home/bitcoin/.mynode/.btcrpcpw
chmod 600 /home/bitcoin/.mynode/.btcrpcpw
< /dev/urandom tr -dc A-Za-z0-9 | head -c${1:-24} > /mnt/hdd/mynode/settings/.btcrpcpw
chown bitcoin:bitcoin /mnt/hdd/mynode/settings/.btcrpcpw
chmod 600 /mnt/hdd/mynode/settings/.btcrpcpw
fi
# Setup LND Node Name
if [ ! -f /home/bitcoin/.mynode/.lndalias ]; then
echo "mynodebtc.com [myNode]" > /home/bitcoin/.mynode/.lndalias
if [ ! -f /mnt/hdd/mynode/settings/.lndalias ]; then
echo "mynodebtc.com [myNode]" > /mnt/hdd/mynode/settings/.lndalias
fi
# BTC Config
cp -f /usr/share/mynode/bitcoin.conf /mnt/hdd/mynode/bitcoin/bitcoin.conf
PW=$(cat /home/bitcoin/.mynode/.btcrpcpw)
PW=$(cat /mnt/hdd/mynode/settings/.btcrpcpw)
sed -i "s/rpcpassword=.*/rpcpassword=$PW/g" /mnt/hdd/mynode/bitcoin/bitcoin.conf
cp -f /mnt/hdd/mynode/bitcoin/bitcoin.conf /home/admin/.bitcoin/bitcoin.conf
@ -98,7 +106,7 @@ chown admin:admin /home/admin/.bitcoin/bitcoin.conf
# LND Config
cp /usr/share/mynode/lnd.conf /mnt/hdd/mynode/lnd/lnd.conf
ALIAS=$(cat /home/bitcoin/.mynode/.lndalias)
ALIAS=$(cat /mnt/hdd/mynode/settings/.lndalias)
sed -i "s/alias=.*/alias=$ALIAS/g" /mnt/hdd/mynode/lnd/lnd.conf
chown bitcoin:bitcoin /mnt/hdd/mynode/lnd/lnd.conf
@ -108,15 +116,15 @@ chown bitcoin:bitcoin /opt/mynode/RTL/RTL.conf
# Update files that need RPC password (needed if upgrades overwrite files)
PW=$(cat /home/bitcoin/.mynode/.btcrpcpw)
PW=$(cat /mnt/hdd/mynode/settings/.btcrpcpw)
if [ -f /opt/mynode/LndHub/config.js ]; then
sed -i "s/mynode:.*@/mynode:$PW@/g" /opt/mynode/LndHub/config.js
fi
if [ -f /opt/mynode/btc-rpc-explorer/.env ]; then
sed -i "s/BTCEXP_BITCOIND_PASS=.*/BTCEXP_BITCOIND_PASS=$PW/g" /opt/mynode/btc-rpc-explorer/.env
fi
echo "BTC_RPC_PASSWORD=$PW" > /home/bitcoin/.mynode/.btcrpc_environment
chown bitcoin:bitcoin /home/bitcoin/.mynode/.btcrpc_environment
echo "BTC_RPC_PASSWORD=$PW" > /mnt/hdd/mynode/settings/.btcrpc_environment
chown bitcoin:bitcoin /mnt/hdd/mynode/settings/.btcrpc_environment
if [ -f /mnt/hdd/mynode/bitcoin/bitcoin.conf ]; then
sed -i "s/rpcpassword=.*/rpcpassword=$PW/g" /mnt/hdd/mynode/bitcoin/bitcoin.conf
fi
@ -136,6 +144,10 @@ USER=$(stat -c '%U' /mnt/hdd/mynode/quicksync)
if [ "$USER" != "bitcoin" ]; then
chown -R bitcoin:bitcoin /mnt/hdd/mynode/quicksync
fi
USER=$(stat -c '%U' /mnt/hdd/mynode/settings)
if [ "$USER" != "bitcoin" ]; then
chown -R bitcoin:bitcoin /mnt/hdd/mynode/settings
fi
USER=$(stat -c '%U' /mnt/hdd/mynode/bitcoin)
if [ "$USER" != "bitcoin" ]; then
chown -R bitcoin:bitcoin /mnt/hdd/mynode/bitcoin

View File

@ -1,10 +1,10 @@
#!/bin/bash
# Make sure we have wallet pw
mkdir -p /home/bitcoin/.mynode/
if [ ! -f /home/bitcoin/.mynode/.lndpw ]; then
< /dev/urandom tr -dc A-Za-z0-9 | head -c${1:-24} > /home/bitcoin/.mynode/.lndpw
chmod 600 /home/bitcoin/.mynode/.lndpw
mkdir -p /mnt/hdd/mynode/settings
if [ ! -f /mnt/hdd/mynode/settings/.lndpw ]; then
< /dev/urandom tr -dc A-Za-z0-9 | head -c${1:-24} > /mnt/hdd/mynode/settings/.lndpw
chmod 600 /mnt/hdd/mynode/settings/.lndpw
fi
exit 0

View File

@ -5,7 +5,7 @@ set timeout 20
set tls_cert "/home/bitcoin/.lnd/tls.cert"
set macaroon "/home/bitcoin/.lnd/data/chain/bitcoin/mainnet/admin.macaroon"
set f [open "/home/bitcoin/.mynode/.lndpw"]
set f [open "/mnt/hdd/mynode/settings/.lndpw"]
set pw [read $f]
spawn lncli --tlscertpath $tls_cert --macaroonpath $macaroon unlock

View File

@ -13,7 +13,7 @@ MYNODE_DIR=/mnt/hdd/mynode
QUICKSYNC_DIR=/mnt/hdd/mynode/quicksync
QUICKSYNC_CONFIG_DIR=/home/bitcoin/.config/transmission
QUICKSYNC_TORRENT_URL="https://mynodebtc.com/device/blockchain.tar.gz.torrent"
QUICKSYNC_BANDWIDTH_FILE="/home/bitcoin/.mynode/.bandwidth"
QUICKSYNC_BANDWIDTH_FILE="/mnt/hdd/mynode/settings/.bandwidth"
LND_BACKUP_FOLDER="/home/bitcoin/lnd_backup/"
LND_TLS_CERT_FILE="/mnt/hdd/mynode/lnd/tls.cert"
LND_WALLET_FILE="/mnt/hdd/mynode/lnd/data/chain/bitcoin/mainnet/wallet.db"

View File

@ -20,7 +20,7 @@ def get_bitcoin_rpc_username():
def get_bitcoin_rpc_password():
try:
with open("/home/bitcoin/.mynode/.btcrpcpw", "r") as f:
with open("/mnt/hdd/mynode/settings/.btcrpcpw", "r") as f:
return f.read()
except:
return "error_getting_password"

View File

@ -42,14 +42,17 @@ def get_device_serial():
def set_skipped_product_key():
os.system("touch /home/bitcoin/.mynode/.product_key_skipped")
os.system("touch /mnt/hdd/mynode/settings/.product_key_skipped")
def unset_skipped_product_key():
os.system("rm -rf /home/bitcoin/.mynode/.product_key_skipped")
os.system("rm -rf /mnt/hdd/mynode/settings/.product_key_skipped")
def skipped_product_key():
return os.path.isfile("/home/bitcoin/.mynode/.product_key_skipped")
def delete_product_key():
os.system("rm -rf /home/bitcoin/.mynode/.product_key")
os.system("rm -rf /mnt/hdd/mynode/settings/.product_key")
def has_product_key():
return os.path.isfile("/home/bitcoin/.mynode/.product_key")
def get_product_key():
@ -71,6 +74,8 @@ def is_valid_product_key():
def save_product_key(product_key):
pk = product_key.replace("-","")
os.system("echo '{}' > /home/bitcoin/.mynode/.product_key".format(pk))
os.system("echo '{}' > /mnt/hdd/mynode/settings/.product_key".format(pk))
def delete_product_key_error():
os.system("rm -rf /home/bitcoin/.mynode/.product_key_error")
os.system("rm -rf /mnt/hdd/mynode/settings/.product_key_error")

View File

@ -251,7 +251,7 @@ def page_lnd_change_alias():
return redirect(url_for(".page_lnd", error_message="Empty Alias"))
if len(alias) > 35:
return redirect(url_for(".page_lnd", error_message="Invalid Alias"))
with open("/home/bitcoin/.mynode/.lndalias", "w") as f:
with open("/mnt/hdd/mynode/settings/.lndalias", "w") as f:
utf8_alias = alias.decode('utf-8', 'ignore')
f.write(utf8_alias)
f.close()

View File

@ -32,8 +32,8 @@ def reset_bitcoin_env_file():
def delete_bitcoin_data():
os.system("rm -rf /mnt/hdd/mynode/bitcoin")
os.system("rm -rf /mnt/hdd/mynode/quicksync/.quicksync_complete")
os.system("rm -rf /home/bitcoin/.mynode/.btcrpc_environment")
os.system("rm -rf /home/bitcoin/.mynode/.btcrpcpw")
os.system("rm -rf /mnt/hdd/mynode/settings/.btcrpc_environment")
os.system("rm -rf /mnt/hdd/mynode/settings/.btcrpcpw")
def delete_quicksync_data():
os.system("rm -rf /mnt/hdd/mynode/quicksync")
@ -43,7 +43,7 @@ def delete_lnd_data():
#os.system("rm -f "+LND_WALLET_FILE)
os.system("rm -rf "+LND_DATA_FOLDER)
os.system("rm -rf /home/bitcoin/.lnd-admin/credentials.json")
os.system("rm -rf /home/bitcoin/.mynode/.lndpw")
os.system("rm -rf /mnt/hdd/mynode/settings/.lndpw")
os.system("rm -rf /home/admin/.lnd/")
return True

View File

@ -18,6 +18,11 @@ IS_RASPI3=0
IS_RASPI4=0
uname -a | grep aarch64 && IS_ROCK64=1 || IS_RASPI3=1
# Make sure FS is expanded for Rock64
if [ $IS_ROCK64 = 1 ]; then
/usr/lib/armbian/armbian-resize-filesystem start
fi
# Update OS
apt-get update
apt-get -y upgrade
@ -29,6 +34,7 @@ apt-get -y install transmission-cli fail2ban ufw tclsh bluez python-bluez redis-
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 tor tmux screen
#apt-get -y install python-grpcio python3-grpcio # Need Debian Buster on Rock64 first...
# Install other things without recommendation
@ -294,6 +300,7 @@ rm -rf /root/.ssh/known_hosts
rm -rf /etc/resolv.conf
rm -rf /tmp/*
rm -rf ~/setup_device.sh
rm -rf /etc/motd # Remove simple motd for update-motd.d
sync