(00raspiblitz.sh): fix typos; use -z for empty check; condensed some code (#4665)

This commit is contained in:
Christoph Stenglein
2024-09-01 15:32:27 +02:00
committed by GitHub
parent 5a742b12a3
commit 3f3660dfed

View File

@@ -15,7 +15,7 @@ infoFile="/home/admin/raspiblitz.info"
source ${infoFile} source ${infoFile}
# check that basic system phase/state information is available # check that basic system phase/state information is available
if [ "${setupPhase}" == "" ] || [ "${state}" == "" ]; then if [ -z "${setupPhase}" ] || [ -z "${state}" ]; then
echo "setupPhase(${setupPhase}) state(${state})" echo "setupPhase(${setupPhase}) state(${state})"
echo "FAIL: ${infoFile} does not exist or missing state." echo "FAIL: ${infoFile} does not exist or missing state."
echo "Check logs & bootstrap.service for errors and report to devs." echo "Check logs & bootstrap.service for errors and report to devs."
@@ -26,10 +26,8 @@ fi
if [ "${state}" = "stop" ]; then if [ "${state}" = "stop" ]; then
echo "OK ready for manual provision - run 'release' at the end." echo "OK ready for manual provision - run 'release' at the end."
exit exit
fi
# special state: copysource # special state: copysource
if [ "${state}" = "copysource" ]; then elif [ "${state}" = "copysource" ]; then
echo "***********************************************************" echo "***********************************************************"
echo "INFO: You lost connection during copying the blockchain" echo "INFO: You lost connection during copying the blockchain"
echo "You have the following options:" echo "You have the following options:"
@@ -42,7 +40,7 @@ fi
# special state: copytarget # special state: copytarget
source <(/home/admin/config.scripts/blitz.copychain.sh status) source <(/home/admin/config.scripts/blitz.copychain.sh status)
if [ "${copyInProgress}" = "1" ]; then if [ "${copyInProgress}" = "1" ]; then
echo "Detected interrupted COPY blochain process ..." echo "Detected interrupted COPY blockchain process ..."
/home/admin/config.scripts/blitz.copychain.sh target /home/admin/config.scripts/blitz.copychain.sh target
exit exit
fi fi
@@ -58,43 +56,30 @@ quit() {
echo "SIGINT or SIGTERM received, exiting..." echo "SIGINT or SIGTERM received, exiting..."
kill -9 $$ kill -9 $$
} }
trap quit INT trap quit INT TERM
trap quit TERM
echo "# start ssh menu loop" echo "# start ssh menu loop"
# put some values on higher scan rate for 10 minute # put some values on higher scan rate for 10 minute
/home/admin/_cache.sh focus ln_default_ready 2 600 >/dev/null for key in ln_default_ready ln_default_locked btc_default_synced; do
/home/admin/_cache.sh focus ln_default_locked 2 600 >/dev/null /home/admin/_cache.sh focus $key 2 600 >/dev/null
/home/admin/_cache.sh focus btc_default_synced 2 600 >/dev/null done
echo "# starting ssh menu loop ... " echo "# starting ssh menu loop ... "
exitMenuLoop=0 exitMenuLoop=0
doneIBD=0 doneIBD=0
while [ ${exitMenuLoop} -eq 0 ] while [ ${exitMenuLoop} -eq 0 ]; do
do
##################################### #####################################
# Access fresh system info on every loop # Access fresh system info on every loop
# refresh system state information # refresh system state information
source <(/home/admin/_cache.sh get \ source <(/home/admin/_cache.sh get \
systemscan_runtime \ systemscan_runtime state setupPhase btc_default_synced \
state \ ln_default_sync_chain ln_default_locked ln_default_ready \
setupPhase \ ln_default_sync_initial_done message network chain \
btc_default_synced \ lightning internet_localip)
ln_default_sync_chain \
ln_default_locked \
ln_default_ready \
ln_default_sync_initial_done \
message \
network \
chain \
lightning \
internet_localip
)
# background.scan is not ready yet # background.scan is not ready yet
if [ "${systemscan_runtime}" == "" ]; then if [ -z "${systemscan_runtime}" ]; then
echo "# background.scan not ready yet ... (please wait)" echo "# background.scan not ready yet ... (please wait)"
sleep 4 sleep 4
continue continue
@@ -108,18 +93,14 @@ do
# Wallet Unlock # Wallet Unlock
if [ "${state}" == "ready" ] && [ "${setupPhase}" == "done" ] && [ "${ln_default_locked}" == "1" ]; then if [ "${state}" == "ready" ] && [ "${setupPhase}" == "done" ] && [ "${ln_default_locked}" == "1" ]; then
# unlock lnd # unlock lnd
if [ "${lightning}" == "lnd" ]; then if [ "${lightning}" == "lnd" ]; then
/home/admin/config.scripts/lnd.unlock.sh /home/admin/config.scripts/lnd.unlock.sh
fi
# unlock c-lightning # unlock c-lightning
if [ "${lightning}" == "cl" ]; then elif [ "${lightning}" == "cl" ]; then
/home/admin/config.scripts/cl.hsmtool.sh unlock ${chain}net /home/admin/config.scripts/cl.hsmtool.sh unlock ${chain}net
sleep 5 sleep 5
fi fi
fi fi
##################################### #####################################
@@ -152,7 +133,7 @@ do
# exit loop/script in case if system shutting down # exit loop/script in case if system shutting down
if [ "${state}" == "reboot" ] || [ "${state}" == "shutdown" ]; then if [ "${state}" == "reboot" ] || [ "${state}" == "shutdown" ]; then
dialog --pause " Prepare Reboot ..." 8 58 4 dialog --pause " Prepare ${state} ..." 8 58 4
clear clear
echo "***********************************************************" echo "***********************************************************"
echo "RaspiBlitz going to ${state}" echo "RaspiBlitz going to ${state}"
@@ -171,24 +152,10 @@ do
# MAKE SURE BLOCKCHAIN/LN IS SYNC # MAKE SURE BLOCKCHAIN/LN IS SYNC
##################################### #####################################
if [ "${setupPhase}" == "done" ] && [ "${state}" == "ready" ]; then if [ "${setupPhase}" == "done" ] && [ "${state}" == "ready" ]; then
if [ "${lightning}" = "cl" ]; then if [ "${btc_default_synced}" != "1" ] || [ "${ln_default_ready}" == "0" ] || [ "${ln_default_sync_chain}" == "0" ] || [ "${ln_default_sync_initial_done}" == "0" ]; then
if [ "${btc_default_synced}" != "1" ] || [ "${ln_default_ready}" == "0" ] || [ "${ln_default_sync_chain}" == "0" ]; then /home/admin/setup.scripts/eventBlockchainSync.sh ssh
/home/admin/setup.scripts/eventBlockchainSync.sh ssh sleep 3
sleep 3 continue
continue
fi
elif [ "${lightning}" = "lnd" ]; then
if [ "${btc_default_synced}" != "1" ] || [ "${ln_default_ready}" == "0" ] || [ "${ln_default_sync_chain}" == "0" ] || [ "${ln_default_sync_initial_done}" == "0" ]; then
/home/admin/setup.scripts/eventBlockchainSync.sh ssh
sleep 3
continue
fi
else
if [ "${btc_default_synced}" != "1" ]; then
/home/admin/setup.scripts/eventBlockchainSync.sh ssh
sleep 3
continue
fi
fi fi
fi fi
@@ -202,25 +169,23 @@ do
# check if there is a channel.backup to activate # check if there is a channel.backup to activate
gotSCB=$(ls /home/admin/channel.backup 2>/dev/null | grep -c 'channel.backup') gotSCB=$(ls /home/admin/channel.backup 2>/dev/null | grep -c 'channel.backup')
if [ "${gotSCB}" == "1" ]; then if [ "${gotSCB}" == "1" ]; then
clear clear
echo echo
echo "*** channel.backup Recovery ***" echo "*** channel.backup Recovery ***"
echo "Running ... (please wait)" echo "Running ... (please wait)"
lncli --chain=${network} restorechanbackup --multi_file=/home/admin/channel.backup 2>/home/admin/.error.tmp lncli --chain=${network} restorechanbackup --multi_file=/home/admin/channel.backup 2>/home/admin/.error.tmp
error=`cat /home/admin/.error.tmp` error=$(cat /home/admin/.error.tmp)
rm /home/admin/.error.tmp 2>/dev/null rm /home/admin/.error.tmp 2>/dev/null
if [ ${#error} -gt 0 ]; then if [ ${#error} -gt 0 ]; then
# output error message # output error message
echo "" echo ""
echo "# FAIL # SOMETHING WENT WRONG:" echo "# FAIL # SOMETHING WENT WRONG:"
echo "${error}" echo "${error}"
# check if its possible to give background info on the error # check if its possible to give background info on the error
notMachtingSeed=$(echo $error | grep -c 'unable to unpack chan backup') notMatchingSeed=$(echo $error | grep -c 'unable to unpack chan backup')
if [ ${notMachtingSeed} -gt 0 ]; then if [ ${notMatchingSeed} -gt 0 ]; then
echo "--> ERROR BACKGROUND:" echo "--> ERROR BACKGROUND:"
echo "The WORD SEED is not matching the channel.backup file." echo "The WORD SEED is not matching the channel.backup file."
echo "Either there was an error in the word seed list or" echo "Either there was an error in the word seed list or"
@@ -260,14 +225,15 @@ MAINMENU > REPAIR > REPAIR-LND > RETRYSCB
if [ "${setupPhase}" == "done" ] && [ "${state}" == "ready" ]; then if [ "${setupPhase}" == "done" ] && [ "${state}" == "ready" ]; then
# MAIN MENU # MAIN MENU
# remove higher scan rate on values # remove higher scan rate on values
/home/admin/_cache.sh focus ln_default_locked -1 for key in ln_default_locked btc_default_synced; do
/home/admin/_cache.sh focus btc_default_synced -1 /home/admin/_cache.sh focus $key -1
done
echo "# 00mainMenu.sh" echo "# 00mainMenu.sh"
/home/admin/00mainMenu.sh /home/admin/00mainMenu.sh
# use the exit code from main menu as signal if menu loop should exited # use the exit code from main menu as signal if menu loop should exited
# 0 = continue loop / everything else = break loop and exit to terminal # 0 = continue loop / everything else = break loop and exit to terminal
exitMenuLoop=$? exitMenuLoop=$?
if [ "${exitMenuLoop}" != "0" ]; then break; fi [ "${exitMenuLoop}" != "0" ] && break
fi fi
##################################### #####################################
@@ -307,9 +273,7 @@ MAINMENU > REPAIR > REPAIR-LND > RETRYSCB
# every other state just push as event to SSH frontend # every other state just push as event to SSH frontend
/home/admin/setup.scripts/eventInfoWait.sh "${state}" "${message}" /home/admin/setup.scripts/eventInfoWait.sh "${state}" "${message}"
fi fi
fi fi
done done
echo "# menu loop received exit code ${exitMenuLoop} --> exit to terminal" echo "# menu loop received exit code ${exitMenuLoop} --> exit to terminal"
@@ -350,12 +314,8 @@ echo "* Here be dragons .. have fun :)"
echo "***********************************" echo "***********************************"
if [ "${setupPhase}" == "done" ]; then if [ "${setupPhase}" == "done" ]; then
echo "Bitcoin command line options: ${network}-cli help" echo "Bitcoin command line options: ${network}-cli help"
if [ "${lightning}" == "lnd" ]; then [ "${lightning}" == "lnd" ] && echo "LND command line options: lncli -h"
echo "LND command line options: lncli -h" [ "${lightning}" == "cl" ] && echo "Core Lightning command line options: lightning-cli help"
fi
if [ "${lightning}" == "cl" ]; then
echo "Core Lightning command line options: lightning-cli help"
fi
else else
echo "Your setup is not finished." echo "Your setup is not finished."
echo "For setup logs: cat raspiblitz.log" echo "For setup logs: cat raspiblitz.log"