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"
|
2018-12-12 19:45:59 +01:00
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion}" --infobox "$l1$l2$l3" 5 30
|
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"
|
2018-12-12 19:45:59 +01:00
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion} (${localip})" --infobox "$l1$l2$l3" 5 30
|
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
|
|
|
## get basic info from SD
|
2018-12-11 01:27:43 +01:00
|
|
|
bootstrapInfoExists=$(ls ${infoFile} 2>/dev/null | grep -c '.info')
|
2018-12-10 21:29:22 +01:00
|
|
|
if [ ${bootstrapInfoExists} -eq 1 ]; then
|
|
|
|
source ${infoFile}
|
|
|
|
fi
|
2018-10-15 22:31:56 +02:00
|
|
|
|
2018-12-10 21:29:22 +01:00
|
|
|
# get final config if already avaulable
|
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}
|
|
|
|
setupStep=100
|
|
|
|
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
|
|
|
|
|
|
|
|
# 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)"
|
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
|
|
|
|
fi
|
2018-12-11 20:18:50 +01:00
|
|
|
|
|
|
|
# when old data - improve message
|
|
|
|
if [ "${state}" = "olddata" ]; then
|
|
|
|
message="login for manual migration"
|
|
|
|
fi
|
2018-12-12 15:05:54 +01:00
|
|
|
|
|
|
|
# when no HDD - improve message
|
|
|
|
if [ "${state}" = "nohdd" ]; then
|
|
|
|
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-10 21:29:22 +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
|
2018-12-12 19:45:59 +01:00
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion} ${localip} - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth}
|
2018-12-10 21:29:22 +01:00
|
|
|
sleep 7
|
|
|
|
continue
|
|
|
|
fi
|
2018-07-17 13:12:03 +02:00
|
|
|
|
2018-12-10 21:29:22 +01:00
|
|
|
###########################
|
|
|
|
# DISPLAY AFTER SETUP
|
|
|
|
###########################
|
|
|
|
|
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))
|
2018-12-12 19:45:59 +01:00
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion} (${state})" --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))
|
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
|
|
|
|
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
|
|
|
|
|
|
|
|
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"
|
2018-10-15 22:31:56 +02:00
|
|
|
fi
|
2018-12-10 21:29:22 +01:00
|
|
|
boxwidth=40
|
2018-12-12 19:45:59 +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:11:02 +01:00
|
|
|
locked=$(sudo -u admin 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
|
|
|
|
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"
|
2018-11-04 04:02:45 +01:00
|
|
|
fi
|
2018-12-10 21:29:22 +01:00
|
|
|
boxwidth=$((${#localip} + 24))
|
2018-12-12 19:45:59 +01:00
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion} (${localip}) - ${hostname}" --infobox "$l1$l2$l3" 5 ${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
|
|
|
|
|
|
|
fi
|