2019-02-02 23:49:04 +01:00
#!/bin/bash
source /home/admin/raspiblitz.info
2019-02-05 18:24:33 +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-12-25 12:19:03 +01:00
online = 1
2018-08-24 04:49:04 +02:00
if [ ${# item } -eq 0 ] ; then
item = "?"
2018-12-25 12:11:36 +01:00
# check if offline
# https://en.wikipedia.org/wiki/1.1.1.1
online = $( ping 1.1.1.1 -c 1 -W 2 | grep -c '1 received' )
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
2018-12-25 12:20:02 +01:00
if [ ${ online } -eq 0 ] ; then
2018-12-25 12:11:36 +01:00
heigh = 7
width = 44
infoStr = $( echo " Waiting INTERNET CONNECTION\n RaspiBlitz cannot ping 1.1.1.1\n Local IP is ${ localip } \n Please check cables and router. " )
elif [ ${ 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-23 13:37:15 +01:00
# check if wallet has any UTXO
# reason see: https://github.com/lightningnetwork/lnd/issues/2326
2018-12-23 14:20:13 +01:00
txlines = $( sudo -u bitcoin lncli listchaintxns 2>/dev/null | wc -l)
2018-12-23 13:37:15 +01:00
# has just 4 lines if empty
if [ ${ txlines } -eq 4 ] ; then
2018-12-23 20:14:46 +01:00
infoStr = $( echo " Lightning ${ action } Blockchain\n Progress: ${ scanstate } \n re-rescan every start until funding\n ssh admin@ ${ localip } \n Password A " )
2018-12-23 13:37:15 +01:00
else
infoStr = $( echo " Lightning ${ action } Blockchain\n Progress: ${ scanstate } \n Please wait - this can take some time\n ssh admin@ ${ localip } \n Password A " )
if [ " $USER " = "admin" ] ; then
heigh = 6
width = 53
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. " )
fi
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 }