mirror of
https://github.com/rootzoll/raspiblitz.git
synced 2025-02-24 22:58:43 +01:00
* 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>
793 lines
27 KiB
Bash
Executable file
793 lines
27 KiB
Bash
Executable file
#!/bin/bash
|
|
|
|
# This script runs on every start called by boostrap.service
|
|
# see logs with --> tail -n 100 /home/admin/raspiblitz.log
|
|
|
|
################################
|
|
# BASIC SETTINGS
|
|
################################
|
|
|
|
# load codeVersion
|
|
source /home/admin/_version.info
|
|
|
|
# CONFIGFILE - configuration of RaspiBlitz
|
|
# used by fresh SD image to recover configuration
|
|
# and delivers basic config info for scripts
|
|
# make raspiblitz.conf if not there
|
|
sudo touch /mnt/hdd/raspiblitz.conf
|
|
configFile="/mnt/hdd/raspiblitz.conf"
|
|
|
|
# LOGFILE - store debug logs of bootstrap
|
|
# resets on every start
|
|
logFile="/home/admin/raspiblitz.log"
|
|
|
|
# INFOFILE - state data from bootstrap
|
|
# used by display and later setup steps
|
|
infoFile="/home/admin/raspiblitz.info"
|
|
|
|
# SETUPFILE
|
|
# this key/value file contains the state during the setup process
|
|
setupFile="/var/cache/raspiblitz/temp/raspiblitz.setup"
|
|
|
|
# Init boostrap log file
|
|
echo "Writing logs to: ${logFile}"
|
|
echo "" > $logFile
|
|
echo "***********************************************" >> $logFile
|
|
echo "Running RaspiBlitz Bootstrap ${codeVersion}" >> $logFile
|
|
date >> $logFile
|
|
echo "***********************************************" >> $logFile
|
|
|
|
# set default values for raspiblitz.info
|
|
network=""
|
|
chain=""
|
|
setupStep=0
|
|
setupPhase='boot'
|
|
fsexpanded=0
|
|
# see https://github.com/rootzoll/raspiblitz/issues/1265#issuecomment-813369284
|
|
displayClass="lcd"
|
|
displayType=""
|
|
fundRecovery=0
|
|
|
|
################################
|
|
# INIT raspiblitz.info
|
|
################################
|
|
|
|
# try to load old values if available (overwrites defaults)
|
|
source ${infoFile} 2>/dev/null
|
|
|
|
# try to load config values if available (config overwrites info)
|
|
source ${configFile} 2>/dev/null
|
|
|
|
# get first basic network info
|
|
source <(/home/admin/config.scripts/internet.sh status)
|
|
|
|
# get basic hardware info
|
|
source <(/home/admin/config.scripts/.sh status)
|
|
|
|
# get basic dns info
|
|
source <(sudo /home/admin/config.scripts/internet.dns.sh test nodialog)
|
|
|
|
# resetting info file
|
|
echo "Resetting the InfoFile: ${infoFile}"
|
|
echo "state=starting" > $infoFile
|
|
echo "message=" >> $infoFile
|
|
echo "baseimage=${baseimage}" >> $infoFile
|
|
echo "cpu=${cpu}" >> $infoFile
|
|
echo "board=${board}" >> $infoFile
|
|
echo "ramMB=${ramMB}" >> $infoFile
|
|
echo "network=${network}" >> $infoFile
|
|
echo "chain=${chain}" >> $infoFile
|
|
echo "localip='${localip}'" >> $infoFile
|
|
echo "online='${online}'" >> $infoFile
|
|
echo "dnsworking=${dnsworking}" >> $infoFile
|
|
echo "fsexpanded=${fsexpanded}" >> $infoFile
|
|
echo "displayClass=${displayClass}" >> $infoFile
|
|
echo "displayType=${displayType}" >> $infoFile
|
|
echo "setupStep=${setupStep}" >> $infoFile
|
|
echo "setupPhase=${setupPhase}" >> $infoFile
|
|
echo "fundRecovery=${fundRecovery}" >> $infoFile
|
|
if [ "${setupStep}" != "100" ]; then
|
|
echo "hostname=${hostname}" >> $infoFile
|
|
fi
|
|
sudo chmod 777 ${infoFile}
|
|
|
|
######################################
|
|
# CHECK SD CARD INCONSISTENT STATE
|
|
|
|
# when the provision did not ran thru without error (ask user for fresh sd card)
|
|
provisionFlagExists=$(sudo ls /home/admin/provision.flag | grep -c 'provision.flag')
|
|
if [ "${provisionFlagExists}" == "1" ]; then
|
|
sudo systemctl stop ${network}d 2>/dev/null
|
|
sudo systemctl stop lnd 2>/dev/null
|
|
sed -i "s/^state=.*/state=inconsistentsystem/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='provision did not ran thru'/g" ${infoFile}
|
|
echo "FAIL: 'provision did not ran thru - need fresh sd card!" >> ${logFile}
|
|
exit 1
|
|
fi
|
|
|
|
######################################
|
|
# SECTION FOR POSSIBLE REBOOT ACTIONS
|
|
systemInitReboot=0
|
|
|
|
################################
|
|
# FORCED SWITCH TO HDMI
|
|
# if a file called 'hdmi' gets
|
|
# placed onto the boot part of
|
|
# the sd card - switch to hdmi
|
|
################################
|
|
|
|
forceHDMIoutput=$(sudo ls /boot/hdmi* 2>/dev/null | grep -c hdmi)
|
|
if [ ${forceHDMIoutput} -eq 1 ]; then
|
|
# delete that file (to prevent loop)
|
|
sudo rm /boot/hdmi*
|
|
# switch to HDMI what will trigger reboot
|
|
echo "HDMI switch found ... activating HDMI display output & reboot" >> $logFile
|
|
sudo /home/admin/config.scripts/blitz.display.sh set-display hdmi >> $logFile
|
|
systemInitReboot=1
|
|
else
|
|
echo "No HDMI switch found. " >> $logFile
|
|
fi
|
|
|
|
################################
|
|
# SSH SERVER CERTS RESET
|
|
# if a file called 'ssh.reset' gets
|
|
# placed onto the boot part of
|
|
# the sd card - delete old ssh data
|
|
################################
|
|
|
|
sshReset=$(sudo ls /boot/ssh.reset* 2>/dev/null | grep -c reset)
|
|
if [ ${sshReset} -eq 1 ]; then
|
|
# delete that file (to prevent loop)
|
|
sudo rm /boot/ssh.reset* >> $logFile
|
|
# delete ssh certs
|
|
echo "SSHRESET switch found ... stopping SSH and deleting old certs" >> $logFile
|
|
sudo systemctl stop sshd >> $logFile
|
|
sudo rm /mnt/hdd/ssh/ssh_host* >> $logFile
|
|
sudo ssh-keygen -A >> $logFile
|
|
systemInitReboot=1
|
|
else
|
|
echo "No SSHRESET switch found. " >> $logFile
|
|
fi
|
|
|
|
################################
|
|
# BACKGROUND TASK RUN FROM BEGINNING
|
|
# on 1.7 sd card build background task runs after boostrap
|
|
# but bootstrap already needs background task running now
|
|
# REMOVE ON v1.8 release #2328
|
|
################################
|
|
|
|
backgroundNeedsEdit=$(sudo cat /etc/systemd/system/background.service 2>/dev/null | grep -c 'Wants=bootstrap.service')
|
|
if [ ${backgroundNeedsEdit} -eq 1 ]; then
|
|
echo "BACKGROUND EDIT needed ..." >> $logFile
|
|
sudo sed -i "s/^Wants=.*/Wants=network.target/g" /etc/systemd/system/background.service
|
|
sudo sed -i "s/^After=.*/After=network.target/g" /etc/systemd/system/background.service
|
|
systemInitReboot=1
|
|
else
|
|
echo "BACKGROUND EDIT already done. " >> $logFile
|
|
fi
|
|
|
|
################################
|
|
# FS EXPAND
|
|
# if a file called 'ssh.reset' gets
|
|
# placed onto the boot part of
|
|
# the sd card - delete old ssh data
|
|
################################
|
|
source <(sudo /home/admin/config.scripts/blitz.bootdrive.sh status)
|
|
if [ "${needsExpansion}" == "1" ] && [ "${fsexpanded}" == "0" ]; then
|
|
echo "FSEXPAND needed ... starting process" >> $logFile
|
|
sudo /home/admin/config.scripts/blitz.bootdrive.sh status >> $logFile
|
|
sudo /home/admin/config.scripts/blitz.bootdrive.sh fsexpand >> $logFile
|
|
systemInitReboot=1
|
|
elif [ "${tooSmall}" == "1" ]; then
|
|
echo "!!! FAIL !!!!!!!!!!!!!!!!!!!!" >> $logFile
|
|
echo "SDCARD TOO SMALL 16G minimum" >> $logFile
|
|
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" >> $logFile
|
|
sed -i "s/^state=.*/state=sdtoosmall/g" ${infoFile}
|
|
echo "System stopped. Please cut power." >> $logFile
|
|
sleep 6000
|
|
sudo shutdown -r now
|
|
slepp 100
|
|
exit 1
|
|
else
|
|
echo "No FS EXPAND needed. needsExpansion(${needsExpansion}) fsexpanded(${fsexpanded})" >> $logFile
|
|
fi
|
|
|
|
################################
|
|
# UASP FIX - first try
|
|
# if HDD is connected on start
|
|
################################
|
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh uasp-fix)
|
|
if [ "${neededReboot}" == "1" ]; then
|
|
echo "UASP FIX applied (1st-try) ... reboot needed." >> $logFile
|
|
systemInitReboot=1
|
|
else
|
|
echo "No UASP FIX needed (1st-try)." >> $logFile
|
|
fi
|
|
|
|
######################################
|
|
# CHECK IF REBOOT IS NEEDED
|
|
# from actions above
|
|
|
|
if [ "${systemInitReboot}" == "1" ]; then
|
|
sudo cp ${logFile} ${logFile}.systeminit
|
|
sudo sed -i "s/^state=.*/state=reboot/g" ${infoFile}
|
|
sudo shutdown -r now
|
|
sleep 100
|
|
exit 0
|
|
fi
|
|
|
|
################################
|
|
# BOOT LOGO
|
|
################################
|
|
|
|
# display 3 secs logo - try to kickstart LCD
|
|
# see https://github.com/rootzoll/raspiblitz/issues/195#issuecomment-469918692
|
|
# see https://github.com/rootzoll/raspiblitz/issues/647
|
|
# see https://github.com/rootzoll/raspiblitz/pull/1580
|
|
randnum=$(shuf -i 0-7 -n 1)
|
|
/home/admin/config.scripts/blitz.display.sh image /home/admin/raspiblitz/pictures/startlogo${randnum}.png
|
|
sleep 5
|
|
/home/admin/config.scripts/blitz.display.sh hide
|
|
|
|
################################
|
|
# GENERATE UNIQUE SSH PUB KEYS
|
|
# on first boot up
|
|
################################
|
|
|
|
numberOfPubKeys=$(sudo ls /etc/ssh/ | grep -c 'ssh_host_')
|
|
if [ ${numberOfPubKeys} -eq 0 ]; then
|
|
echo "*** Generating new SSH PubKeys" >> $logFile
|
|
sudo dpkg-reconfigure openssh-server
|
|
echo "OK" >> $logFile
|
|
fi
|
|
|
|
################################
|
|
# CLEANING BOOT SYSTEM
|
|
################################
|
|
|
|
# resetting start count files
|
|
echo "SYSTEMD RESTART LOG: blockchain (bitcoind/litecoind)" > /home/admin/systemd.blockchain.log
|
|
echo "SYSTEMD RESTART LOG: lightning (LND)" > /home/admin/systemd.lightning.log
|
|
sudo chmod 777 /home/admin/systemd.blockchain.log
|
|
sudo chmod 777 /home/admin/systemd.lightning.log
|
|
|
|
# Emergency cleaning logs when over 1GB (to prevent SD card filling up)
|
|
# see https://github.com/rootzoll/raspiblitz/issues/418#issuecomment-472180944
|
|
echo "*** Checking Log Size ***"
|
|
logsMegaByte=$(sudo du -c -m /var/log | grep "total" | awk '{print $1;}')
|
|
if [ ${logsMegaByte} -gt 1000 ]; then
|
|
echo "WARN !! Logs /var/log in are bigger then 1GB"
|
|
echo "ACTION --> DELETED ALL LOGS"
|
|
if [ -d "/var/log/nginx" ]; then
|
|
nginxLog=1
|
|
echo "/var/log/nginx is present"
|
|
fi
|
|
sudo rm -r /var/log/*
|
|
if [ $nginxLog == 1 ]; then
|
|
sudo mkdir /var/log/nginx
|
|
echo "Recreated /var/log/nginx"
|
|
fi
|
|
sleep 3
|
|
echo "WARN !! Logs in /var/log in were bigger then 1GB and got emergency delete to prevent fillup."
|
|
echo "If you see this in the logs please report to the GitHub issues, so LOG config needs to hbe optimized."
|
|
else
|
|
echo "OK - logs are at ${logsMegaByte} MB - within safety limit"
|
|
fi
|
|
echo ""
|
|
|
|
###############################
|
|
# WAIT FOR ALL SERVICES
|
|
|
|
# get the state of data drive
|
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
|
|
|
|
################################
|
|
# WAIT LOOP: HDD CONNECTED
|
|
################################
|
|
|
|
echo "Waiting for HDD/SSD ..." >> $logFile
|
|
until [ ${isMounted} -eq 1 ] || [ ${#hddCandidate} -gt 0 ]
|
|
do
|
|
|
|
# recheck HDD/SSD
|
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
|
|
echo "isMounted: $isMounted"
|
|
echo "hddCandidate: $hddCandidate"
|
|
|
|
# in case of HDD analyse ERROR
|
|
if [ "${hddError}" != "" ]; then
|
|
echo "FAIL - error on HDD analysis: ${hddError}" >> $logFile
|
|
sed -i "s/^state=.*/state=errorHDD/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='${hddError}'/g" ${infoFile}
|
|
elif [ "${isMounted}" == "0" ] && [ "${hddCandidate}" == "" ]; then
|
|
sed -i "s/^state=.*/state=noHDD/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='>=1TB'/g" ${infoFile}
|
|
fi
|
|
|
|
# wait for next check
|
|
sleep 2
|
|
|
|
done
|
|
echo "HDD/SSD connected: ${$hddCandidate}" >> $logFile
|
|
|
|
# write info for LCD
|
|
sed -i "s/^state=.*/state=system-init/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='please wait'/g" ${infoFile}
|
|
|
|
####################################
|
|
# WIFI RESTORE from HDD works with
|
|
# mem copy from datadrive inspection
|
|
####################################
|
|
|
|
# check if there is a WIFI configuration to backup or restore
|
|
/home/admin/config.scripts/internet.wifi.sh backup-restore >> $logFile
|
|
|
|
################################
|
|
# UASP FIX - second try
|
|
# when HDD gets connected later
|
|
################################
|
|
sed -i "s/^message=.*/message='checking HDD'/g" ${infoFile}
|
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh uasp-fix)
|
|
if [ "${neededReboot}" == "1" ]; then
|
|
echo "UASP FIX applied (2nd-try) ... reboot needed." >> $logFile
|
|
sudo cp ${logFile} ${logFile}.uasp
|
|
sudo sed -i "s/^state=.*/state=reboot/g" ${infoFile}
|
|
sudo shutdown -r now
|
|
sleep 100
|
|
exit 0
|
|
else
|
|
echo "No UASP FIX needed (2nd-try)." >> $logFile
|
|
fi
|
|
|
|
###################################
|
|
# WAIT LOOP: LOCALNET / INTERNET
|
|
# after HDD > can contain WIFI conf
|
|
###################################
|
|
|
|
gotLocalIP=0
|
|
until [ ${gotLocalIP} -eq 1 ]
|
|
do
|
|
|
|
# get latest network info & update raspiblitz.info
|
|
source <(/home/admin/config.scripts/internet.sh status)
|
|
sed -i "s/^localip=.*/localip='${localip}'/g" ${infoFile}
|
|
|
|
# check state of network
|
|
if [ ${dhcp} -eq 0 ]; then
|
|
# display user waiting for DHCP
|
|
sed -i "s/^state=.*/state=noDHCP/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='Waiting for DHCP'/g" ${infoFile}
|
|
elif [ ${#localip} -eq 0 ]; then
|
|
if [ ${configWifiExists} -eq 0 ]; then
|
|
# display user to connect LAN
|
|
sed -i "s/^state=.*/state=noIP-LAN/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='Connect the LAN/WAN'/g" ${infoFile}
|
|
else
|
|
# display user that wifi settings are not working
|
|
sed -i "s/^state=.*/state=noIP-WIFI/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='WIFI Settings not working'/g" ${infoFile}
|
|
fi
|
|
elif [ ${online} -eq 0 ]; then
|
|
# display user that wifi settings are not working
|
|
sed -i "s/^state=.*/state=noInternet/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='No connection to Internet'/g" ${infoFile}
|
|
else
|
|
gotLocalIP=1
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
# write info for LCD
|
|
sed -i "s/^state=.*/state=inspect-hdd/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='please wait'/g" ${infoFile}
|
|
|
|
# get fresh info about data drive to continue
|
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
|
|
|
|
# check if the HDD is auto-mounted ( auto-mounted = setup-done)
|
|
echo "HDD already part of system: $isMounted" >> $logFile
|
|
|
|
############################
|
|
############################
|
|
# WHEN SETUP IS NEEDED
|
|
############################
|
|
|
|
if [ ${isMounted} -eq 0 ]; then
|
|
|
|
# write data needed for setup process into raspiblitz.info
|
|
echo "hddCandidate='${hddCandidate}'" >> ${infoFile}
|
|
echo "hddBlocksBitcoin=${hddBlocksBitcoin}" >> ${infoFile}
|
|
echo "hddBlocksLitecoin=${hddBlocksLitecoin}" >> ${infoFile}
|
|
echo "hddGotMigrationData=${hddGotMigrationData}" >> ${infoFile}
|
|
echo ""
|
|
|
|
echo "HDD is there but not AutoMounted yet - Waiting for user Setup/Update" >> $logFile
|
|
|
|
# determine correct setup phase
|
|
infoMessage="Please Login for Setup"
|
|
setupPhase="setup"
|
|
if [ "${hddGotMigrationData}" != "" ]; then
|
|
infoMessage="Please Login for Migration"
|
|
setupPhase="migration"
|
|
elif [ "${hddRaspiData}" == "1" ]; then
|
|
# determine if this is a recovery or an update
|
|
# TODO: improve version/update detetion later
|
|
isRecovery=$(echo "${hddRaspiVersion}" | grep -c "${codeVersion}")
|
|
if [ "${isRecovery}" == "1" ]; then
|
|
infoMessage="Please Login for Recovery"
|
|
setupPhase="recovery"
|
|
else
|
|
infoMessage="Please Login for Update"
|
|
setupPhase="update"
|
|
fi
|
|
fi
|
|
|
|
# signal "WAIT LOOP: SETUP" to LCD, SSH & WEBAPI
|
|
echo "Displaying Info Message: ${infoMessage}" >> $logFile
|
|
sed -i "s/^state=.*/state=waitsetup/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='${infoMessage}'/g" ${infoFile}
|
|
sed -i "s/^setupPhase=.*/setupPhase='${setupPhase}'/g" ${infoFile}
|
|
|
|
#############################################
|
|
# WAIT LOOP: USER SETUP/UPDATE/MIGRATION
|
|
# until SSH or WEBUI setup data is available
|
|
#############################################
|
|
|
|
echo "## WAIT LOOP: USER SETUP/UPDATE/MIGRATION" >> $logFile
|
|
until [ "${state}" == "waitprovision" ]
|
|
do
|
|
|
|
# get fresh info about data drive (in case the hdd gets disconnected)
|
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
|
|
if [ "${hddCandidate}" == "" ]; then
|
|
echo "!!! WARNING !!! Lost HDD connection .. triggering reboot, to restart system-init." >> $logFile
|
|
sed -i "s/^state=.*/state=errorHDD/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='lost HDD - rebooting'/g" ${infoFile}
|
|
sudo cp ${logFile} ${logFile}.error
|
|
sleep 6
|
|
sudo shutdown -r now
|
|
sleep 100
|
|
exit 0
|
|
fi
|
|
|
|
# give the loop a little bed time
|
|
sleep 4
|
|
|
|
# check info file for updated values
|
|
# especially the state for checking loop
|
|
source ${infoFile}
|
|
|
|
done
|
|
|
|
#############################################
|
|
# PROVISION PROCESS
|
|
#############################################
|
|
|
|
# refresh data from info file
|
|
source ${infoFile}
|
|
echo "# PROVISION PROCESS with setupPhase(${setupPhase})" >> $logFile
|
|
|
|
# mark system on sd card as in setup process
|
|
echo "the provision process was started but did not finish yet" > /home/admin/provision.flag
|
|
|
|
# temp mount the HDD
|
|
echo "Temp mounting data drive ($hddCandidate)" >> $logFile
|
|
if [ "${hddFormat}" != "btrfs" ]; then
|
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh tempmount ${hddPartitionCandidate})
|
|
else
|
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh tempmount ${hddCandidate})
|
|
fi
|
|
|
|
# make sure all links between directories/drives are correct
|
|
echo "Refreshing links between directories/drives .." >> $logFile
|
|
sudo /home/admin/config.scripts/blitz.datadrive.sh link
|
|
|
|
# copy over the raspiblitz.conf created from setup to HDD
|
|
configExists=$(ls /mnt/hdd/raspiblitz.conf 2>/dev/null | grep -c "raspiblitz.conf")
|
|
if [ "${configExists}" != "1" ]; then
|
|
sudo cp /var/cache/raspiblitz/temp/raspiblitz.conf /mnt/hdd/raspiblitz.conf
|
|
fi
|
|
|
|
# kick-off provision process
|
|
sed -i "s/^state=.*/state=provision/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='Starting Provision'/g" ${infoFile}
|
|
|
|
# load setup data
|
|
source ${setupFile} 2>$logFile
|
|
|
|
# make sure basic info id in raspiblitz.info
|
|
sudo sed -i "s/^network=.*/network=${network}/g" ${infoFile}
|
|
sudo sed -i "s/^chain=.*/chain=${chain}/g" ${infoFile}
|
|
sudo sed -i "s/^lightning=.*/lightning=${lightning}/g" ${infoFile}
|
|
|
|
###################################
|
|
# Set Password A (in all cases)
|
|
|
|
if [ "${passwordA}" == "" ]; then
|
|
sed -i "s/^state=.*/state=error/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='config: missing passwordA'/g" ${infoFile}
|
|
echo "FAIL see ${logFile}"
|
|
echo "FAIL: missing passwordA in (${setupFile})!" >> ${logFile}
|
|
exit 1
|
|
fi
|
|
|
|
echo "SETTING PASSWORD A" >> ${logFile}
|
|
sudo /home/admin/config.scripts/blitz.setpassword.sh a "${passwordA}" >> ${logFile}
|
|
|
|
# if setup - run provision setup first
|
|
if [ "${setupPhase}" == "setup" ]; then
|
|
echo "Calling _provision.setup.sh for basic setup tasks .." >> $logFile
|
|
sed -i "s/^message=.*/message='Provision Setup'/g" ${infoFile}
|
|
sudo /home/admin/_provision.setup.sh
|
|
if [ "$?" != "0" ]; then
|
|
echo "EXIT _provision.setup.sh BECAUSE OF ERROR STATE ($?)" >> $logFile
|
|
echo "This can also happen if _provision.setup.sh has syntax errros" >> $logFile
|
|
sed -i "s/^state=.*/state='error'/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='_provision.setup.sh fail'/g" ${infoFile}
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# if migration - run the migration provision first
|
|
if [ "${setupPhase}" == "migration" ]; then
|
|
echo "Calling _provision.migration.sh for possible migrations .." >> $logFile
|
|
sed -i "s/^message=.*/message='Provision migration'/g" ${infoFile}
|
|
sudo /home/admin/_provision.migration.sh
|
|
if [ "$?" != "0" ]; then
|
|
echo "EXIT _provision.migration.sh BECAUSE OF ERROR STATE ($?)" >> $logFile
|
|
echo "This can also happen if _provision.migration.sh has syntax errros" >> $logFile
|
|
sed -i "s/^state=.*/state='error'/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='_provision.migration.sh fail'/g" ${infoFile}
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# if update/recovery/migration
|
|
if [ "${setupPhase}" == "update" ] || [ "${setupPhase}" == "recovery" ] || [ "${setupPhase}" == "migration" ]; then
|
|
echo "Calling _provision.update.sh .." >> $logFile
|
|
sed -i "s/^message=.*/message='Provision Update/Recovery/Migration'/g" ${infoFile}
|
|
sudo /home/admin/_provision.update.sh
|
|
if [ "$?" != "0" ]; then
|
|
echo "EXIT _provision.update.sh BECAUSE OF ERROR STATE ($?)" >> $logFile
|
|
echo "This can also happen if _provision.update.sh has syntax errros" >> $logFile
|
|
sed -i "s/^state=.*/state='error'/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='_provision.update.sh fail'/g" ${infoFile}
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# finalize provisioning
|
|
echo "Calling _bootstrap.provision.sh for general system provisioning (${setupPhase}) .." >> $logFile
|
|
sed -i "s/^message=.*/message='Provision Basics'/g" ${infoFile}
|
|
sudo /home/admin/_provision_.sh
|
|
if [ "$?" != "0" ]; then
|
|
echo "EXIT _provision_.sh BECAUSE OF ERROR STATE" >> $logFile
|
|
echo "This can also happen if _provision_.sh has syntax errros" >> $logFile
|
|
sed -i "s/^state=.*/state='error'/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='_provision_.sh fail'/g" ${infoFile}
|
|
exit 1
|
|
fi
|
|
|
|
# unlock lnd if needed
|
|
source ${setupFile}
|
|
echo "checking Unlock ..." >> $logFile
|
|
if [ "${lightning}" == "lnd" ] && [ "${passwordC}" != "" ]; then
|
|
echo "Unlock LND at end of provision with temp stored password C" >> $logFile
|
|
/home/admin/config.scripts/lnd.unlock.sh unlock "${passwordC}" >> ${logFile}
|
|
sleep 3
|
|
else
|
|
echo "No lightning unlock (${lightning}) or password C temp stored" >> $logFile
|
|
fi
|
|
|
|
# mark provision process done
|
|
sed -i "s/^message=.*/message='Provision Done'/g" ${infoFile}
|
|
|
|
# wait until syncProgress is available (neeed for final dialogs)
|
|
while [ "${syncProgress}" == "" ]
|
|
do
|
|
echo "# Waiting for blockchain sync progress info ..." >> $logFile
|
|
source <(sudo /home/admin/config.scripts/blitz.statusscan.sh)
|
|
sed -i "s/^state=.*/state=waitsync/g" ${infoFile}
|
|
sleep 2
|
|
done
|
|
|
|
###################################################
|
|
# WAIT LOOP: AFTER FRESH SETUP, MIGRATION
|
|
# successfull update & recover can skip this
|
|
###################################################
|
|
|
|
if [ "${setupPhase}" == "setup" ] || [ "${setupPhase}" == "migration" ]; then
|
|
echo "# Go into WAIT LOOP for final setup dialog ..." >> $logFile
|
|
sed -i "s/^state=.*/state=waitfinal/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='Setup Done'/g" ${infoFile}
|
|
else
|
|
echo "# Skip WAIT LOOP boot directly into main menu ..." >> $logFile
|
|
sed -i "s/^state=.*/state=ready/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='Setup Done'/g" ${infoFile}
|
|
fi
|
|
|
|
source ${infoFile}
|
|
echo "WAIT LOOP: FINAL SETUP .. see controlFinalDialog.sh" >> $logFile
|
|
until [ "${state}" == "ready" ]
|
|
do
|
|
|
|
# get latest network info & update raspiblitz.info (in case network changes)
|
|
source <(/home/admin/config.scripts/internet.sh status)
|
|
sed -i "s/^localip=.*/localip='${localip}'/g" ${infoFile}
|
|
|
|
# give the loop a little bed time
|
|
sleep 4
|
|
|
|
# check info file for updated values
|
|
# especially the state for checking loop
|
|
source ${infoFile}
|
|
|
|
done
|
|
echo "WAIT LOOP: DONE" >> $logFile
|
|
|
|
########################################
|
|
# AFTER FINAL SETUP TASKS
|
|
|
|
# make sure for future starts that blockchain service gets started after boostrap
|
|
sed -i "s/^Wants=.*/Wants=bootstrap.service/g" /etc/systemd/system/${network}d.service
|
|
sed -i "s/^After=.*/After=network.target/g" /etc/systemd/system/${network}d.service
|
|
|
|
# delete provision in progress flag
|
|
sudo rm /home/admin/provision.flag
|
|
|
|
# delete setup data from RAM
|
|
sudo rm ${setupFile}
|
|
|
|
# signal that setup phas is over
|
|
sed -i "s/^setupPhase=.*/setupPhase='done'/g" ${infoFile}
|
|
|
|
else
|
|
|
|
############################
|
|
############################
|
|
# NORMAL START BOOTSTRAP (not executed after setup)
|
|
# Blockchain & Lightning not running
|
|
############################
|
|
|
|
######################################################################
|
|
# MAKE SURE LND RPC/REST ports are standard & open to all connections
|
|
######################################################################
|
|
sudo sed -i "s/^rpclisten=.*/rpclisten=0.0.0.0:10009/g" /mnt/hdd/lnd/lnd.conf
|
|
sudo sed -i "s/^restlisten=.*/restlisten=0.0.0.0:8080/g" /mnt/hdd/lnd/lnd.conf
|
|
|
|
#################################
|
|
# FIX BLOCKCHAINDATA OWNER (just in case)
|
|
# https://github.com/rootzoll/raspiblitz/issues/239#issuecomment-450887567
|
|
#################################
|
|
sudo chown bitcoin:bitcoin -R /mnt/hdd/bitcoin 2>/dev/null
|
|
|
|
#################################
|
|
# FIX BLOCKING FILES (just in case)
|
|
# https://github.com/rootzoll/raspiblitz/issues/1901#issue-774279088
|
|
# https://github.com/rootzoll/raspiblitz/issues/1836#issue-755342375
|
|
sudo rm -f /mnt/hdd/bitcoin/bitcoind.pid 2>/dev/null
|
|
sudo rm -f /mnt/hdd/bitcoin/.lock 2>/dev/null
|
|
|
|
################################
|
|
# DELETE LOG & LOCK FILES
|
|
################################
|
|
# LND and Blockchain Errors will be still in systemd journals
|
|
|
|
# /mnt/hdd/bitcoin/debug.log
|
|
sudo rm /mnt/hdd/${network}/debug.log 2>/dev/null
|
|
# /mnt/hdd/lnd/logs/bitcoin/mainnet/lnd.log
|
|
sudo rm /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2>/dev/null
|
|
# https://github.com/rootzoll/raspiblitz/issues/1700
|
|
sudo rm /mnt/storage/app-storage/electrs/db/mainnet/LOCK 2>/dev/null
|
|
|
|
fi
|
|
|
|
##############################
|
|
##############################
|
|
# BOOSTRAP IN EVERY SITUATION
|
|
##############################
|
|
|
|
sed -i "s/^setupPhase=.*/setupPhase='starting'/g" ${infoFile}
|
|
|
|
# if a WIFI config exists backup to HDD
|
|
configWifiExists=$(sudo cat /etc/wpa_supplicant/wpa_supplicant.conf 2>/dev/null| grep -c "network=")
|
|
if [ ${configWifiExists} -eq 1 ]; then
|
|
echo "Making Backup Copy of WIFI config to HDD" >> $logFile
|
|
sudo cp /etc/wpa_supplicant/wpa_supplicant.conf /mnt/hdd/app-data/wpa_supplicant.conf
|
|
fi
|
|
|
|
# make sure lndAddress & lndPort exist in cofigfile
|
|
valueExists=$(cat ${configFile} | grep -c 'lndPort=')
|
|
if [ ${valueExists} -eq 0 ]; then
|
|
lndPort=$(sudo cat /mnt/hdd/lnd/lnd.conf | grep "^listen=*" | cut -f2 -d':')
|
|
if [ ${#lndPort} -eq 0 ]; then
|
|
lndPort="9735"
|
|
fi
|
|
echo "lndPort='${lndPort}'" >> ${configFile}
|
|
fi
|
|
valueExists=$(cat ${configFile} | grep -c 'lndAddress=')
|
|
if [ ${valueExists} -eq 0 ]; then
|
|
echo "lndAddress=''" >> ${configFile}
|
|
fi
|
|
|
|
# load data from config file fresh
|
|
echo "load configfile data" >> $logFile
|
|
source ${configFile}
|
|
|
|
# update public IP on boot - set to domain if available
|
|
/home/admin/config.scripts/internet.sh update-publicip ${lndAddress}
|
|
|
|
#################################
|
|
# MAKE SURE USERS HAVE LATEST LND CREDENTIALS
|
|
#################################
|
|
source ${configFile}
|
|
if [ ${#network} -gt 0 ] && [ ${#chain} -gt 0 ]; then
|
|
|
|
echo "running LND users credentials update" >> $logFile
|
|
sudo /home/admin/config.scripts/lnd.credentials.sh sync >> $logFile
|
|
|
|
else
|
|
echo "skipping LND credientials sync" >> $logFile
|
|
fi
|
|
|
|
################################
|
|
# MOUNT BACKUP DRIVE
|
|
# if "localBackupDeviceUUID" is set in
|
|
# raspiblitz.conf mount it on boot
|
|
################################
|
|
source ${configFile}
|
|
echo "Checking if additional backup device is configured .. (${localBackupDeviceUUID})" >> $logFile
|
|
if [ "${localBackupDeviceUUID}" != "" ] && [ "${localBackupDeviceUUID}" != "off" ]; then
|
|
echo "Yes - Mounting BackupDrive: ${localBackupDeviceUUID}" >> $logFile
|
|
sudo /home/admin/config.scripts/blitz.backupdevice.sh mount >> $logFile
|
|
else
|
|
echo "No additional backup device was configured." >> $logFile
|
|
fi
|
|
|
|
#####################################
|
|
# CLEAN HDD TEMP
|
|
#####################################
|
|
|
|
echo "CLEANING TEMP DRIVE/FOLDER" >> $logFile
|
|
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh clean temp)
|
|
if [ ${#error} -gt 0 ]; then
|
|
echo "FAIL: ${error}" >> $logFile
|
|
else
|
|
echo "OK: Temp cleaned" >> $logFile
|
|
fi
|
|
|
|
###############################
|
|
# RAID data check (BRTFS)
|
|
###############################
|
|
# see https://github.com/rootzoll/raspiblitz/issues/360#issuecomment-467698260
|
|
|
|
if [ ${isRaid} -eq 1 ]; then
|
|
echo "TRIGGERING BTRFS RAID DATA CHECK ..."
|
|
echo "Check status with: sudo btrfs scrub status /mnt/hdd/"
|
|
sudo btrfs scrub start /mnt/hdd/
|
|
fi
|
|
|
|
######################################
|
|
# PREPARE SUBSCRIPTIONS DATA DIRECTORY
|
|
######################################
|
|
|
|
if [ -d "/mnt/hdd/app-data/subscrptions" ]; then
|
|
echo "OK: subscription data directory exists"
|
|
else
|
|
echo "CREATE: subscription data directory"
|
|
sudo mkdir /mnt/hdd/app-data/subscriptions
|
|
sudo chown admin:admin /mnt/hdd/app-data/subscriptions
|
|
fi
|
|
|
|
# mark that node is ready now
|
|
sed -i "s/^state=.*/state=ready/g" ${infoFile}
|
|
sed -i "s/^message=.*/message='Node Running'/g" ${infoFile}
|
|
|
|
# make sure that bitcoin service is active
|
|
sudo systemctl enable ${network}d
|
|
|
|
sed -i "s/^setupPhase=.*/setupPhase='done'/g" ${infoFile}
|
|
sed -i "s/^state=.*/state=ready/g" ${infoFile}
|
|
|
|
echo "DONE BOOTSTRAP" >> $logFile
|
|
exit 0
|