Christian Rotzoll
6 years ago
2 changed files with 206 additions and 0 deletions
@ -0,0 +1,101 @@ |
|||
#!/bin/bash |
|||
|
|||
source /home/admin/raspiblitz.info |
|||
source /mnt/hdd/raspiblitz.conf |
|||
|
|||
### USER PI AUTOSTART (LCD Display) |
|||
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') |
|||
|
|||
# parse the actual scanned height progress from LND logs |
|||
item=0 |
|||
blockchaininfo=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo) |
|||
chain="$(echo "${blockchaininfo}" | jq -r '.chain')" |
|||
|
|||
## 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') |
|||
action="Rescanning" |
|||
|
|||
# 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') |
|||
action="Catching-Up" |
|||
fi |
|||
|
|||
# 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') |
|||
action="Filtering" |
|||
fi |
|||
|
|||
# if no progress info |
|||
online=1 |
|||
if [ ${#item} -eq 0 ]; then |
|||
item="?" |
|||
|
|||
# check if offline |
|||
online=$(ping 1.0.0.1 -c 1 -W 2 | grep -c '1 received') |
|||
if [ ${online} -eq 0 ]; then |
|||
# re-test with other server |
|||
online=$(ping 8.8.8.8 -c 1 -W 2 | grep -c '1 received') |
|||
fi |
|||
if [ ${online} -eq 0 ]; then |
|||
# re-test with other server |
|||
online=$(ping 208.67.222.222 -c 1 -W 2 | grep -c '1 received') |
|||
fi |
|||
|
|||
fi |
|||
|
|||
# get total number of blocks |
|||
total=$(echo "${blockchaininfo}" | jq -r '.blocks') |
|||
# put scanstate |
|||
scanstate="${item}/${total}" |
|||
|
|||
# get blockchain sync progress |
|||
progress="$(echo "${blockchaininfo}" | jq -r '.verificationprogress')" |
|||
#progress=$(echo "${progress}*100" | bc) |
|||
progress=$(echo $progress | awk '{printf( "%.2f%%", 100 * $1)}') |
|||
|
|||
# check if blockchain is still syncing |
|||
heigh=6 |
|||
width=44 |
|||
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 ) |
|||
if [ ${isWaitingBlockchain} -gt 0 ]; then |
|||
isInitialChainSync=1 |
|||
fi |
|||
if [ ${online} -eq 0 ]; then |
|||
heigh=7 |
|||
width=44 |
|||
infoStr=$(echo " Waiting INTERNET CONNECTION\n RaspiBlitz cannot ping 1.0.0.1\n Local IP is ${localip}\n Please check cables and router.") |
|||
elif [ ${isInitialChainSync} -gt 0 ]; then |
|||
heigh=7 |
|||
infoStr=" Waiting for final Blockchain Sync\n Progress: ${progress} \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 " 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.") |
|||
fi |
|||
else |
|||
heigh=7 |
|||
# check if wallet has any UTXO |
|||
# reason see: https://github.com/lightningnetwork/lnd/issues/2326 |
|||
txlines=$(sudo -u bitcoin lncli listchaintxns 2>/dev/null | wc -l) |
|||
# has just 4 lines if empty |
|||
if [ ${txlines} -eq 4 ]; then |
|||
infoStr=$(echo " Lightning ${action} Blockchain\n Progress: ${scanstate}\n re-rescan every start until funding\n ssh admin@${localip}\n Password A") |
|||
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 |
|||
fi |
|||
fi |
|||
|
|||
# display progress to user |
|||
sleep 3 |
|||
temp=$(echo "scale=1; $(cat /sys/class/thermal/thermal_zone0/temp)/1000" | bc) |
|||
dialog --title " ${network} / ${chain} " --backtitle "RaspiBlitz (${hostname}) CPU: ${temp}°C" --infobox "${infoStr}" ${heigh} ${width} |
@ -0,0 +1,105 @@ |
|||
#!/bin/bash |
|||
|
|||
source /home/admin/raspiblitz.info |
|||
source /mnt/hdd/raspiblitz.conf |
|||
|
|||
# command info |
|||
if [ "$1" = "-h" ] || [ "$1" = "-help" ]; then |
|||
echo "# script to scan the state of the system after setup" |
|||
exit 1 |
|||
fi |
|||
|
|||
# measure time of scan |
|||
startTime=$(date +%s) |
|||
|
|||
# localIP |
|||
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') |
|||
echo "localIP='${localip}'" |
|||
|
|||
# is bitcoind running |
|||
bitcoinRunning=$(systemctl status ${network}d.service 2>/dev/null | grep -c running) |
|||
echo "bitcoinActive=${bitcoinRunning}" |
|||
|
|||
if [ ${bitcoinRunning} -eq 1 ]; then |
|||
|
|||
# get blockchain info |
|||
blockchaininfo=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 2>/home/bitcoin/.${network}/.bitcoind.error) |
|||
|
|||
# check if error on request |
|||
bitcoinError=$(sudo -u bitcoin cat /home/bitcoin/.${network}/.bitcoind.error | tr "'" '"' | tr '"' '\"' ) |
|||
sudo -u bitcoin rm /home/bitcoin/.${network}/.bitcoind.error |
|||
if [ ${#bitcoinError} -gt 0 ]; |
|||
echo "bitcoinError='${bitcoinError}'" |
|||
else |
|||
|
|||
############################## |
|||
# Get data from blockchaininfo |
|||
############################## |
|||
|
|||
# get total number of blocks |
|||
total=$(echo ${blockchaininfo} | jq -r '.blocks') |
|||
echo "blockchainHeight=${total}" |
|||
|
|||
# is initial sync of blockchain |
|||
initialSync=$(echo ${blockchaininfo} | jq -r '.initialblockdownload' | grep -c 'true') |
|||
echo "initialSync=${initialSync}" |
|||
|
|||
# get blockchain sync progress |
|||
syncProgress="$(echo ${blockchaininfo} | jq -r '.verificationprogress')" |
|||
syncProgress=$(echo $syncProgress | awk '{printf( "%.2f%%", 100 * $1)}') |
|||
echo "syncProgress=${syncProgress}" |
|||
|
|||
fi |
|||
fi |
|||
|
|||
# is LND running |
|||
lndRunning=$(systemctl status lnd.service 2>/dev/null | grep -c running) |
|||
|
|||
# TODO: check how long running ... try to find out if problem on starting |
|||
|
|||
echo "lndActive=${lndRunning}" |
|||
|
|||
if [ ${lndRunning} -eq 1 ]; then |
|||
|
|||
# get LND info |
|||
lndinfo=$(sudo -u bitcoin lncli getinfo 2>/home/bitcoin/.lnd/.lnd.error) |
|||
|
|||
# check if error on request |
|||
lndError=$(sudo -u bitcoin cat /home/bitcoin/.lnd/.lnd.error | tr "'" '"' | tr '"' '\"' ) |
|||
sudo -u bitcoin rm /home/bitcoin/.lnd/.lnd.error |
|||
if [ ${#lndError} -gt 0 ]; |
|||
echo "lndError='${lndError}'" |
|||
else |
|||
|
|||
# synced to chain |
|||
syncedToChain=$(echo ${lndinfo} | jq -r '.synced_to_chain' | grep -c 'true') |
|||
echo "syncedToChain=${syncedToChain}" |
|||
|
|||
# lnd scan progress |
|||
lndTimestamp=$(echo ${lndinfo} | jq -r '.best_header_timestamp') |
|||
echo "lndTimestamp=${lndTimestamp}" |
|||
lndDate=$(date -d @${lndTimestamp}) |
|||
echo "lndDate=${lndDate}" |
|||
|
|||
# calculate LND scan progress by seconds since Genesisblock |
|||
genesisTimestamp=1230940800 |
|||
nowTimestamp=$(date +%s) |
|||
totalSeconds=$(echo "${nowTimestamp}-${genesisTimestamp}" | bc) |
|||
echo "# totalSeconds($totalSeconds)" |
|||
scannedSeconds=$(echo "${lndTimestamp}-${genesisTimestamp}" | bc) |
|||
echo "# scannedSeconds($scannedSeconds)" |
|||
scanProgress=$(echo "scale=2; $scannedSeconds*100/$totalSeconds" | bc) |
|||
echo "scanProgress=${scanProgress}" |
|||
|
|||
fi |
|||
|
|||
fi |
|||
|
|||
# check if online if problem with other stuff |
|||
|
|||
# info on scan run time |
|||
endTime=$(date +%s) |
|||
runTime=$(echo "${endTime}-${startTime}" | bc) |
|||
echo "scantime=${runTime}" |
|||
|
|||
|
Loading…
Reference in new issue