raspiblitz/home.admin/_provision_.sh
/rootzoll 074c9d8549
merging pre-1.7.1 (#2462)
* fix copychain returns

* typo in sync loop

* stop services on inconsistent state

* calling correct provisioning

* apply bitcoin and lncli aliases in all scripts

* network.aliases: add CLNETWORK

* make cln default plugin dir: cln-plugins-enabled

similar to the nginx model make 2 directories for plugins:
cln-plugins-enabled - symlinked to ~/.lightning/plugins
plugins from here are loaded automatically on cln start

cln-plugins-available: plugins are downloaded here to
be run until the next cln restart (or stopped with runonce)

note the disk is mounted with noexec so plugins can't
run from there

discuss in: https://github.com/rootzoll/raspiblitz/issues/2295

* move shutdown script

* change all place where shutdown script is used

* change notify & release

* moved shutdown script

* moved shutdown scripts

* add more debug info

* moving github script

* remove chain in sync

* no longer needed chain in sync

* move debug script

* patch patch command

* make sure setup file is sourced

* remove debug output

* make sure lnd is put behind tor

* change indent

* get fresh sync progress

* avoid scrolling in menus

* use new selfsignedcert if no lnd tls.cert present

* sparko: add info and connect menu with own cert

https://github.com/rootzoll/raspiblitz/issues/2295

* cln.rest: add connect option for Zeus

https://github.com/rootzoll/raspiblitz/issues/2295

* cln: add the backup plugin + options

Usage options:
cln-plugin.backup.sh [on] [testnet|mainnet|signet]
cln-plugin.backup.sh [restore] [testnet|mainnet|signet] [force]
cln-plugin.backup.sh [backup-compact] [testnet|mainnet|signet]
https://github.com/lightningd/plugins/tree/master/backup

Discussed in: https://github.com/rootzoll/raspiblitz/issues/2295

* cln: add cln-plugin.standard.python.sh

Install and show the output of the chosen plugin for C-lightning
Usage:
cln-plugin.standard-python.sh on [plugin-name] [testnet|mainnet|signet] [runonce]
tested plugins:
summary | helpme | feeadjuster

find more at:
https://github.com/lightningd/plugins
discussed in:
https://github.com/rootzoll/raspiblitz/issues/2295

* shellcheck: change all `egrep` to `grep -E`

https://github.com/koalaman/shellcheck/wiki/SC2196

* do not resolve aliases, use as variables

* lnd: fix lnd.conf for parallel networks

discussed in: https://github.com/rootzoll/raspiblitz/issues/2290

* lnd: add LND option for parallel networks

* deprecate Testnet in SETTINGS
keysend and autopilot only for mainnet

due to: https://github.com/rootzoll/raspiblitz/issues/2290

* lnd: autopilot and autounlock for testnet

* fix comments

* add the SYSTEM menu for parallel chains

* RTL update to v0.11.0

make chain specific directory for the config: /home/rtl/${netprefix}RTL/
use ${netprefix}lnd.conf in config
override Environmen tvaribales for cln in the systemd service:
/etc/systemd/system/${netprefix}${typeprefix}RTL.service

discussed in: https://github.com/rootzoll/raspiblitz/issues/2384

* lnd.setname.sh for testnet

* display ${CHAIN} in the SYSTEM menu options

* keep _aliases file when live patches are applied

* all lncli_aliases to be used as variables

* default to KIllMode=control-group in services

https://www.man7.org/linux/man-pages/man5/systemd.kill.5.html
discussed in: https://github.com/rootzoll/raspiblitz/issues/1901

* add cln.hsmtool.sh for  hsm_secret handling

encrypt | decrypt | autounlock the hsm_secret for C-lightning
usage:
cln.hsmtool.sh [unlock] [testnet|mainnet|signet]
cln.hsmtool.sh [encrypt|decrypt] [testnet|mainnet|signet]
cln.hsmtool.sh [autounlock-on|autounlock-off] [testnet|mainnet|signet]

discussed in: https://github.com/rootzoll/raspiblitz/issues/2295

* add cln.install-service.sh to set up cln with systemd

script to set up or update the CLN systemd service
checks for hsm_secret encryption, autounlock and the sparko plugin
usage:
/home/admin/config.scripts/cln.install-service.sh $CHAIN

discussed in: https://github.com/rootzoll/raspiblitz/issues/2295

* use symlink to cln-plugins-enabled for all plugins

* keep lnd autopilot and autounlock mainnet only

mainnet only settings:
lnd autopilot
lnd keysend
circuibreaker
lnd autounlock
StaticChannelBackup to DropBox and USB

* cln FUNDING fix parsing address

* cln.hsmtool: add change-password and lock options

* always set password A

* cached peer info

* fix printing cache

* fix check for existing files

* handle bitcoind not running

* result with newline

* test line break

* test new line

* test new line

* two vars on output

* #2388 improve online check (less pinging)

* used cached peer status

* move chache

* cach file permissions

* allow sudo call

* fix cache

* remove double scan info

* add conf info to sync screen

* reorder info

* add space

* add space

* order info

* internet suppress error messages

* order info

* fix offering Blockchain copy

* fix hostname

* final ready state info

* lnd unlock after provision

* remove debug exit

* harmonize ready state

* add status to lnd unlock

* update lnd unlock script

* edit the unlock

* remove debug echo

* add debug

* add debug

* fix if statement

* debug output

* switch position of source setupdata

* #1126 preparing new setup with new c-lightning  (#2396)

* move debug script

* patch patch command

* make sure setup file is sourced

* remove debug output

* make sure lnd is put behind tor

* change indent

* get fresh sync progress

* always set password A

* cached peer info

* fix printing cache

* fix check for existing files

* handle bitcoind not running

* result with newline

* test line break

* test new line

* test new line

* two vars on output

* #2388 improve online check (less pinging)

* used cached peer status

* move chache

* cach file permissions

* allow sudo call

* fix cache

* remove double scan info

* add conf info to sync screen

* reorder info

* add space

* add space

* order info

* internet suppress error messages

* order info

* fix offering Blockchain copy

* fix hostname

* final ready state info

* lnd unlock after provision

* remove debug exit

* harmonize ready state

* add status to lnd unlock

* update lnd unlock script

* edit the unlock

* remove debug echo

* add debug

* add debug

* fix if statement

* debug output

* switch position of source setupdata

* lnd.unlock: fix typo

* netwok.monitor.sh debug

* cln-plugin.summary: fix paths

* rtl: fix permission of config on copy

* CASHOUT: use aliases for lnd

* rtl: install correctly for paralell chains

* use CHAIN in CLN and LND menu

* cln: add  CASHOUT option

* CLOSEALL and  CASHOUT: Improve labels and comments

Explaining CASHOUT in the label as discussed in:
https://github.com/rootzoll/raspiblitz/issues/2358

* cln.install: fix tor config

* cln: installthe  latest master until the next release

* _commands: source _aliases only if exists

* network aliases: fall back to 'main' for 'chain'

* new setup: keep testnet3 blocks and chainstate

* new setup: improve capitalization in menu

* improve help and comments

* cln: install Sparko if configured, but not present

* cln: add new wallet and import seed options

* fix peernum

* make sure that aliases get created on lnd setup

* no error if aliases not yet exist

* debug state

* fix network alias when not set

* fix syntax error

* add debug error info

* mute unlocking echos

* add debug wait

* add debug wait

* make sure info is uptodate

* make alias info as defaults

* rename option

* update sync info for no lightning

* add action string

* update sync info

* move name dialog

* wait for sync progress info

* wait for syncprogress info

* fix syntax

* get fresh data

* make sure to disable lnd

* add c-lightning to debug

* add setup logs to debug output

* fix syntax error

* add new-force wallet

* try fix call hsmtool

* hsm output tool

* fix output

* add seed-force

* refactor blitz.mnemonic.py

* test seed

* debug info

* dump object

* try check

* correct putput

* fix syntax

* check lnd for valid seed

* fix gui

* add Suez install script

discussed in:
https://github.com/rootzoll/raspiblitz/issues/2366

* cln rescue file export

* get correct version

* add cln export gui

* cln.backup.sh cln-import

* correct bytesize

* generate cln wallet with passwordc

* fix syntax

* fix syntax

* mute not needed error msg

* PEERING: correct message on success

* cln.install-service: fix sparko check

* add Suez to menu for CLN and LND

needs to be installed with the bitcoin user to be able to interact with CLN
related: https://github.com/rootzoll/raspiblitz/issues/2366

* debug _provison.setup.sh

stop bitcoind and restart with new config to avoid rpc password error
disable and enable service instead of daemon-reload
CLN: don't use passwordC  as seedPassword

* add cln.setname.sh

make lnd.setname.sh work with parallel wallets

* improve comments

* SYSTEM: add CLNLOG and CLNCONF options

* SYSTEM menu fixes

* cln: add more aliases cln, clnlog, clnconf

* cln: activate the backup plugin on every install

* SERVICES menu: fix chantools/CLN switch

* cln: load plugins from ${netprefix}cln-plugins-enabled

changed the config paths to $lightning-dir/config or /networkname/config

plugins are downloaded to the SDcard:
/home/bitcoin/cln-plugins-available/
symlinked and loaded automatically from:
/home/bitcoin/${netprefix}cln-plugins-enabled

Related: #2295

* sparko: don't show logs after install

* #2425 Adding experimental Blitz WebUI & API (#2426)

* no password C & D when cln

* add debug echos

* set defaults before

* #2228 wider grep to detect nvms (#2427)

* cln.hsmtool: init backup with the new wallet

* cln.install: fix access to raspiblitz.conf

* cln-plugin.backup: fix path to backup-cli

* cln: hide unhelpful warnings during setup

* remove old jinja template rendering

* fix lnd unlock detection

* cln: look for files in .lightning dir with sudo

* cln: correct lightning name in FInalDialog + typo

* cln: make sure .lightning/bitcoin dir exists

* FinalDialog: make the 24 words fit

* cln.install.sh: create cln config if not present

* Simplify localIP detection and improve compatibility (#2432)

* show tail info on provision

* only show lnd options when activated

* fix syntax

* only show main lightning impl options for RC1

* cln: always start the lightnind.service

* cln: clear before showing summary

* start cln on the end of provisioning

* exit 0 on cln menu

* press key after single actions

* remove key press on cln actions

* change to none

* detect cln running

* fix syntax

* fix lightniing info

* add TODO for CLN

* add clnblockheight

* zty with user bitcoin

* check synced to chain for cln

* fix increment

* try scanprogress

* use cln sync detection and progress

* replace LNTYPE

* next line

* fix spaces

* fix spaces

* Update README.md (#2456)

Fix 404

* Fix FAQ links (#2441)

* Fix invalid URL ( (#2440)

* support channels (#2382)

* use #2370 height optimization

* adjust exit codes in menu scripts

* adjust password menu exit codes

* adapt shutdown for cln

* settings adapt to running lightning impl

* fix syntax

* debug info

* add debug

* better height

* add default values

* add config entry if not there yet

* change default value

* Added exit info for cln

* make sure to load config file if available

* add sparko to menu

* add default for sparko

* replace default sparko entry

* show sparko installed or not

* add more description to sparko option

* RTL for clightnign in service menu

* main menu item rtl

* add RTL description

* debug in RTL install

* install sparko on recovery

* update menu with cln

* rework menu options

Co-authored-by: openoms <oms@tuta.io>
Co-authored-by: openoms <43343391+openoms@users.noreply.github.com>
Co-authored-by: rek79 <rek79@users.noreply.github.com>
Co-authored-by: Bitpaint <67663265+bitpaint@users.noreply.github.com>
Co-authored-by: João Thallis <joaothallis@icloud.com>
Co-authored-by: Peter Flock <78184669+peterflock@users.noreply.github.com>
Co-authored-by: nyxnor <nyxnor@protonmail.com>
2021-08-04 00:18:30 +02:00

751 lines
29 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/bash
# This script gets called from a fresh SD card
# starting up that has an config file on HDD
# from old RaspiBlitz or manufacturer to
# to install and config services
# LOGFILE - store debug logs of bootstrap
logFile="/home/admin/raspiblitz.log"
# INFOFILE - state data from bootstrap
infoFile="/home/admin/raspiblitz.info"
# CONFIGFILE - configuration of RaspiBlitz
configFile="/mnt/hdd/raspiblitz.conf"
# log header
echo "" >> ${logFile}
echo "###################################" >> ${logFile}
echo "# _provision_.sh" >> ${logFile}
echo "###################################" >> ${logFile}
sudo sed -i "s/^message=.*/message='Provisioning from Config'/g" ${infoFile}
# check if there is a config file
configExists=$(ls ${configFile} 2>/dev/null | grep -c '.conf')
if [ ${configExists} -eq 0 ]; then
echo "FAIL: no config file (${configFile}) found to run provision!" >> ${logFile}
exit 1
fi
# check that default parameter exist in config
parameterExists=$(cat /mnt/hdd/raspiblitz.conf | grep -c "lndExtraParameter=")
if [ ${parameterExists} -eq 0 ]; then
echo "lndExtraParameter=''" >> ${configFile}
fi
# import config values
source ${configFile}
##########################
# DISPLAY SETTINGS
##########################
# check if the raspiblitz config has a different display mode than the build image
echo "### DISPLAY SETTINGS ###" >> ${logFile}
# OLD: when nothing is set in raspiblitz.conf (<1.7)
existsDisplayClass=$(sudo cat ${configFile} | grep -c "displayClass=")
if [ "${existsDisplayClass}" == "0" ]; then
displayClass="lcd"
fi
# OLD: lcd2hdmi (deprecated)
if [ "${lcd2hdmi}" == "on" ]; then
echo "Convert lcd2hdmi=on to displayClass='hdmi'" >> ${logFile}
sudo sed -i "s/^lcd2hdmi=.*//g" ${configFile}
echo "displayClass=hdmi" >> ${configFile}
displayClass="hdmi"
elif [ "${lcd2hdmi}" != "" ]; then
echo "Remove old lcd2hdmi pramater from config" >> ${logFile}
sudo sed -i "s/^lcd2hdmi=.*//g" ${configFile}
displayClass="lcd"
fi
# OLD: headless (deprecated)
if [ "${headless}" == "on" ]; then
echo "Convert headless=on to displayClass='headless'" >> ${logFile}
sudo sed -i "s/^headless=.*//g" ${configFile}
echo "displayClass=headless" >> ${configFile}
displayClass="headless"
elif [ "${headless}" != "" ]; then
echo "Remove old headless pramater from config" >> ${logFile}
sudo sed -i "s/^headless=.*//g" ${configFile}
displayClass="lcd"
fi
# NEW: decide by displayClass
echo "raspiblitz.info(${infoFileDisplayClass}) raspiblitz.conf(${displayClass})" >> ${logFile}
if [ "${infoFileDisplayClass}" != "" ] && [ "${displayClass}" != "" ]; then
if [ "${infoFileDisplayClass}" != "${displayClass}" ]; then
echo "Need to update displayClass from (${infoFileDisplayClass}) to (${displayClass})'" >> ${logFile}
sudo /home/admin/config.scripts/blitz.display.sh set-display ${displayClass} >> ${logFile}
echo "going into reboot" >> ${logFile}
sudo cp ${logFile} ${logFile}.display.recover
sudo shutdown -r now
exit 0
else
echo "Display Setting is correct ... no need for change" >> ${logFile}
fi
else
echo "WARN values in raspiblitz info and/or conf file seem broken" >> ${logFile}
fi
##########################
# BASIC SYSTEM SETTINGS
##########################
echo "### BASIC SYSTEM SETTINGS ###" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup System .'/g" ${infoFile}
# install litecoin (just if needed)
if [ "${network}" = "litecoin" ]; then
echo "Installing Litecoin ..." >> ${logFile}
/home/admin/config.scripts/blitz.litecoin.sh on >> ${logFile}
fi
echo "# Make sure the user bitcoin is in the debian-tor group"
sudo usermod -a -G debian-tor bitcoin
# set hostname data
echo "Setting lightning alias: ${hostname}" >> ${logFile}
sudo sed -i "s/^alias=.*/alias=${hostname}/g" /home/admin/assets/lnd.${network}.conf >> ${logFile} 2>&1
# link old SSH PubKeys
# so that client ssh_known_hosts is not complaining after update
if [ -d "/mnt/hdd/ssh" ]; then
echo "Old SSH PubKey exists on HDD > copy them HDD to SD card for next start" >> ${logFile}
sudo cp -r /mnt/hdd/ssh/* /etc/ssh/ >> ${logFile} 2>&1
else
echo "No SSH PubKey exists on HDD > copy from SD card to HDD as backup" >> ${logFile}
sudo cp -r /etc/ssh /mnt/hdd/ssh >> ${logFile} 2>&1
fi
# just copy - dont link anymore so that sshd will also start without HDD connected
# see: https://github.com/rootzoll/raspiblitz/issues/1798
#sudo rm -rf /etc/ssh >> ${logFile} 2>&1
#sudo ln -s /mnt/hdd/ssh /etc/ssh >> ${logFile} 2>&1
#sudo /home/admin/config.scripts/blitz.systemd.sh update-sshd >> ${logFile} 2>&1
# optimze mempool if RAM >1GB
kbSizeRAM=$(cat /proc/meminfo | grep "MemTotal" | sed 's/[^0-9]*//g')
if [ ${kbSizeRAM} -gt 1500000 ]; then
echo "Detected RAM >1GB --> optimizing ${network}.conf"
sudo sed -i "s/^maxmempool=.*/maxmempool=300/g" /mnt/hdd/${network}/${network}.conf
fi
if [ ${kbSizeRAM} -gt 3500000 ]; then
echo "Detected RAM >3GB --> optimizing ${network}.conf"
sudo sed -i "s/^maxmempool=.*/maxmempool=300/g" /mnt/hdd/${network}/${network}.conf
fi
# link and copy HDD content into new OS on sd card
echo "Copy HDD content for user admin" >> ${logFile}
sudo mkdir /home/admin/.${network} >> ${logFile} 2>&1
sudo cp /mnt/hdd/${network}/${network}.conf /home/admin/.${network}/${network}.conf >> ${logFile} 2>&1
sudo mkdir /home/admin/.lnd >> ${logFile} 2>&1
sudo cp /mnt/hdd/lnd/lnd.conf /home/admin/.lnd/lnd.conf >> ${logFile} 2>&1
sudo cp /mnt/hdd/lnd/tls.cert /home/admin/.lnd/tls.cert >> ${logFile} 2>&1
sudo mkdir /home/admin/.lnd/data >> ${logFile} 2>&1
sudo cp -r /mnt/hdd/lnd/data/chain /home/admin/.lnd/data/chain >> ${logFile} 2>&1
sudo chown -R admin:admin /home/admin/.${network} >> ${logFile} 2>&1
sudo chown -R admin:admin /home/admin/.lnd >> ${logFile} 2>&1
sudo cp /home/admin/assets/${network}d.service /etc/systemd/system/${network}d.service >> ${logFile} 2>&1
sudo cp /home/admin/assets/tmux.conf.local /mnt/hdd/.tmux.conf.local >> ${logFile} 2>&1
sudo chown admin:admin /mnt/hdd/.tmux.conf.local >> ${logFile} 2>&1
sudo ln -s -f /mnt/hdd/.tmux.conf.local /home/admin/.tmux.conf.local >> ${logFile} 2>&1
# backup LND dir (especially for macaroons and tlscerts)
# https://github.com/rootzoll/raspiblitz/issues/324
echo "*** Make backup of LND directory" >> ${logFile}
sudo rm -r /mnt/hdd/backup_lnd 2>/dev/null
sudo cp -r /mnt/hdd/lnd /mnt/hdd/backup_lnd >> ${logFile} 2>&1
numOfDiffers=$(sudo diff -arq /mnt/hdd/lnd /mnt/hdd/backup_lnd | grep -c "differ")
if [ ${numOfDiffers} -gt 0 ]; then
echo "FAIL: Backup was not successfull" >> ${logFile}
sudo diff -arq /mnt/hdd/lnd /mnt/hdd/backup_lnd >> ${logFile} 2>&1
echo "removing backup dir to prevent false override" >> ${logFile}
else
echo "OK Backup is valid." >> ${logFile}
fi
echo "" >> ${logFile}
##########################
# FINISH SETUP
##########################
# finish setup (SWAP, Benus, Firewall, Update, ..)
sudo sed -i "s/^message=.*/message='Setup System ..'/g" ${infoFile}
# add bonus scripts (auto install deactivated to reduce third party repos)
mkdir /home/admin/tmpScriptDL
cd /home/admin/tmpScriptDL
echo "installing bash completion for bitcoin-cli and lncli"
wget https://raw.githubusercontent.com/bitcoin/bitcoin/master/contrib/bitcoin-cli.bash-completion
wget https://raw.githubusercontent.com/lightningnetwork/lnd/master/contrib/lncli.bash-completion
sudo cp *.bash-completion /etc/bash_completion.d/
echo "OK - bash completion available after next login"
echo "type \"bitcoin-cli getblockch\", press [Tab] → bitcoin-cli getblockchaininfo"
rm -r /home/admin/tmpScriptDL
cd
###### SWAP File
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
if [ ${isSwapExternal} -eq 0 ]; then
echo "No external SWAP found - creating ... "
sudo /home/admin/config.scripts/blitz.datadrive.sh swap on
else
echo "SWAP already OK"
fi
####### FIREWALL - just install (not configure)
echo ""
echo "*** Setting and Activating Firewall ***"
echo "deny incoming connection on other ports"
sudo ufw default deny incoming
echo "allow outgoing connections"
sudo ufw default allow outgoing
echo "allow: ssh"
sudo ufw allow ssh
echo "allow: bitcoin testnet"
sudo ufw allow 18333 comment 'bitcoin testnet'
echo "allow: bitcoin mainnet"
sudo ufw allow 8333 comment 'bitcoin mainnet'
echo "allow: litecoin mainnet"
sudo ufw allow 9333 comment 'litecoin mainnet'
echo 'allow: lightning testnet'
sudo ufw allow 19735 comment 'lightning testnet'
echo "allow: lightning mainnet"
sudo ufw allow 9735 comment 'lightning mainnet'
echo "allow: lightning gRPC"
sudo ufw allow 10009 comment 'lightning gRPC'
echo "allow: lightning REST API"
sudo ufw allow 8080 comment 'lightning REST API'
echo "allow: transmission"
sudo ufw allow 49200:49250/tcp comment 'rtorrent'
echo "allow: public web HTTP"
sudo ufw allow from any to any port 80 comment 'allow public web HTTP'
echo "allow: local web admin HTTPS"
sudo ufw allow from 10.0.0.0/8 to any port 443 comment 'allow local LAN HTTPS'
sudo ufw allow from 172.16.0.0/12 to any port 443 comment 'allow local LAN HTTPS'
sudo ufw allow from 192.168.0.0/16 to any port 443 comment 'allow local LAN HTTPS'
echo "open firewall for auto nat discover (see issue #129)"
sudo ufw allow proto udp from 10.0.0.0/8 port 1900 to any comment 'allow local LAN SSDP for UPnP discovery'
sudo ufw allow proto udp from 172.16.0.0/12 port 1900 to any comment 'allow local LAN SSDP for UPnP discovery'
sudo ufw allow proto udp from 192.168.0.0/16 port 1900 to any comment 'allow local LAN SSDP for UPnP discovery'
echo "enable lazy firewall"
sudo ufw --force enable
echo ""
# update system
echo ""
echo "*** Update System ***"
sudo apt-mark hold raspberrypi-bootloader
sudo apt-get update -y
echo "OK - System is now up to date"
# mark setup is done
sudo sed -i "s/^setupStep=.*/setupStep=100/g" /home/admin/raspiblitz.info
##########################
# PROVISIONING SERVICES
##########################
sudo sed -i "s/^message=.*/message='Installing Services'/g" ${infoFile}
echo "### RUNNING PROVISIONING SERVICES ###" >> ${logFile}
# BLITZ WEB SERVICE
echo "Provisioning BLITZ WEB SERVICE - run config script" >> ${logFile}
/home/admin/config.scripts/blitz.web.sh on >> ${logFile} 2>&1
# BITCOIN INTERIMS UPDATE
if [ ${#bitcoinInterimsUpdate} -gt 0 ]; then
sudo sed -i "s/^message=.*/message='Provisioning Bitcoin Core update'/g" ${infoFile}
if [ "${bitcoinInterimsUpdate}" == "reckless" ]; then
# recklessly update Bitcoin Core to latest release on GitHub
echo "Provisioning BItcoin Core reckless interims update" >> ${logFile}
sudo /home/admin/config.scripts/bitcoin.update.sh reckless >> ${logFile}
else
# when installing the same sd image - this will re-trigger the secure interims update
# if this a update with a newer RaspiBlitz version .. interims update will be ignored
# because standard Bitcoin Core version is most more up to date
echo "Provisioning BItcoin Core tested interims update" >> ${logFile}
sudo /home/admin/config.scripts/bitcoin.update.sh tested ${bitcoinInterimsUpdate} >> ${logFile}
fi
else
echo "Provisioning Bitcoin Core interims update - keep default" >> ${logFile}
fi
# LND INTERIMS UPDATE
if [ ${#lndInterimsUpdate} -gt 0 ]; then
sudo sed -i "s/^message=.*/message='Provisioning LND update'/g" ${infoFile}
if [ "${lndInterimsUpdate}" == "reckless" ]; then
# recklessly update LND to latest release on GitHub (just for test & dev nodes)
echo "Provisioning LND reckless interims update" >> ${logFile}
sudo /home/admin/config.scripts/lnd.update.sh reckless >> ${logFile}
else
# when installing the same sd image - this will re-trigger the secure interims update
# if this a update with a newer RaspiBlitz version .. interims update will be ignored
# because standard LND version is most more up to date
echo "Provisioning LND verified interims update" >> ${logFile}
sudo /home/admin/config.scripts/lnd.update.sh verified ${lndInterimsUpdate} >> ${logFile}
fi
else
echo "Provisioning LND interims update - keep default" >> ${logFile}
fi
# TESTNET
if [ "${chain}" = "test" ]; then
echo "Provisioning TESTNET - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Provisioning Testnet'/g" ${infoFile}
sudo /home/admin/config.scripts/network.chain.sh testnet >> ${logFile} 2>&1
else
echo "Provisioning TESTNET - keep default" >> ${logFile}
fi
# TOR
if [ "${runBehindTor}" == "on" ]; then
echo "Provisioning TOR - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup Tor (takes time)'/g" ${infoFile}
sudo /home/admin/config.scripts/internet.tor.sh on >> ${logFile} 2>&1
else
echo "Provisioning TOR - keep default" >> ${logFile}
fi
# AUTO PILOT
if [ "${autoPilot}" = "on" ]; then
echo "Provisioning AUTO PILOT - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup AutoPilot'/g" ${infoFile}
sudo /home/admin/config.scripts/lnd.autopilot.sh on >> ${logFile} 2>&1
else
echo "Provisioning AUTO PILOT - keep default" >> ${logFile}
fi
# NETWORK UPNP
if [ "${networkUPnP}" = "on" ]; then
echo "Provisioning NETWORK UPnP - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup UPnP'/g" ${infoFile}
sudo /home/admin/config.scripts/network.upnp.sh on >> ${logFile} 2>&1
else
echo "Provisioning NETWORK UPnP - keep default" >> ${logFile}
fi
# LND AUTO NAT DISCOVERY
if [ "${autoNatDiscovery}" = "on" ]; then
echo "Provisioning LND AUTO NAT DISCOVERY - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup AutoNAT'/g" ${infoFile}
sudo /home/admin/config.scripts/lnd.autonat.sh on >> ${logFile} 2>&1
else
echo "Provisioning AUTO NAT DISCOVERY - keep default" >> ${logFile}
fi
# DYNAMIC DOMAIN
if [ "${#dynDomain}" -gt 0 ]; then
echo "Provisioning DYNAMIC DOMAIN - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup DynamicDomain'/g" ${infoFile}
sudo /home/admin/config.scripts/internet.dyndomain.sh on ${dynDomain} ${dynUpdateUrl} >> ${logFile} 2>&1
else
echo "Provisioning DYNAMIC DOMAIN - keep default" >> ${logFile}
fi
# RTL (LND)
if [ "${rtlWebinterface}" = "on" ]; then
echo "Provisioning RTL LND - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup RTL (takes time)'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.rtl.sh on lnd mainnet >> ${logFile} 2>&1
sudo systemctl disable RTL # will get enabled after recover dialog
else
echo "Provisioning RTL LND - keep default" >> ${logFile}
fi
# RTL (CLN)
if [ "${crtlWebinterface}" = "on" ]; then
echo "Provisioning RTL CLN - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup RTL (takes time)'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.rtl.sh on cln mainnet >> ${logFile} 2>&1
sudo systemctl disable cRTL # will get enabled after recover dialog
else
echo "Provisioning RTL CLN - keep default" >> ${logFile}
fi
# SPARKO
if [ "${sparko}" = "on" ]; then
echo "Provisioning Sparko - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup SPARKO (takes time)'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/cln-plugin.sparko.sh on mainnet >> ${logFile} 2>&1
sudo systemctl disable cRTL # will get enabled after recover dialog
else
echo "Provisioning RTL CLN - keep default" >> ${logFile}
fi
#LOOP
if [ "${loop}" = "on" ]; then
echo "Provisioning Lightning Loop - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup Lightning Loop'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.loop.sh on >> ${logFile} 2>&1
sudo systemctl disable loopd # will get enabled after recover dialog
else
echo "Provisioning Lightning Loop - keep default" >> ${logFile}
fi
#BTC RPC EXPLORER
if [ "${BTCRPCexplorer}" = "on" ]; then
echo "Provisioning BTCRPCexplorer - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup BTCRPCexplorer (takes time)'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.btc-rpc-explorer.sh on >> ${logFile} 2>&1
sudo systemctl disable btc-rpc-explorer # will get enabled after recover dialog
else
echo "Provisioning BTCRPCexplorer - keep default" >> ${logFile}
fi
#ELECTRS
if [ "${ElectRS}" = "on" ]; then
echo "Provisioning ElectRS - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup ElectRS (takes time)'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.electrs.sh on >> ${logFile} 2>&1
sudo systemctl disable electrs # will get enabled after recover dialog
else
echo "Provisioning ElectRS - keep default" >> ${logFile}
fi
# BTCPAYSERVER
if [ "${BTCPayServer}" = "on" ]; then
echo "Provisioning BTCPAYSERVER on TOR - running setup" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup BTCPay (takes time)'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.btcpayserver.sh on >> ${logFile} 2>&1
else
echo "Provisioning BTCPayServer - keep default" >> ${logFile}
fi
# deprecated - see: #2031
# LNDMANAGE
#if [ "${lndmanage}" = "on" ]; then
# echo "Provisioning lndmanage - run config script" >> ${logFile}
# sudo sed -i "s/^message=.*/message='Setup lndmanage '/g" ${infoFile}
# sudo -u admin /home/admin/config.scripts/bonus.lndmanage.sh on >> ${logFile} 2>&1
#else
# echo "Provisioning lndmanage - not active" >> ${logFile}
#fi
# CUSTOM PORT
echo "Provisioning LND Port" >> ${logFile}
if [ ${#lndPort} -eq 0 ]; then
lndPort=$(sudo cat /mnt/hdd/lnd/lnd.conf | grep "^listen=*" | cut -f2 -d':')
fi
if [ ${#lndPort} -gt 0 ]; then
if [ "${lndPort}" != "9735" ]; then
echo "User is running custom LND port: ${lndPort}" >> ${logFile}
sudo /home/admin/config.scripts/lnd.setport.sh ${lndPort} >> ${logFile} 2>&1
else
echo "User is running standard LND port: ${lndPort}" >> ${logFile}
fi
else
echo "Was not able to get LND port from config." >> ${logFile}
fi
# DNS Server
if [ ${#dnsServer} -gt 0 ]; then
echo "Provisioning DNS Server - Setting DNS Server" >> ${logFile}
sudo /home/admin/config.scripts/internet.dns.sh ${dnsServer} >> ${logFile} 2>&1
else
echo "Provisioning DNS Server - keep default" >> ${logFile}
fi
# CHANTOOLS
if [ "${chantools}" == "on" ]; then
echo "Provisioning chantools - run config script" >> ${logFile}
sudo /home/admin/config.scripts/bonus.chantools.sh on >> ${logFile} 2>&1
else
echo "Provisioning chantools - keep default" >> ${logFile}
fi
# ROOT SSH KEYS
# check if a backup on HDD exists  if so, restore it
backupRootSSH=$(sudo ls /mnt/hdd/ssh/root_backup 2>/dev/null | grep -c "id_rsa")
if [ ${backupRootSSH} -gt 0 ]; then
echo "Provisioning Root SSH Keys - RESTORING from HDD" >> ${logFile}
sudo cp -r /mnt/hdd/ssh/root_backup /root/.ssh
sudo chown -R root:root /root/.ssh
else
echo "Provisioning Root SSH Keys - keep default" >> ${logFile}
fi
# SSH TUNNEL
if [ "${#sshtunnel}" -gt 0 ]; then
echo "Provisioning SSH Tunnel - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup SSH Tunnel'/g" ${infoFile}
sudo /home/admin/config.scripts/internet.sshtunnel.py restore ${sshtunnel} >> ${logFile} 2>&1
else
echo "Provisioning SSH Tunnel - not active" >> ${logFile}
fi
# ZEROTIER
if [ "${#zerotier}" -gt 0 ] && [ "${zerotier}" != "off" ]; then
echo "Provisioning ZeroTier - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup ZeroTier'/g" ${infoFile}
sudo /home/admin/config.scripts/bonus.zerotier.sh on ${zerotier} >> ${logFile} 2>&1
else
echo "Provisioning ZeroTier - not active" >> ${logFile}
fi
# LCD ROTATE
if [ "${#lcdrotate}" -eq 0 ]; then
# when upgrading from an old raspiblitz - enforce lcdrotate = 0
lcdrotate=0
fi
echo "Provisioning LCD rotate - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='LCD Rotate'/g" ${infoFile}
sudo /home/admin/config.scripts/blitz.display.sh rotate ${lcdrotate} >> ${logFile} 2>&1
# TOUCHSCREEN
if [ "${#touchscreen}" -gt 0 ]; then
echo "Provisioning Touchscreen - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup Touchscreen'/g" ${infoFile}
sudo /home/admin/config.scripts/blitz.touchscreen.sh ${touchscreen} >> ${logFile} 2>&1
else
echo "Provisioning Touchscreen - not active" >> ${logFile}
fi
# UPS
if [ "${#ups}" -gt 0 ]; then
echo "Provisioning UPS - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup UPS'/g" ${infoFile}
sudo /home/admin/config.scripts/blitz.ups.sh on ${ups} >> ${logFile} 2>&1
else
echo "Provisioning UPS - not active" >> ${logFile}
fi
# LNbits
if [ "${LNBits}" = "on" ]; then
echo "Provisioning LNbits - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup LNbits '/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.lnbits.sh on >> ${logFile} 2>&1
else
echo "Provisioning LNbits - keep default" >> ${logFile}
fi
# JoinMarket
if [ "${joinmarket}" = "on" ]; then
echo "Provisioning JoinMarket - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup JoinMarket'/g" ${infoFile}
sudo /home/admin/config.scripts/bonus.joinmarket.sh on >> ${logFile} 2>&1
else
echo "Provisioning JoinMarket - keep default" >> ${logFile}
fi
# Specter
if [ "${specter}" = "on" ]; then
echo "Provisioning Specter - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup Specter'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.cryptoadvance-specter.sh on >> ${logFile} 2>&1
else
echo "Provisioning Specter - keep default" >> ${logFile}
fi
# Faraday
if [ "${faraday}" = "on" ]; then
echo "Provisioning Faraday - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup Faraday'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.faraday.sh on >> ${logFile} 2>&1
else
echo "Provisioning Faraday - keep default" >> ${logFile}
fi
# BOS
if [ "${bos}" = "on" ]; then
echo "Provisioning Balance of Satoshis - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup Balance of Satoshis'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.bos.sh on >> ${logFile} 2>&1
else
echo "Provisioning Balance of Satoshis - keep default" >> ${logFile}
fi
# thunderhub
if [ "${thunderhub}" = "on" ]; then
echo "Provisioning ThunderHub - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup ThunderHub'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.thunderhub.sh on >> ${logFile} 2>&1
else
echo "Provisioning ThunderHub - keep default" >> ${logFile}
fi
# mempool space
if [ "${mempoolExplorer}" = "on" ]; then
echo "Provisioning MempoolSpace - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup Mempool Space'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.mempool.sh on >> ${logFile} 2>&1
else
echo "Provisioning Mempool Explorer - keep default" >> ${logFile}
fi
# letsencrypt
if [ "${letsencrypt}" = "on" ]; then
echo "Provisioning letsencrypt - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup letsencrypt'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.letsencrypt.sh on >> ${logFile} 2>&1
else
echo "Provisioning letsencrypt - keep default" >> ${logFile}
fi
# kindle-display
if [ "${kindleDisplay}" = "on" ]; then
echo "Provisioning kindle-display - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup kindle-display'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.kindle-display.sh on >> ${logFile} 2>&1
else
echo "Provisioning kindle-display - keep default" >> ${logFile}
fi
# pyblock
if [ "${pyblock}" = "on" ]; then
echo "Provisioning pyblock - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup pyblock'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.pyblock.sh on >> ${logFile} 2>&1
else
echo "Provisioning pyblock - keep default" >> ${logFile}
fi
# stacking-sats-kraken
if [ "${stackingSatsKraken}" = "on" ]; then
echo "Provisioning Stacking Sats Kraken - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup Stacking Sats Kraken'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.stacking-sats-kraken.sh on >> ${logFile} 2>&1
else
echo "Provisioning Stacking Sats Kraken - keep default" >> ${logFile}
fi
# lit (make sure to be installed after RTL)
if [ "${lit}" = "on" ]; then
echo "Provisioning LIT - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup LIT'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.lit.sh on >> ${logFile} 2>&1
else
echo "Provisioning LIT - keep default" >> ${logFile}
fi
# pool
if [ "${pool}" = "on" ]; then
echo "Provisioning Pool - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup Pool'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.pool.sh on >> ${logFile} 2>&1
else
echo "Provisioning Pool - keep default" >> ${logFile}
fi
# sphinxrelay
if [ "${sphinxrelay}" = "on" ]; then
echo "Sphinx-Relay - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup Sphinx-Relay'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.sphinxrelay.sh on >> ${logFile} 2>&1
else
echo "Sphinx-Relay - keep default" >> ${logFile}
fi
# circuitbreaker
if [ "${circuitbreaker}" = "on" ]; then
echo "Provisioning CircuitBreaker - run config script" >> ${logFile}
sudo sed -i "s/^message=.*/message='Setup CircuitBreaker'/g" ${infoFile}
sudo -u admin /home/admin/config.scripts/bonus.circuitbreaker.sh on >> ${logFile} 2>&1
else
echo "Provisioning CircuitBreaker - keep default" >> ${logFile}
fi
# custom install script from user
customInstallAvailable=$(sudo ls /mnt/hdd/app-data/custom-installs.sh 2>/dev/null | grep -c "custom-installs.sh")
if [ ${customInstallAvailable} -gt 0 ]; then
echo "Running the custom install script .." >> ${logFile}
# copy script over to admin (in case HDD is not allowing exec)
sudo cp -av /mnt/hdd/app-data/custom-installs.sh /home/admin/custom-installs.sh >> ${logFile}
# make sure script is executable
sudo chmod +x /home/admin/custom-installs.sh >> ${logFile}
# run it & delete it again
sudo /home/admin/custom-installs.sh >> ${logFile}
sudo rm /home/admin/custom-installs.sh >> ${logFile}
echo "Done" >> ${logFile}
else
echo "No custom install script ... adding the placeholder." >> ${logFile}
sudo cp /home/admin/assets/custom-installs.sh /mnt/hdd/app-data/custom-installs.sh
fi
# replay backup LND conf & tlscerts
# https://github.com/rootzoll/raspiblitz/issues/324
echo "" >> ${logFile}
echo "*** Replay backup of LND conf/tls" >> ${logFile}
if [ -d "/mnt/hdd/backup_lnd" ]; then
echo "Copying TLS ..." >> ${logFile}
sudo cp /mnt/hdd/backup_lnd/tls.cert /mnt/hdd/lnd/tls.cert >> ${logFile} 2>&1
sudo cp /mnt/hdd/backup_lnd/tls.key /mnt/hdd/lnd/tls.key >> ${logFile} 2>&1
sudo chown -R bitcoin:bitcoin /mnt/hdd/lnd >> ${logFile} 2>&1
echo "On next final restart admin creds will be updated by _boostrap.sh" >> ${logFile}
echo "DONE" >> ${logFile}
else
echo "No BackupDir so skipping that step." >> ${logFile}
fi
echo "" >> ${logFile}
# repair Bitcoin conf if needed
echo "*** Repair Bitcoin Conf (if needed)" >> ${logFile}
confExists="$(sudo ls /mnt/hdd/${network} | grep -c "${network}.conf")"
if [ ${confExists} -eq 0 ]; then
echo "Doing init of ${network}.conf" >> ${logFile}
sudo cp /home/admin/assets/bitcoin.conf /mnt/hdd/bitcoin/bitcoin.conf
sudo chown bitcoin:bitcoin /mnt/hdd/bitcoin/bitcoin.conf
fi
# singal setup done
sudo sed -i "s/^message=.*/message='Setup Done'/g" ${infoFile}
# set the local network hostname (just if set in config - will not be set anymore by default in newer version)
# have at the end - see https://github.com/rootzoll/raspiblitz/issues/462
# see also https://github.com/rootzoll/raspiblitz/issues/819
if [ ${#hostname} -gt 0 ]; then
hostnameSanatized=$(echo "${hostname}"| tr -dc '[:alnum:]\n\r')
if [ ${#hostnameSanatized} -gt 0 ]; then
# by default set hostname for older versions on update
if [ ${#setnetworkname} -eq 0 ]; then
setnetworkname=1
fi
if [ "${setnetworkname}" = "1" ]; then
echo "Setting new network hostname '$hostnameSanatized'" >> ${logFile}
sudo raspi-config nonint do_hostname ${hostnameSanatized} >> ${logFile} 2>&1
else
echo "Not setting local network hostname" >> ${logFile}
fi
else
echo "WARNING: hostname in raspiblitz.conf contains just special chars" >> ${logFile}
fi
else
echo "No hostname set." >> ${logFile}
fi
# PERMANENT MOUNT OF HDD/SSD
# always at the end, because data drives will be just available again after a reboot
echo "Prepare fstab for permanent data drive mounting .." >> ${logFile}
# get info on data drive
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
# update /etc/fstab
echo "datadisk --> ${datadisk}" >> ${logFile}
echo "datapartition --> ${datapartition}" >> ${logFile}
if [ ${isBTRFS} -eq 0 ]; then
sudo /home/admin/config.scripts/blitz.datadrive.sh fstab ${datapartition} >> ${logFile}
else
sudo /home/admin/config.scripts/blitz.datadrive.sh fstab ${datadisk} >> ${logFile}
fi
# MAKE SURE SERVICES ARE RUNNING
echo "Make sure main services are running .." >> ${logFile}
sudo systemctl start ${network}d
if [ "${lightning}" == "lnd" ];then
sudo systemctl start lnd
elif [ "${lightning}" == "cln" ];then
sudo systemctl start lightningd
fi
echo "DONE - Give raspi some cool off time after hard building .... 5 secs sleep" >> ${logFile}
sleep 5
echo "END Provisioning" >> ${logFile}