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.

167 lines
4.9 KiB

6 years ago
#!/bin/bash
7 years ago
### 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
6 years ago
# CONFIGFILE - configuration of RaspiBlitz
configFile="/mnt/hdd/raspiblitz.conf"
# INFOFILE - state data from bootstrap
infoFile="/home/admin/raspiblitz.info"
# check that user is pi
if [ "$USER" != "pi" ]; then
echo "plz run as user pi --> su pi"
exit 1
fi
6 years ago
# display a 10s startup time
dialog --pause " Starting services ..." 8 58 12
# DISPLAY LOOP
chain=""
while :
do
6 years ago
###########################
# CHECK BASIC DATA
###########################
6 years ago
# 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'/')
6 years ago
# waiting for IP in general
6 years ago
if [ ${#localip} -eq 0 ]; then
6 years ago
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
sleep 3
6 years ago
continue
fi
6 years ago
# waiting for DHCP in general
if [ "${localip:0:4}" = "169." ]; then
6 years ago
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
sleep 3
6 years ago
continue
fi
6 years ago
## get basic info from SD
bootstrapInfoExists=$(ls ${infoFile} | grep -c '.info')
if [ ${bootstrapInfoExists} -eq 1 ]; then
source ${infoFile}
fi
6 years ago
# get final config if already avaulable
configExists=$(ls ${configFile} | grep -c '.conf')
if [ ${configExists} -eq 1 ]; then
source ${configFile}
setupStep=100
fi
6 years ago
# if no information available from files - set default
if [ ${#setupStep} -eq 0 ]; then
setupStep=0
fi
6 years ago
###########################
# DISPLAY DURING SETUP
###########################
# before setup even started
if [ ${setupStep} -eq 0 ]; then
# when in presync - get more info on progress
if [ "${state}" = "presync" ]; then
# get blockchain sync progress
blockchaininfo="$(sudo -u root bitcoin-cli -conf=/home/admin/assets/bitcoin.conf getblockchaininfo 2>/dev/null)"
if [ ${#blockchaininfo} -gt 0 ]; then
message="$(echo "${blockchaininfo}" | jq -r '.verificationprogress')"
fi
fi
6 years ago
# 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
dialog --backtitle "RaspiBlitz (${state}) - ${message}" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 5
continue
fi
6 years ago
# 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 ${localip} - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 7
continue
fi
7 years ago
6 years ago
###########################
# DISPLAY AFTER 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"
l3="Can take longer if device was off."
isVerifying=$(echo "${clienterror}" | grep -c 'Verifying blocks')
if [ ${isVerifying} -gt 0 ]; then
l2="---> Verifying Blocks\n"
fi
6 years ago
boxwidth=40
dialog --backtitle "RaspiBlitz ${localip} - Welcome" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 5
continue
fi
7 years ago
6 years ago
# 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 [ "${rtlWebinterface}" = "on" ]; then
l2="Open: http://${localip}:3000\n"
l3="Use Password C to unlock\n"
6 years ago
fi
6 years ago
boxwidth=$((${#localip} + 24))
dialog --backtitle "RaspiBlitz ${localip} - Action Required" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 5
continue
fi
6 years ago
# if LND is syncing or scanning
lndSynced=$(sudo -u bitcoin /usr/local/bin/lncli --chain=${network} getinfo 2>/dev/null | jq -r '.synced_to_chain' | grep -c true)
if [ ${lndSynced} -eq 0 ]; then
/home/admin/80scanLND.sh
sleep 20
continue
fi
6 years ago
# no special case - show status display
/home/admin/00infoBlitz.sh
sleep 5
done
7 years ago
fi