Browse Source

moved after boot setup to bootstrap

#146
rootzoll 6 years ago
parent
commit
37bd101486
  1. 74
      home.admin/00infoLCD.sh
  2. 35
      home.admin/_bootstrap.sh

74
home.admin/00infoLCD.sh

@ -1,46 +1,34 @@
#!/bin/sh
if [ "$USER" = "pi" ]; then
# check for after setup script
afterSetupScriptExists=$(ls /home/pi/setup.sh 2>/dev/null | grep -c setup.sh)
if [ ${afterSetupScriptExists} -eq 1 ]; then
echo "*** SETUP SCRIPT DETECTED ***"
sudo cat /home/pi/setup.sh
sudo /home/pi/setup.sh
sudo rm /home/pi/setup.sh
echo "DONE wait 6 secs ... one more reboot needed ... "
sudo shutdown -r now
fi
# load network
network=`sudo cat /home/admin/.network 2>/dev/null`
### 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
### USER PI AUTOSTART (LCD Display)
localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/')
# check that user is pi
if [ "$USER" != "pi" ]; then
echo "plz run as user pi --> su pi"
exit 1
fi
# check if bitcoin service is configured
bitcoinInstalled=$(sudo -u bitcoin ls /mnt/hdd/${network}/ 2>/dev/null | grep -c ${network}.conf)
if [ ${bitcoinInstalled} -eq 1 ]; then
# wait enough secs to let bitcoind init
dialog --pause " Waiting for ${network} to startup and init ..." 8 58 130
fi
# 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'/')
# show updating status in loop
chain=""
while :
# DISPLAY LOOP
chain=""
freshstart=1
while :
do
# refresh network
# refresh network (if information is already available)
network=`sudo cat /home/admin/.network 2>/dev/null`
# get the setup state
setupStepExists=$(sudo -u admin ls -la /home/admin/.setup 2>/dev/null | grep -c .setup)
if [ ${setupStepExists} -eq 1 ]; then
setupStep=$(sudo -u admin cat /home/admin/.setup)
else
# 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
fi
# before initial setup
if [ ${setupStep} -eq 0 ]; then
# setup process has not started yet
@ -49,9 +37,10 @@ if [ "$USER" = "pi" ]; then
l3="Use password: raspiblitz\n"
boxwidth=$((${#localip} + 24))
sleep 3
dialog --backtitle "RaspiBlitz - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth}
dialog --backtitle "RaspiBlitz ${localip} - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 5
# during basic setup
elif [ ${setupStep} -lt 65 ]; then
# setup process has not started yet
@ -60,12 +49,19 @@ if [ "$USER" = "pi" ]; then
l3="Use your password A\n"
boxwidth=$((${#localip} + 24))
sleep 3
dialog --backtitle "RaspiBlitz - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth}
dialog --backtitle "RaspiBlitz ${localip} - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 5
# when blockchain and lightning are running
elif [ ${setupStep} -lt 100 ]; then
# setup process init is done and not finished
# 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
# 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')
@ -80,7 +76,7 @@ if [ "$USER" = "pi" ]; then
l2="Login: ssh admin@${localip}\n"
l3="Use your Password A\n"
boxwidth=$((${#localip} + 24))
dialog --backtitle "RaspiBlitz - Action Required" --infobox "$l1$l2$l3" 5 ${boxwidth}
dialog --backtitle "RaspiBlitz ${localip} - Action Required" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 5
elif [ ${lndSynced} -eq 0 ]; then
@ -97,7 +93,7 @@ if [ "$USER" = "pi" ]; then
l3="Use your Password A\n"
boxwidth=$((${#localip} + 24))
sleep 3
dialog --backtitle "RaspiBlitz - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth}
dialog --backtitle "RaspiBlitz ${localip} - Welcome (${setupStep})" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 10
fi
@ -115,7 +111,7 @@ if [ "$USER" = "pi" ]; then
l2="Login: ssh admin@${localip}\n"
l3="Use your Password A\n"
boxwidth=$((${#localip} + 24))
dialog --backtitle "RaspiBlitz - Welcome" --infobox "$l1$l2$l3" 5 ${boxwidth}
dialog --backtitle "RaspiBlitz ${localip} - Welcome" --infobox "$l1$l2$l3" 5 ${boxwidth}
sleep 5
else
@ -129,8 +125,4 @@ if [ "$USER" = "pi" ]; then
fi
done
else
echo "plz run as user pi --> su pi"
fi

35
home.admin/_bootstrap.sh

@ -1,8 +1,8 @@
#!/bin/bash
# This script runs on every start and makes sure the system
# is configured like the default values or as in the config
# file /mnt/hdd/raspiblitz.cfg
# This script runs on every start calles by boostrap.service
# It makes sure that the system is configured like the
# default values or as in the config.
# For more details see background_raspiblitzSettings.md
# load codeVersion
@ -16,8 +16,10 @@ echo "Running RaspiBlitz Bootstrap ${codeVersion}" >> $logfile
date >> $logfile
echo "***********************************************" >> $logfile
################################
# HDD CHECK / INIT
# for the very first setup
################################
# check if the HDD is mounted
@ -28,6 +30,29 @@ if [ ${#hddAvailable} -eq 0 ]; then
exit 1
fi
################################
# AFTER BOOT SCRIPT
# when a process needs to
# execute stuff after a reboot
################################
# check for after boot script
afterSetupScriptExists=$(ls /home/pi/setup.sh 2>/dev/null | grep -c setup.sh)
if [ ${afterSetupScriptExists} -eq 1 ]; then
echo "*** SETUP SCRIPT DETECTED ***"
# echo out script to journal logs
sudo cat /home/pi/setup.sh
# execute the after boot script
sudo /home/pi/setup.sh
# delete the after boot script
sudo rm /home/pi/setup.sh
# reboot again
echo "DONE wait 6 secs ... one more reboot needed ... "
sudo shutdown -r now
sleep 100
fi
################################
# CONFIGFILE BASICS
################################
@ -60,11 +85,11 @@ fi
# AUTOPILOT
# autoPilot=off|on
if [ ${#autoPilot} -eq 0 ]; then
echo "autoPilot=off" >> $configExists
echo "autoPilot=off" >> $configFile
fi
# after all default values written to config - reload config
source $configExists
source $configFile
################################

Loading…
Cancel
Save