raspiblitz/home.admin/00infoLCD.sh

221 lines
6.9 KiB
Bash
Raw Normal View History

2018-11-04 04:15:23 +01:00
#!/bin/bash
2018-07-17 13:12:03 +02:00
2018-10-15 22:31:56 +02:00
### USER PI AUTOSTART (LCD Display)
# this script gets started by the autologin of the pi user and
# and its output is gets displayed on the LCD or the RaspiBlitz
2018-08-24 23:29:22 +02:00
2018-12-10 21:29:22 +01:00
# CONFIGFILE - configuration of RaspiBlitz
configFile="/mnt/hdd/raspiblitz.conf"
# INFOFILE - state data from bootstrap
infoFile="/home/admin/raspiblitz.info"
2018-10-15 22:31:56 +02:00
# check that user is pi
if [ "$USER" != "pi" ]; then
echo "plz run as user pi --> su pi"
exit 1
fi
2018-08-24 23:29:22 +02:00
2018-12-10 21:29:22 +01:00
# display a 10s startup time
2018-12-12 19:45:59 +01:00
source /home/admin/_version.info
dialog --pause " Starting RaspiBlitz v${codeVersion} ..." 8 58 12
2018-11-04 01:21:58 +01:00
2018-10-15 22:31:56 +02:00
# DISPLAY LOOP
chain=""
while :
do
2018-12-10 21:29:22 +01:00
###########################
# CHECK BASIC DATA
###########################
2018-11-04 04:02:45 +01:00
# get the local network IP to be displayed on the lCD
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
2018-10-15 22:31:56 +02:00
2018-12-10 21:29:22 +01:00
# waiting for IP in general
2018-11-04 04:15:23 +01:00
if [ ${#localip} -eq 0 ]; then
2018-11-04 04:02:45 +01:00
l1="Waiting for Network ...\n"
l2="Not able to get local IP.\n"
l3="Is LAN cable connected?\n"
2019-01-28 12:13:37 +01:00
dialog --backtitle "RaspiBlitz ${codeVersion}" --infobox "$l1$l2$l3" 5 40
2018-10-15 22:31:56 +02:00
sleep 3
2018-12-10 21:29:22 +01:00
continue
fi
2018-10-15 22:31:56 +02:00
2018-12-10 21:29:22 +01:00
# waiting for DHCP in general
if [ "${localip:0:4}" = "169." ]; then
2018-11-04 04:02:45 +01:00
l1="Waiting for DHCP ...\n"
l2="Not able to get local IP.\n"
2018-12-11 13:15:15 +01:00
l3="Will try reboot every 5min.\n"
2019-01-28 12:13:37 +01:00
dialog --backtitle "RaspiBlitz ${codeVersion} (${localip})" --infobox "$l1$l2$l3" 5 40
2018-10-15 22:31:56 +02:00
sleep 3
2018-12-10 21:29:22 +01:00
continue
fi
2018-10-15 22:31:56 +02:00
2019-02-10 19:37:29 +01:00
# get config info if already available
2018-12-11 01:27:43 +01:00
configExists=$(ls ${configFile} 2>/dev/null | grep -c '.conf')
2018-12-10 21:29:22 +01:00
if [ ${configExists} -eq 1 ]; then
source ${configFile}
2019-02-10 19:37:29 +01:00
fi
# if setup not marked as done (=100) load boostrap info file
if [ "${setupStep}" != "100" ]; then
source ${infoFile}
2018-12-10 21:29:22 +01:00
fi
2018-12-03 00:37:58 +01:00
2018-12-10 21:29:22 +01:00
# if no information available from files - set default
if [ ${#setupStep} -eq 0 ]; then
setupStep=0
fi
2018-12-03 00:37:58 +01:00
2018-12-10 21:29:22 +01:00
# before setup even started
if [ ${setupStep} -eq 0 ]; then
2018-12-25 12:57:25 +01:00
# check for internet connection
# https://en.wikipedia.org/wiki/1.1.1.1
online=$(ping 1.1.1.1 -c 1 -W 2 | grep -c '1 received')
if [ ${online} -eq 0 ]; then
message="no internet connection"
2018-12-10 21:29:22 +01:00
# when in presync - get more info on progress
2018-12-25 12:57:25 +01:00
elif [ "${state}" = "presync" ]; then
2018-12-10 21:29:22 +01:00
# get blockchain sync progress
blockchaininfo="$(sudo -u root bitcoin-cli -conf=/home/admin/assets/bitcoin.conf getblockchaininfo 2>/dev/null)"
2018-12-11 20:30:13 +01:00
message="starting"
2018-12-10 21:29:22 +01:00
if [ ${#blockchaininfo} -gt 0 ]; then
message="$(echo "${blockchaininfo}" | jq -r '.verificationprogress')"
2018-12-11 00:28:34 +01:00
message=$(echo "${message}*100" | bc)
2018-12-11 01:32:52 +01:00
message="${message}%"
2018-12-03 00:37:58 +01:00
fi
2018-12-11 20:18:50 +01:00
# when old data - improve message
2018-12-25 12:57:25 +01:00
elif [ "${state}" = "olddata" ]; then
2018-12-11 20:18:50 +01:00
message="login for manual migration"
2018-12-12 15:05:54 +01:00
# when no HDD - improve message
2018-12-25 12:57:25 +01:00
elif [ "${state}" = "nohdd" ]; then
2018-12-12 15:05:54 +01:00
message="Connect HHD"
fi
2018-12-10 21:29:22 +01:00
# setup process has not started yet
l1="Login to your RaspiBlitz with:\n"
l2="ssh admin@${localip}\n"
l3="Use password: raspiblitz\n"
boxwidth=$((${#localip} + 24))
sleep 3
2018-12-12 19:45:59 +01:00
dialog --backtitle "RaspiBlitz ${codeVersion} (${state}) - ${message}" --infobox "$l1$l2$l3" 5 ${boxwidth}
2018-12-10 21:29:22 +01:00
sleep 5
continue
fi
2018-12-03 00:37:58 +01:00
2018-12-12 16:12:30 +01:00
# check if recovering/upgrade is running
if [ "${state}" = "recovering" ]; then
if [ ${#message} -eq 0 ]; then
message="Setup in Progress"
fi
2018-12-12 16:46:54 +01:00
l1="Upgrade/Recover/Provision\n"
2018-12-12 16:12:30 +01:00
l2="---> ${message}\n"
2018-12-12 17:28:54 +01:00
l3="Please keep running until reboot."
boxwidth=$((${#localip} + 28))
2019-02-10 11:53:49 +01:00
dialog --backtitle "RaspiBlitz ${codeVersion} (${state}) ${setupStep} ${localip}" --infobox "$l1$l2$l3" 5 ${boxwidth}
2018-12-12 16:46:54 +01:00
sleep 3
2018-12-12 16:12:30 +01:00
continue
fi
2018-12-12 18:21:01 +01:00
# if freshly recovered
if [ "${state}" = "recovered" ]; then
2018-12-12 18:24:45 +01:00
l1="FINAL RECOVER LOGIN NEEDED:\n"
2018-12-12 18:21:01 +01:00
l2="ssh admin@${localip}\n"
l3="Use password: raspiblitz\n"
boxwidth=$((${#localip} + 28))
2019-01-28 15:42:24 +01:00
dialog --backtitle "RaspiBlitz ${codeVersion} (${state})" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 3
continue
fi
# if re-indexing
if [ "${state}" = "reindex" ]; then
l1="REINDEXING BLOCKCHAIN\n"
l2="To monitor & detect finish:\n"
l3="ssh admin@${localip}\n"
boxwidth=$((${#localip} + 28))
2018-12-12 19:45:59 +01:00
dialog --backtitle "RaspiBlitz ${codeVersion} (${state})" --infobox "$l1$l2$l3" 5 ${boxwidth}
2018-12-12 18:21:01 +01:00
sleep 3
continue
fi
2018-12-12 16:12:30 +01:00
2019-02-11 13:44:03 +01:00
# when setup is in progress - password has been changed
if [ ${setupStep} -lt 100 ]; then
l1="Login to your RaspiBlitz with:\n"
l2="ssh admin@${localip}\n"
l3="Use your Password A\n"
boxwidth=$((${#localip} + 24))
sleep 3
dialog --backtitle "RaspiBlitz ${codeVersion} ${localip} - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 7
continue
fi
###########################
# DISPLAY AFTER SETUP
###########################
2018-12-10 21:29:22 +01:00
# check if bitcoin is ready
sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 1>/dev/null 2>error.tmp
clienterror=`cat error.tmp`
rm error.tmp
if [ ${#clienterror} -gt 0 ]; then
boxwidth=40
2018-12-10 21:29:22 +01:00
l1="Waiting for ${network}d to get ready.\n"
2019-01-09 23:06:20 +01:00
l2="---> ${clienterror/error*:/}\n"
2018-12-10 21:29:22 +01:00
l3="Can take longer if device was off."
2019-01-09 23:06:20 +01:00
uptimeSeconds="$(cat /proc/uptime | grep -o '^[0-9]\+')"
if [ ${uptimeSeconds} -gt 600 ]; then
l3="!!Please login for more details!!"
2018-10-15 22:31:56 +02:00
fi
2019-02-11 11:58:20 +01:00
dialog --backtitle "RaspiBlitz ${codeVersion} (${localip}) - Welcome Back" --infobox "$l1$l2$l3" 5 ${boxwidth}
2018-12-10 21:29:22 +01:00
sleep 5
continue
fi
2018-07-17 13:12:03 +02:00
2018-12-10 21:29:22 +01:00
# check if locked
2018-12-20 20:19:01 +01:00
locked=$(sudo -u bitcoin lncli --chain=${network} --network=${chain}net getinfo 2>&1 | grep -c unlock)
2018-12-10 21:29:22 +01:00
if [ "${locked}" -gt 0 ]; then
# special case: LND wallet is locked ---> show unlock info
2019-02-11 19:59:09 +01:00
h=5
2018-12-10 21:29:22 +01:00
l1="!!! LND WALLET IS LOCKED !!!\n"
l2="Login: ssh admin@${localip}\n"
l3="Use your Password A\n"
2019-02-11 19:59:09 +01:00
l4=""
if [ "${rtlWebinterface}" = "on" ]; then
l2="Browser: http://${localip}:3000\n"
l3="PasswordB=login / PasswordC=unlock\n"
l4="PasswordA: ssh admin@${localip}"
h=6
fi
2018-12-22 16:51:43 +01:00
if [ "${autoUnlock}" = "on" ]; then
2018-12-23 14:20:13 +01:00
l2="ssh admin@${localip}\n"
l3="Waiting for AUTO-UNLOCK"
2018-12-22 16:51:43 +01:00
fi
2019-02-18 17:07:20 +01:00
boxwidth=$((${#localip} + 26))
2019-02-11 19:59:09 +01:00
dialog --backtitle "RaspiBlitz ${codeVersion} (${localip}) - ${hostname}" --infobox "$l1$l2$l3$l4" ${h} ${boxwidth}
2018-12-10 21:29:22 +01:00
sleep 5
continue
fi
2018-11-04 04:09:35 +01:00
2018-12-10 21:29:22 +01:00
# if LND is syncing or scanning
2018-12-12 14:53:48 +01:00
lndSynced=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} --network=${chain}net getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true)
2018-12-10 21:29:22 +01:00
if [ ${lndSynced} -eq 0 ]; then
/home/admin/80scanLND.sh
sleep 20
continue
2018-11-04 04:05:25 +01:00
fi
2018-12-10 21:29:22 +01:00
# no special case - show status display
/home/admin/00infoBlitz.sh
sleep 5
2018-10-15 22:31:56 +02:00
done
2018-07-17 13:12:03 +02:00
2019-02-11 13:44:03 +01:00
fi