2018-12-10 22:28:02 +01:00
source /mnt/hdd/raspiblitz.conf
2018-08-24 00:11:33 +02:00
2018-08-02 03:50:31 +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' )
2018-12-11 04:53:22 +01:00
action = "Rescanning"
2018-08-24 13:40:15 +02:00
# 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' )
2018-12-11 04:53:22 +01:00
action = "Catching-Up"
2018-08-24 13:40:15 +02:00
fi
2018-12-11 04:50:25 +01:00
# 3) Third try the "LNWL: Filtering block" - thats the usual on later starts
if [ ${# item } -eq 0 ] ; then
item = $( sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${ network } /${ chain } net/lnd.log | grep "LNWL: Filtering block" | tail -n1 | cut -d ' ' -f7 | tr -dc '0-9' )
2018-12-11 04:53:22 +01:00
action = "Filtering"
2018-12-11 04:50:25 +01:00
fi
# if no progress info
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-12-11 00:20:51 +01:00
progress = $( echo " ${ progress } *100 " | bc)
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-12-11 00:20:51 +01: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-12-11 00:20:51 +01: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
2018-12-11 04:53:22 +01:00
infoStr = $( echo " Lightning ${ action } 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-12-11 04:53:22 +01:00
infoStr = $( echo " Lightning ${ action } 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-12-10 22:28:02 +01:00
dialog --title " ${ network } / ${ chain } " --backtitle " RaspiBlitz ( ${ hostname } ) " --infobox " ${ infoStr } " ${ heigh } ${ width }