raspiblitz/home.admin/00infoLCD.sh

200 lines
6.5 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-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-11-04 01:21:58 +01:00
# check if RTL web interface is installed
runningRTL=$(sudo ls /etc/systemd/system/RTL.service 2>/dev/null | grep -c 'RTL.service')
2018-10-15 22:31:56 +02:00
# DISPLAY LOOP
chain=""
freshstart=1
while :
do
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'/')
dhcpMissing=
2018-10-15 22:31:56 +02:00
2018-11-04 04:15:23 +01:00
if [ ${#localip} -eq 0 ]; then
2018-10-15 22:31:56 +02:00
2018-11-04 04:02:45 +01:00
# waiting for IP in general
l1="Waiting for Network ...\n"
l2="Not able to get local IP.\n"
l3="Is LAN cable connected?\n"
dialog --backtitle "RaspiBlitz" --infobox "$l1$l2$l3" 5 30
2018-10-15 22:31:56 +02:00
sleep 3
2018-11-04 04:09:35 +01:00
elif [ "${localip:0:4}" = "169." ]; then
2018-10-15 22:31:56 +02:00
2018-11-04 04:02:45 +01:00
# waiting for IP in general
l1="Waiting for DHCP ...\n"
l2="Not able to get local IP.\n"
l3="Is Router working?\n"
dialog --backtitle "RaspiBlitz (${localip})" --infobox "$l1$l2$l3" 5 30
2018-10-15 22:31:56 +02:00
sleep 3
2018-11-04 04:02:45 +01:00
else
2018-10-15 22:31:56 +02:00
2018-11-04 04:02:45 +01:00
# refresh network (if information is already available)
network=`sudo cat /home/admin/.network 2>/dev/null`
2018-07-17 13:12:03 +02:00
2018-11-04 04:02:45 +01:00
# get the actual step number of setup process
setupStep=$(sudo -u admin cat /home/admin/.setup 2>/dev/null)
if [ ${#setupStep} -eq 0 ]; then
setupStep=0
2018-10-15 22:31:56 +02:00
fi
2018-07-17 13:12:03 +02:00
2018-11-04 04:02:45 +01:00
# before initial setup
if [ ${setupStep} -eq 0 ]; then
2018-07-17 13:12:03 +02:00
2018-11-27 04:19:57 +01:00
state="0"
message="Welcome"
# check data from _bootstrap.sh that was running on device setup
bootstrapInfoExists=$(ls /home/admin/raspiblitz.info | grep -c '.info')
if [ ${bootstrapInfoExists} -eq 1 ]; then
# load the data from the info file - overwrite state & message
2018-11-27 04:38:37 +01:00
source /home/admin/raspiblitz.info
2018-11-27 15:38:55 +01:00
if [ "${state}" = "presync" ]; then
# get blockchain sync progress
blockchaininfo="$(bitcoin-cli -datadir=/mnt/hdd/bitcoin getblockchaininfo 2>/dev/null)"
if [ ${#blockchaininfo} -gt 0 ]; then
message="$(echo "${blockchaininfo}" | jq -r '.verificationprogress')"
fi
fi
2018-11-27 04:19:57 +01:00
fi
2018-11-04 04:02:45 +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"
2018-10-15 22:31:56 +02:00
boxwidth=$((${#localip} + 24))
2018-11-04 04:02:45 +01:00
sleep 3
2018-11-27 04:38:37 +01:00
dialog --backtitle "RaspiBlitz (${state}) - ${message}" --infobox "$l1$l2$l3" 5 ${boxwidth}
2018-10-15 22:31:56 +02:00
sleep 5
2018-07-17 13:12:03 +02:00
2018-11-04 04:02:45 +01:00
# during basic setup
elif [ ${setupStep} -lt 65 ]; then
2018-07-17 13:12:03 +02:00
2018-11-04 04:02:45 +01:00
# setup process has not started yet
2018-10-15 22:31:56 +02:00
l1="Login to your RaspiBlitz with:\n"
l2="ssh admin@${localip}\n"
2018-11-04 04:02:45 +01:00
l3="Use your password A\n"
2018-10-15 22:31:56 +02:00
boxwidth=$((${#localip} + 24))
sleep 3
dialog --backtitle "RaspiBlitz ${localip} - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth}
2018-11-04 04:02:45 +01:00
sleep 5
2018-07-17 13:12:03 +02:00
2018-11-04 04:02:45 +01:00
# when blockchain and lightning are running
elif [ ${setupStep} -lt 100 ]; then
2018-07-17 13:12:03 +02:00
2018-11-04 04:02:45 +01:00
# when entering first time after boot - display a delay
if [ ${freshstart} -eq 1 ]; then
dialog --pause " Waiting for ${network} to startup and init ..." 8 58 130
freshstart=0
fi
2018-07-17 13:12:03 +02:00
2018-11-04 04:02:45 +01:00
# get state of system
if [ ${#chain} -eq 0 ];then
# get chain if not available before
chain=$(sudo -u bitcoin ${network}-cli -datadir=/home/bitcoin/.${network} getblockchaininfo 2>/dev/null | jq -r '.chain')
2018-10-19 00:29:20 +02:00
fi
2018-11-04 04:02:45 +01:00
lndSynced=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true)
locked=$(sudo tail -n 1 /mnt/hdd/lnd/logs/${network}/${chain}net/lnd.log 2>/dev/null | grep -c unlock)
2018-07-17 13:12:03 +02:00
2018-11-04 04:02:45 +01:00
if [ ${locked} -gt 0 ]; then
# special case: LND wallet is locked ---> show unlock info
l1="!!! LND WALLET IS LOCKED !!!\n"
l2="Login: ssh admin@${localip}\n"
l3="Use your Password A\n"
2018-11-04 01:21:58 +01:00
if [ ${runningRTL} -eq 1 ]; then
l2="Open: http://${localip}:3000\n"
l3="Use Password C to unlock\n"
fi
boxwidth=$((${#localip} + 24))
2018-11-04 04:02:45 +01:00
dialog --backtitle "RaspiBlitz ${localip} - Action Required" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 5
2018-11-04 04:02:45 +01:00
elif [ ${lndSynced} -eq 0 ]; then
# special case: LND is syncing
/home/admin/80scanLND.sh
sleep 20
else
2018-11-04 04:02:45 +01:00
# setup in progress without special case - password has been changed
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 ${localip} - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 10
fi
2018-11-04 04:02:45 +01:00
else
# RASPIBLITZ iS FULL SETUP
# 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
l1="Waiting for ${network}d to get ready.\n"
l2="---> Starting Up\n"
2018-11-12 21:13:21 +01:00
l3="Can take longer if device was off."
2018-11-04 04:02:45 +01:00
isVerifying=$(echo "${clienterror}" | grep -c 'Verifying blocks')
if [ ${isVerifying} -gt 0 ]; then
l2="---> Verifying Blocks\n"
fi
boxwidth=40
dialog --backtitle "RaspiBlitz ${localip} - Welcome" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 5
else
# check if locked
locked=$(sudo -u admin lncli --chain=${network} getinfo 2>&1 | grep -c unlock)
if [ "${locked}" -gt 0 ]; then
# special case: LND wallet is locked ---> show unlock info
l1="!!! LND WALLET IS LOCKED !!!\n"
l2="Login: ssh admin@${localip}\n"
l3="Use your Password A\n"
if [ ${runningRTL} -eq 1 ]; then
l2="Open: http://${localip}:3000\n"
l3="Use Password C to unlock\n"
fi
boxwidth=$((${#localip} + 24))
dialog --backtitle "RaspiBlitz ${localip} - Welcome" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 5
else
# no special case - show status display
/home/admin/00infoBlitz.sh
sleep 5
2018-07-17 13:12:03 +02:00
2018-11-04 04:02:45 +01:00
fi
fi
fi
2018-11-04 04:09:35 +01:00
2018-11-04 04:05:25 +01:00
fi
2018-10-15 22:31:56 +02:00
done
2018-07-17 13:12:03 +02:00
fi