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
|
|
|
|
2019-10-06 12:37:35 +02:00
|
|
|
function usage() {
|
|
|
|
echo -e "This script gets started by the autologin of the pi user and "
|
|
|
|
echo -e "and its output is gets displayed on the LCD or the RaspiBlitz."
|
|
|
|
echo -e ""
|
|
|
|
echo -e "Usage: $0 [-h|--help] [-v*|--verbose] [-p|--pause STRING]"
|
|
|
|
echo -e ""
|
|
|
|
echo -e " -h, --help\t\tprint this help message"
|
|
|
|
echo -e " -v, --verbose\t\tbe more verbose"
|
|
|
|
echo -e " -p, --pause STRING\ttime in seconds to pause"
|
|
|
|
echo -e ""
|
|
|
|
}
|
|
|
|
|
|
|
|
# Default Values
|
|
|
|
verbose=0
|
|
|
|
pause=12
|
|
|
|
|
|
|
|
while [[ "$1" == -* ]]; do
|
|
|
|
case "$1" in
|
|
|
|
-h|--help)
|
|
|
|
usage
|
|
|
|
exit 0
|
|
|
|
;;
|
|
|
|
-v*)
|
|
|
|
(( verbose += ${#1} - 1 ))
|
|
|
|
;;
|
|
|
|
--verbose)
|
|
|
|
(( verbose++ ))
|
|
|
|
;;
|
|
|
|
-p|--pause)
|
|
|
|
shift
|
|
|
|
pause="$1"
|
|
|
|
;;
|
|
|
|
--)
|
|
|
|
shift
|
|
|
|
break
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unrecognized option $1."
|
|
|
|
echo ""
|
|
|
|
usage
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
if ! [[ "$pause" =~ ^[[:digit:]]+$ ]]; then
|
|
|
|
echo "pause must be a positive integer or 0." >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
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
|
2019-10-06 12:37:35 +02:00
|
|
|
if [ "$pause" -ne "0" ]; then
|
|
|
|
dialog --pause " Starting RaspiBlitz v${codeVersion} ..." 8 58 ${pause}
|
|
|
|
fi
|
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
|
|
|
|
###########################
|
|
|
|
|
2019-12-11 14:10:34 +01:00
|
|
|
# get config info if already available (with state value)
|
2019-12-11 13:47:21 +01:00
|
|
|
source ${infoFile}
|
|
|
|
configExists=$(ls ${configFile} 2>/dev/null | grep -c '.conf')
|
|
|
|
if [ ${configExists} -eq 1 ]; then
|
|
|
|
source ${configFile}
|
|
|
|
fi
|
|
|
|
|
2019-12-11 13:59:33 +01:00
|
|
|
# reboot info
|
|
|
|
if [ "${state}" = "reboot" ]; then
|
2019-12-11 14:10:34 +01:00
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion}" --infobox "Waiting for Reboot ..." 3 30
|
2019-12-11 13:59:33 +01:00
|
|
|
sleep 20
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# shutdown info
|
|
|
|
if [ "${state}" = "shutdown" ]; then
|
2019-12-11 14:10:34 +01:00
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion}" --infobox "Waiting for Shutdown ..." 3 30
|
2019-12-11 13:59:33 +01:00
|
|
|
sleep 20
|
2018-12-10 21:29:22 +01:00
|
|
|
continue
|
|
|
|
fi
|
2018-10-15 22:31:56 +02:00
|
|
|
|
2021-05-04 01:51:22 +02:00
|
|
|
# make sure no local ip is readable
|
|
|
|
if [ "${localip}" == "" ]; then localip="no-network"; fi
|
|
|
|
|
2021-05-04 01:35:48 +02:00
|
|
|
# waiting for DHCP in general
|
|
|
|
if [ "${state}" = "noHDD" ]; then
|
|
|
|
l1="Waiting for HDD/SSD ...\n"
|
|
|
|
l2="Please connect a >500GB\n"
|
|
|
|
l3="HDD or SSD to the device.\n"
|
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion} (${localip})" --infobox "$l1$l2$l3" 5 40
|
|
|
|
sleep 1
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2018-12-10 21:29:22 +01:00
|
|
|
# waiting for DHCP in general
|
2019-12-11 13:47:21 +01:00
|
|
|
if [ "${state}" = "noDHCP" ]; then
|
2018-11-04 04:02:45 +01:00
|
|
|
l1="Waiting for DHCP ...\n"
|
|
|
|
l2="Not able to get local IP.\n"
|
2019-12-11 14:12:05 +01:00
|
|
|
l3="Check you router if constant.\n"
|
2019-01-28 12:13:37 +01:00
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion} (${localip})" --infobox "$l1$l2$l3" 5 40
|
2019-12-11 13:47:21 +01:00
|
|
|
sleep 1
|
2018-12-10 21:29:22 +01:00
|
|
|
continue
|
|
|
|
fi
|
2018-10-15 22:31:56 +02:00
|
|
|
|
2021-05-13 14:31:15 +02:00
|
|
|
# waiting for local IP
|
|
|
|
if [ "${state}" = "noIP-LAN" ] || [ "${state}" = "noIP-WIFI" ]; then
|
2021-05-04 01:05:31 +02:00
|
|
|
l1="Waiting for Network ...\n"
|
|
|
|
l2="Not able to get local IP.\n"
|
|
|
|
l3="LAN cable connected? WIFI lost?\n"
|
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion} (${localip})" --infobox "$l1$l2$l3" 5 40
|
|
|
|
sleep 1
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2021-05-13 14:31:15 +02:00
|
|
|
# waiting for Internet
|
2021-05-04 01:05:31 +02:00
|
|
|
if [ "${state}" = "noInternet" ]; then
|
|
|
|
l1="Waiting for Internet ...\n"
|
|
|
|
l2="Local Network seems OK but no Internet.\n"
|
|
|
|
l3="Is router still online?\n"
|
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion} (${localip})" --infobox "$l1$l2$l3" 5 40
|
|
|
|
sleep 1
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2021-05-04 01:35:48 +02:00
|
|
|
# waiting for Intrenet
|
|
|
|
if [ "${state}" = "noInternet" ]; then
|
|
|
|
l1="Waiting for Internet ...\n"
|
|
|
|
l2="Local Network seems OK but no Internet.\n"
|
|
|
|
l3="Is router still online?\n"
|
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion} (${localip})" --infobox "$l1$l2$l3" 5 40
|
|
|
|
sleep 1
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
# waiting for DHCP in general
|
|
|
|
if [ "${state}" = "sdtoosmall" ]; then
|
|
|
|
l1="SD card is too small.\n"
|
|
|
|
l2="Please use 16GB or bigger.\n"
|
|
|
|
l3="Its safe to cut power now.\n"
|
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion} (${localip})" --infobox "$l1$l2$l3" 5 40
|
|
|
|
sleep 1
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
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
|
|
|
|
2018-12-10 21:29:22 +01:00
|
|
|
# when in presync - get more info on progress
|
2021-05-04 01:05:31 +02:00
|
|
|
if [ "${state}" = "presync" ]; then
|
2019-05-28 01:08:42 +02:00
|
|
|
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')"
|
2019-03-08 14:17:17 +01:00
|
|
|
message=$(echo $message | awk '{printf( "%.2f%%", 100 * $1)}')
|
2018-12-03 00:37:58 +01:00
|
|
|
fi
|
2018-12-12 15:05:54 +01:00
|
|
|
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"
|
2020-01-08 13:16:39 +01:00
|
|
|
|
2021-05-04 15:24:38 +02:00
|
|
|
if [ "${state}" = "errorHDD" ]; then
|
|
|
|
l1="HDD Error: ${message}\n"
|
|
|
|
fi
|
|
|
|
|
2020-01-08 13:16:39 +01:00
|
|
|
if [ "${state}" = "recovering" ]; then
|
2020-03-30 18:56:59 +02:00
|
|
|
l1="Recovering please wait ..\n"
|
2020-01-08 13:16:39 +01:00
|
|
|
fi
|
2021-05-04 15:24:38 +02:00
|
|
|
|
2018-12-10 21:29:22 +01:00
|
|
|
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
|
2021-04-15 19:51:29 +02:00
|
|
|
recoveredInfoExists=$(sudo ls /home/admin/recover.flag 2>/dev/null | grep -c '.flag')
|
2019-05-02 14:38:03 +02:00
|
|
|
if [ ${recoveredInfoExists} -gt 0 ]; 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
|
|
|
|
###########################
|
|
|
|
|
2019-03-17 17:18:51 +01:00
|
|
|
if [ "${state}" = "repair" ]; then
|
|
|
|
l1="Repair Mode\n"
|
2019-03-17 17:10:20 +01:00
|
|
|
l2="ssh admin@${localip}\n"
|
|
|
|
l3="Use password: PasswordA\n"
|
|
|
|
boxwidth=$((${#localip} + 28))
|
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion} (${state}) ${setupStep} ${localip}" --infobox "$l1$l2$l3" 5 ${boxwidth}
|
|
|
|
sleep 3
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2019-08-07 12:32:52 +02:00
|
|
|
if [ "${state}" = "reboot" ]; then
|
|
|
|
l1="Reboot needed.\n"
|
|
|
|
l2="ssh admin@${localip}\n"
|
|
|
|
l3="Use password: PasswordA\n"
|
|
|
|
boxwidth=$((${#localip} + 28))
|
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion} (${state}) ${setupStep} ${localip}" --infobox "$l1$l2$l3" 5 ${boxwidth}
|
|
|
|
sleep 3
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2019-03-17 17:18:51 +01:00
|
|
|
if [ "${state}" = "retorrent" ]; then
|
|
|
|
l1="Repair Mode- TORRENT\n"
|
2018-12-12 18:21:01 +01:00
|
|
|
l2="ssh admin@${localip}\n"
|
2019-03-17 17:18:51 +01:00
|
|
|
l3="Use password: PasswordA\n"
|
2018-12-12 18:21:01 +01:00
|
|
|
boxwidth=$((${#localip} + 28))
|
2019-03-17 17:18:51 +01:00
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion} (${state}) ${setupStep} ${localip}" --infobox "$l1$l2$l3" 5 ${boxwidth}
|
2019-01-28 15:42:24 +01:00
|
|
|
sleep 3
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2019-03-17 17:18:51 +01:00
|
|
|
if [ "${state}" = "recopy" ]; then
|
|
|
|
l1="Repair Mode - COPY\n"
|
|
|
|
l2="ssh admin@${localip}\n"
|
|
|
|
l3="Use password: PasswordA\n"
|
2019-01-28 15:42:24 +01:00
|
|
|
boxwidth=$((${#localip} + 28))
|
2019-03-17 17:18:51 +01:00
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion} (${state}) ${setupStep} ${localip}" --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-05-18 21:25:46 +02:00
|
|
|
if [ "${state}" = "copystation" ]; then
|
2019-05-18 22:33:49 +02:00
|
|
|
l1="COPY STATION MODE\n"
|
|
|
|
l2="${message}"
|
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion} ${localip}" --infobox "$l1$l2" 6 56
|
2019-05-18 21:25:46 +02:00
|
|
|
sleep 2
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
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
|
|
|
|
|
2019-12-28 15:25:38 +01:00
|
|
|
# perform config check
|
|
|
|
configCheck=$(/home/admin/config.scripts/blitz.configcheck.py)
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
configValid=1
|
|
|
|
# echo "Config Valid!"
|
|
|
|
else
|
|
|
|
configValid=0
|
|
|
|
# echo "Config Not Valid!"
|
|
|
|
l1="POTENTIAL CONFIG ERROR FOUND\n"
|
|
|
|
l2="ssh admin@${localip}\n"
|
2020-02-20 13:24:57 +01:00
|
|
|
l3="use Password A\n"
|
|
|
|
l4="Run on Terminal command: check"
|
2019-12-28 17:45:01 +01:00
|
|
|
dialog --backtitle "RaspiBlitz ${codeVersion} cfg-err ${localip}" --infobox "$l1$l2$l3$l4" 6 50
|
2019-12-28 15:25:38 +01:00
|
|
|
sleep 20
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2018-12-10 21:29:22 +01:00
|
|
|
# no special case - show status display
|
2019-12-28 15:25:38 +01:00
|
|
|
/home/admin/00infoBlitz.sh
|
|
|
|
sleep 5
|
2018-07-17 13:12:03 +02:00
|
|
|
|
2019-12-28 15:25:38 +01:00
|
|
|
done
|