raspiblitz/home.admin/config.scripts/blitz.statusscan.sh

112 lines
3.3 KiB
Bash
Raw Normal View History

2019-04-16 21:25:27 +01:00
#!/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)
2019-04-16 21:31:52 +01:00
# macke sure temp folder on HDD is available and fro all usable
sudo mkdir /mnt/hdd/temp 2>/dev/null
sudo chmod 777 -R /mnt/hdd/temp 2>/dev/null
2019-04-16 21:25:27 +01:00
# localIP
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
echo "localIP='${localip}'"
2019-04-16 22:00:49 +01:00
# temp
tempC=$(echo "scale=1; $(cat /sys/class/thermal/thermal_zone0/temp)/1000" | bc)
echo "tempCelsius='${tempC}'"
2019-04-16 21:25:27 +01:00
# 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
2019-04-16 21:31:52 +01:00
blockchaininfo=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 2>/mnt/hdd/temp/.bitcoind.error)
2019-04-16 21:25:27 +01:00
# check if error on request
2019-04-16 21:31:52 +01:00
bitcoinError=$(cat /mnt/hdd/temp/.bitcoind.error 2>/dev/null | tr "'" '"' | tr '"' '\"' )
rm /mnt/hdd/temp/.bitcoind.error 2>/dev/null
2019-04-16 21:26:37 +01:00
if [ ${#bitcoinError} -gt 0 ]; then
2019-04-16 21:25:27 +01:00
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')"
2019-04-16 21:39:49 +01:00
syncProgress=$(echo $syncProgress | awk '{printf( "%.2f%%", 100 * $1)}' | tr '%' ' ' | tr -s " ")
2019-04-16 21:25:27 +01:00
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
2019-04-16 21:31:52 +01:00
lndinfo=$(sudo -u bitcoin lncli getinfo 2>/mnt/hdd/temp/.lnd.error)
2019-04-16 21:25:27 +01:00
# check if error on request
2019-04-16 21:31:52 +01:00
lndError=$(cat /mnt/hdd/temp/.lnd.error 2>/dev/null | tr "'" '"' | tr '"' '\"' )
rm /mnt/hdd/temp/.lnd.error 2>/dev/null
2019-04-16 21:26:37 +01:00
if [ ${#lndError} -gt 0 ]; then
2019-04-16 21:25:27 +01:00
echo "lndError='${lndError}'"
else
# synced to chain
syncedToChain=$(echo ${lndinfo} | jq -r '.synced_to_chain' | grep -c 'true')
echo "syncedToChain=${syncedToChain}"
# lnd scan progress
2019-04-16 21:35:45 +01:00
scanTimestamp=$(echo ${lndinfo} | jq -r '.best_header_timestamp')
echo "scanTimestamp=${scanTimestamp}"
scanDate=$(date -d @${scanTimestamp})
2019-04-16 21:48:22 +01:00
echo "scanDate='${scanDate}'"
2019-04-16 21:25:27 +01:00
# calculate LND scan progress by seconds since Genesisblock
genesisTimestamp=1230940800
nowTimestamp=$(date +%s)
totalSeconds=$(echo "${nowTimestamp}-${genesisTimestamp}" | bc)
2019-04-16 21:35:45 +01:00
scannedSeconds=$(echo "${scanTimestamp}-${genesisTimestamp}" | bc)
2019-04-16 21:25:27 +01:00
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)
2019-04-16 21:35:45 +01:00
echo "scriptRuntime=${runTime}"
2019-04-16 21:25:27 +01:00