raspiblitz/home.admin/80scanLND.sh

63 lines
2.6 KiB
Bash
Raw Normal View History

2018-12-06 14:36:02 +01:00
source /home/admin/raspiblitz.info
source /mnt/hdd/raspiblitz.conf 2>/dev/null
2018-08-24 00:11:33 +02:00
### USER PI AUTOSTART (LCD Display)
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
2018-07-17 13:12:03 +02:00
# parse the actual scanned height progress from LND logs
item=0
2018-08-24 00:43:05 +02:00
blockchaininfo=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo)
chain="$(echo "${blockchaininfo}" | jq -r '.chain')"
2018-08-24 13:40:15 +02:00
## TRY to get the actual progress height of scanning
# 1) First try the "Rescanned through block" - it seems to happen if it restarts
item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "Rescanned through block" | tail -n1 | cut -d ']' -f2 | cut -d '(' -f2 | tr -dc '0-9')
# 2) Second try the "Caught up to height" - thats the usual on first scan start
if [ ${#item} -eq 0 ]; then
item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "Caught up to height" | tail -n1 | cut -d ']' -f2 | tr -dc '0-9')
fi
# TODO next fallback try later here if necessary
2018-08-24 04:49:04 +02:00
if [ ${#item} -eq 0 ]; then
item="?"
2018-07-17 13:12:03 +02:00
fi
2018-08-24 13:40:15 +02:00
2018-07-17 13:12:03 +02:00
# get total number of blocks
2018-08-24 00:43:05 +02:00
total=$(echo "${blockchaininfo}" | jq -r '.blocks')
2018-08-24 04:49:04 +02:00
# put scanstate
scanstate="${item}/${total}"
2018-07-17 13:12:03 +02:00
2018-08-24 04:49:04 +02:00
# get blockchain sync progress
progress="$(echo "${blockchaininfo}" | jq -r '.verificationprogress')"
2018-07-17 13:12:03 +02:00
2018-08-02 18:45:09 +02:00
# check if blockchain is still syncing
2018-08-24 00:31:18 +02:00
heigh=6
2018-08-24 03:49:29 +02:00
width=44
2018-08-24 03:43:06 +02:00
isInitialChainSync=$(echo "${blockchaininfo}" | grep 'initialblockdownload' | grep "true" -c)
isWaitingBlockchain=$( sudo -u bitcoin tail -n 2 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log | grep "Waiting for chain backend to finish sync" -c )
2018-08-02 18:45:09 +02:00
if [ ${isWaitingBlockchain} -gt 0 ]; then
2018-08-24 03:43:06 +02:00
isInitialChainSync=1
fi
if [ ${isInitialChainSync} -gt 0 ]; then
2018-08-24 00:43:05 +02:00
heigh=7
2018-08-24 03:49:29 +02:00
infoStr=" Waiting for final Blockchain Sync\n Progress: ${progress}\n Please wait - this can take some time.\n ssh admin@${localip}\n Password A"
2018-08-24 00:31:18 +02:00
if [ "$USER" = "admin" ]; then
2018-08-24 00:43:05 +02:00
heigh=6
2018-08-24 00:54:10 +02:00
width=53
2018-08-24 03:49:29 +02:00
infoStr=$(echo " Waiting for final Blockchain Sync\n Progress: ${progress}\n Please wait - this can take some long time.\n Its OK to close terminal and ssh back in later.")
2018-08-24 00:31:18 +02:00
fi
else
2018-08-24 04:53:56 +02:00
heigh=7
infoStr=$(echo " Lightning Rescanning Blockchain\n Progress: ${scanstate}\n Please wait - this can take some time\n ssh admin@${localip}\n Password A")
2018-08-24 00:31:18 +02:00
if [ "$USER" = "admin" ]; then
2018-08-24 04:53:56 +02:00
heigh=6
2018-08-24 00:54:10 +02:00
width=53
2018-08-24 04:53:56 +02:00
infoStr=$(echo " Lightning Rescanning Blockchain\n Progress: ${scanstate}\n Please wait - this can take some long time.\n Its OK to close terminal and ssh back in later.")
2018-08-24 00:31:18 +02:00
fi
2018-08-02 18:45:09 +02:00
fi
2018-07-17 13:12:03 +02:00
# display progress to user
2018-08-24 00:43:05 +02:00
sleep 3
2018-08-24 00:54:10 +02:00
dialog --title " ${network} / ${chain} " --backtitle "RaspiBlitz (${name})" --infobox "${infoStr}" ${heigh} ${width}