You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

334 lines
12 KiB

6 years ago
#!/bin/bash
7 years ago
# load code software version
source /home/admin/_version.info
7 years ago
# set colors
color_red='\033[0;31m'
color_green='\033[0;32m'
color_amber='\033[0;33m'
color_yellow='\033[1;93m'
7 years ago
color_gray='\033[0;37m'
color_purple='\033[0;35m'
7 years ago
## get basic info
source /home/admin/raspiblitz.info 2>/dev/null
source /mnt/hdd/raspiblitz.conf 2>/dev/null
# check hostname
if [ ${#hostname} -eq 0 ]; then hostname="raspiblitz"; fi
# for oldnodes
if [ ${#network} -eq 0 ]; then
network="bitcoin"
litecoinActive=$(sudo ls /mnt/hdd/litecoin/litecoin.conf 2>/dev/null | grep -c 'litecoin.conf')
if [ ${litecoinActive} -eq 1 ]; then
network="litecoin"
else
network=`sudo cat /home/admin/.network 2>/dev/null`
fi
if [ ${#network} -eq 0 ]; then
network="bitcoin"
fi
fi
# for oldnodes
if [ ${#chain} -eq 0 ]; then
chain="test"
isMainChain=$(sudo cat /mnt/hdd/${network}/${network}.conf 2>/dev/null | grep "#testnet=1" -c)
if [ ${isMainChain} -gt 0 ];then
chain="main"
fi
fi
7 years ago
# set datadir
7 years ago
bitcoin_dir="/home/bitcoin/.${network}"
7 years ago
lnd_dir="/home/bitcoin/.lnd"
lnd_macaroon_dir="/home/bitcoin/.lnd/data/chain/${network}/${chain}net"
7 years ago
# get uptime & load
6 years ago
load=$(w | head -n 1 | cut -d 'v' -f2 | cut -d ':' -f2)
7 years ago
# get CPU temp - no measurement in a VM
cpu=0
if [ -d "/sys/class/thermal/thermal_zone0/" ]; then
cpu=$(cat /sys/class/thermal/thermal_zone0/temp)
fi
tempC=$((cpu/1000))
tempF=$(((cpu/1000) * (9/5) + 32))
7 years ago
# get memory
ram_avail=$(free -m | grep Mem | awk '{ print $7 }')
ram=$(printf "%sM / %sM" "${ram_avail}" "$(free -m | grep Mem | awk '{ print $2 }')")
if [ ${ram_avail} -lt 50 ]; then
7 years ago
color_ram="${color_red}\e[7m"
else
color_ram=${color_green}
fi
# get free HDD ratio
6 years ago
hdd_free_ratio=$(printf "%d" "$(df -h | grep '/mnt/hdd$' | awk '{ print $4/$2*100 }')" 2>/dev/null)
7 years ago
hdd=$(printf "%s (%s%%)" "$(df -h | grep '/mnt/hdd$' | awk '{ print $4 }')" "${hdd_free_ratio}")
if [ ${hdd_free_ratio} -lt 10 ]; then
color_hdd="${color_red}\e[7m"
else
color_hdd=${color_green}
fi
# get network traffic
# ifconfig does not show eth0 on Armbian or in a VM - get first traffic info
isArmbian=$(cat /etc/os-release 2>/dev/null | grep -c 'Debian')
if [ ${isArmbian} -gt 0 ] || [ ! -d "/sys/class/thermal/thermal_zone0/" ]; then
network_rx=$(ifconfig | grep -m1 'RX packets' | awk '{ print $6$7 }' | sed 's/[()]//g')
network_tx=$(ifconfig | grep -m1 'TX packets' | awk '{ print $6$7 }' | sed 's/[()]//g')
else
network_rx=$(ifconfig eth0 | grep 'RX packets' | awk '{ print $6$7 }' | sed 's/[()]//g')
network_tx=$(ifconfig eth0 | grep 'TX packets' | awk '{ print $6$7 }' | sed 's/[()]//g')
fi
7 years ago
# Bitcoin blockchain
7 years ago
btc_path=$(command -v ${network}-cli)
7 years ago
if [ -n ${btc_path} ]; then
7 years ago
btc_title=$network
6 years ago
blockchaininfo="$(${network}-cli -datadir=${bitcoin_dir} getblockchaininfo 2>/dev/null)"
6 years ago
if [ ${#blockchaininfo} -gt 0 ]; then
7 years ago
btc_title="${btc_title} (${chain}net)"
# get sync status
6 years ago
block_chain="$(${network}-cli -datadir=${bitcoin_dir} getblockcount 2>/dev/null)"
block_verified="$(echo "${blockchaininfo}" | jq -r '.blocks')"
7 years ago
block_diff=$(expr ${block_chain} - ${block_verified})
progress="$(echo "${blockchaininfo}" | jq -r '.verificationprogress')"
sync_percentage=$(echo $progress | awk '{printf( "%.2f%%", 100 * $1)}')
7 years ago
if [ ${block_diff} -eq 0 ]; then # fully synced
sync="OK"
sync_color="${color_green}"
sync_behind=" "
elif [ ${block_diff} -eq 1 ]; then # fully synced
7 years ago
sync="OK"
sync_color="${color_green}"
sync_behind="-1 block"
elif [ ${block_diff} -le 10 ]; then # <= 2 blocks behind
sync=""
7 years ago
sync_color="${color_red}"
sync_behind="-${block_diff} blocks"
else
sync=""
7 years ago
sync_color="${color_red}"
sync_behind="${sync_percentage}"
fi
# get last known block
6 years ago
last_block="$(${network}-cli -datadir=${bitcoin_dir} getblockcount 2>/dev/null)"
7 years ago
if [ ! -z "${last_block}" ]; then
btc_line2="${btc_line2} ${color_gray}(block ${last_block})"
fi
# get mem pool transactions
6 years ago
mempool="$(${network}-cli -datadir=${bitcoin_dir} getmempoolinfo 2>/dev/null | jq -r '.size')"
7 years ago
else
btc_line2="${color_red}NOT RUNNING\t\t"
fi
fi
# get IP address & port
6 years ago
networkInfo=$(${network}-cli -datadir=${bitcoin_dir} getnetworkinfo 2>/dev/null)
7 years ago
local_ip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
public_ip="${publicIP}"
public_port="$(echo ${networkInfo} | jq -r '.localaddresses [0] .port')"
if [ "${public_port}" = "null" ]; then
if [ "${chain}" = "test" ]; then
public_port="18333"
else
public_port="8333"
fi
fi
7 years ago
6 years ago
# check if RTL web interface is installed
webinterfaceInfo=""
runningRTL=$(sudo ls /etc/systemd/system/RTL.service 2>/dev/null | grep -c 'RTL.service')
6 years ago
if [ ${runningRTL} -eq 1 ]; then
webinterfaceInfo="web admin --> ${color_green}http://${local_ip}:3000"
fi
6 years ago
# CHAIN NETWORK
public_addr_pre="Public "
public_addr="??"
torInfo=""
# Version
6 years ago
networkVersion=$(${network}-cli -datadir=${bitcoin_dir} -version 2>/dev/null | cut -d ' ' -f6)
# TOR or IP
networkInfo=$(${network}-cli -datadir=${bitcoin_dir} getnetworkinfo)
networkConnections=$(echo ${networkInfo} | jq -r '.connections')
networkConnectionsInfo="${color_purple}${networkConnections} ${color_gray}connections"
if [ "${runBehindTor}" = "on" ]; then
# TOR address
onionAddress=$(echo ${networkInfo} | jq -r '.localaddresses [0] .address')
networkConnectionsInfo="${color_purple}${networkConnections} ${color_gray}peers"
public_addr="${onionAddress}:${public_port}"
public=""
7 years ago
public_color="${color_green}"
torInfo="+ TOR"
7 years ago
else
# IP address
networkConnectionsInfo="${color_purple}${networkConnections} ${color_gray}connections"
public_addr="${public_ip}:${public_port}"
public_check=$(nc -z -w6 ${public_ip} ${public_port} 2>/dev/null; echo $?)
if [ $public_check = "0" ]; then
public=""
# only set yellow/normal because netcat can only say that the port is open - not that it points to this device for sure
public_color="${color_amber}"
else
public=""
public_color="${color_red}"
fi
# DynDNS
6 years ago
if [ ${#dynDomain} -gt 0 ]; then
#check if dyndns resolves to correct IP
ipOfDynDNS=$(getent hosts ${dynDomain} | awk '{ print $1 }')
if [ "${ipOfDynDNS}:${public_port}" != "${public_addr}" ]; then
public_color="${color_red}"
else
public_color="${color_amber}"
fi
# replace IP display with dynDNS
public_addr_pre="DynDNS "
public_addr="${dynDomain}"
fi
if [ ${#public_addr} -gt 25 ]; then
# if a IPv6 address dont show peers to save space
networkConnectionsInfo=""
fi
if [ ${#public_addr} -gt 35 ]; then
# if a LONG IPv6 address dont show "Public" in front to save space
public_addr_pre=""
fi
7 years ago
fi
6 years ago
# LIGHTNING NETWORK
6 years ago
ln_baseInfo="-"
6 years ago
ln_channelInfo="\n"
ln_external="\n"
ln_alias="${hostname}"
ln_publicColor=""
ln_port=$(sudo cat /mnt/hdd/lnd/lnd.conf | grep "^listen=*" | cut -f2 -d':')
if [ ${#ln_port} -eq 0 ]; then
ln_port="9735"
fi
6 years ago
wallet_unlocked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2> /dev/null | grep -c unlock)
6 years ago
if [ "$wallet_unlocked" -gt 0 ] ; then
7 years ago
alias_color="${color_red}"
ln_alias="Wallet Locked"
else
6 years ago
ln_getInfo=$(sudo -u bitcoin /usr/local/bin/lncli --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert getinfo 2>/dev/null)
6 years ago
ln_external=$(echo "${ln_getInfo}" | grep "uris" -A 1 | tr -d '\n' | cut -d '"' -f4)
ln_tor=$(echo "${ln_external}" | grep -c ".onion")
if [ ${ln_tor} -eq 1 ]; then
ln_publicColor="${color_green}"
else
public_check=$(nc -z -w6 ${public_ip} ${ln_port} 2>/dev/null; echo $?)
if [ $public_check = "0" ]; then
# only set yellow/normal because netcat can only say that the port is open - not that it points to this device for sure
ln_publicColor="${color_amber}"
else
ln_publicColor="${color_red}"
fi
fi
7 years ago
alias_color="${color_grey}"
6 years ago
ln_sync=$(echo "${ln_getInfo}" | grep "synced_to_chain" | grep "true" -c)
ln_version=$(echo "${ln_getInfo}" | jq -r '.version' | cut -d' ' -f1)
6 years ago
if [ ${ln_sync} -eq 0 ]; then
6 years ago
if [ ${#ln_getInfo} -eq 0 ]; then
6 years ago
ln_baseInfo="${color_red} Not Started | Not Ready Yet"
else
item=$(sudo -u bitcoin tail -n 100 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2> /dev/null | grep "(height" | tail -n1 | awk '{print $10} {print $11} {print $12}' | tr -dc '0-9')
6 years ago
total=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 2>/dev/null | jq -r '.blocks')
ln_baseInfo="${color_red} waiting for chain sync"
6 years ago
if [ ${#item} -gt 0 ]; then
6 years ago
ln_channelInfo="scanning ${item}/${total}"
fi
fi
else
6 years ago
ln_walletbalance="$(sudo -u bitcoin /usr/local/bin/lncli --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert walletbalance | jq -r '.confirmed_balance')" 2>/dev/null
ln_walletbalance_wait="$(sudo -u bitcoin /usr/local/bin/lncli --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert walletbalance | jq -r '.unconfirmed_balance')" 2>/dev/null
6 years ago
if [ "${ln_walletbalance_wait}" = "0" ]; then ln_walletbalance_wait=""; fi
if [ ${#ln_walletbalance_wait} -gt 0 ]; then ln_walletbalance_wait="(+${ln_walletbalance_wait})"; fi
6 years ago
ln_channelbalance="$(sudo -u bitcoin /usr/local/bin/lncli --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert channelbalance | jq -r '.balance')" 2>/dev/null
6 years ago
ln_channels_online="$(echo "${ln_getInfo}" | jq -r '.num_active_channels')" 2>/dev/null
6 years ago
ln_channels_total="$(sudo -u bitcoin /usr/local/bin/lncli --macaroonpath=${lnd_macaroon_dir}/readonly.macaroon --tlscertpath=${lnd_dir}/tls.cert listchannels | jq '.[] | length')" 2>/dev/null
ln_baseInfo="${color_gray}wallet ${ln_walletbalance} sat ${ln_walletbalance_wait}"
ln_peers="$(echo "${ln_getInfo}" | jq -r '.num_peers')" 2>/dev/null
6 years ago
ln_channelInfo="${ln_channels_online}/${ln_channels_total} Channels ${ln_channelbalance} sat"
ln_peersInfo="${color_purple}${ln_peers} ${color_gray}peers"
6 years ago
fi
fi
7 years ago
# STATUS SINALING: Backup Torrent Seeding
torrentBaseStatus=""
torrentUpdateStatus=""
if [ "${backupTorrentSeeding}" == "on" ]; then
torrentBaseStatus="•"
torrentUpdateStatus="•"
source <(sudo -u admin /home/admin/50torrentHDD.sh status)
if [ "${baseComplete}" == "1" ]; then
torrentBaseStatus="↑"
elif [ "${baseSeeding}" == "1" ]; then
torrentBaseStatus="↓"
fi
if [ "${updateComplete}" == "1" ]; then
torrentUpdateStatus="↑"
elif [ "${updateSeeding}" == "1" ]; then
torrentUpdateStatus="↓"
fi
fi
sleep 5
printf "
7 years ago
${color_yellow}
${color_yellow}
${color_yellow}
${color_yellow} ${color_amber}%s ${color_green} ${ln_alias}
6 years ago
${color_yellow} ${color_gray}${network} Fullnode + Lightning Network ${torInfo}
${color_yellow} ,/ ${color_yellow}%s
${color_yellow} ,'/ ${color_gray}%s, temp %s°C %s°F
${color_yellow} ,' / ${color_gray}Free Mem ${color_ram}${ram} ${color_gray} Free HDD ${color_hdd}%s${color_gray}
6 years ago
${color_yellow} ,' /_____, ${color_gray}ssh admin@${color_green}${local_ip}${color_gray}${network_rx}${network_tx}
6 years ago
${color_yellow} .'____ ,' ${color_gray}${webinterfaceInfo}
${color_yellow} / ,' ${color_gray}${network} ${color_green}${networkVersion} ${chain}net ${color_gray}Sync ${sync_color}${sync} %s${torrentBaseStatus}${torrentUpdateStatus}
${color_yellow} / ,' ${color_gray}${public_addr_pre}${public_color}${public_addr} ${public}${networkConnectionsInfo}
6 years ago
${color_yellow} /,' ${color_gray}
${color_yellow} /' ${color_gray}LND ${color_green}${ln_version} ${ln_baseInfo}
${color_yellow} ${color_gray}${ln_channelInfo} ${ln_peersInfo}
6 years ago
${color_yellow}
${color_yellow}${ln_publicColor}${ln_external}${color_red}
7 years ago
" \
"RaspiBlitz v${codeVersion}" \
7 years ago
"-------------------------------------------" \
"CPU load${load##up*, }" "${tempC}" "${tempF}" \
7 years ago
"${hdd}" "${sync_percentage}"
source /home/admin/stresstest.report 2>/dev/null
if [ ${#undervoltageReports} -gt 0 ] && [ "${undervoltageReports}" != "0" ]; then
6 years ago
echo "${undervoltageReports} undervoltage reports - run 'Hardware Test' in menu"
elif [ ${#powerFAIL} -gt 0 ] && [ ${powerFAIL} -gt 0 ]; then
6 years ago
echo "Weak power supply detected - run 'Hardware Test' in menu"
fi