2019-04-16 19:55:25 +02:00
|
|
|
#!/bin/bash
|
2021-08-04 00:18:30 +02:00
|
|
|
|
|
|
|
#######################################
|
|
|
|
# SSH USER INTERFACE
|
|
|
|
# gets called when user logins per SSH
|
|
|
|
# or calls 'raspiblitz' on the terminal
|
|
|
|
#######################################
|
|
|
|
echo "Starting SSH user interface ... (please wait)"
|
2019-04-16 19:55:25 +02:00
|
|
|
|
|
|
|
# CONFIGFILE - configuration of RaspiBlitz
|
|
|
|
configFile="/mnt/hdd/raspiblitz.conf"
|
2021-08-04 00:18:30 +02:00
|
|
|
source ${configFile} 2>/dev/null
|
2019-04-16 19:55:25 +02:00
|
|
|
|
|
|
|
# INFOFILE - state data from bootstrap
|
|
|
|
infoFile="/home/admin/raspiblitz.info"
|
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
# check if raspiblitz.info exists
|
|
|
|
systemInfoExists=$(ls ${infoFile} | grep -c "${infoFile}")
|
|
|
|
if [ "${systemInfoExists}" != "1" ]; then
|
|
|
|
echo "systemInfoExists(${systemInfoExists})"
|
|
|
|
echo "FAIL: ${infoFile} does not exist .. which it should at this point."
|
|
|
|
echo "Check logs & bootstrap.service for errors and report to devs."
|
2019-12-14 16:06:28 +01:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
# get system state information raspiblitz.info
|
2019-04-16 19:55:25 +02:00
|
|
|
source ${infoFile}
|
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
# check that basic system phase/state information is available
|
|
|
|
if [ "${setupPhase}" == "" ] || [ "${state}" == "" ]; then
|
|
|
|
echo "setupPhase(${setupPhase}) state(${state})"
|
|
|
|
echo "FAIL: ${infoFile} does not exist or missing state."
|
|
|
|
echo "Check logs & bootstrap.service for errors and report to devs."
|
|
|
|
exit 1
|
2019-04-16 19:55:25 +02:00
|
|
|
fi
|
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
# special state: copysource
|
2020-09-29 12:35:22 +02:00
|
|
|
if [ "${state}" = "copysource" ]; then
|
|
|
|
echo "***********************************************************"
|
|
|
|
echo "INFO: You lost connection during copying the blockchain"
|
|
|
|
echo "You have the following options:"
|
|
|
|
echo "a) continue/check progress with command: sourcemode"
|
|
|
|
echo "b) return to normal mode with command: restart"
|
|
|
|
echo "***********************************************************"
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
# special state: copytarget
|
|
|
|
source <(/home/admin/config.scripts/blitz.copychain.sh status)
|
2020-11-10 23:40:54 +01:00
|
|
|
if [ "${copyInProgress}" = "1" ]; then
|
|
|
|
echo "Detected interrupted COPY blochain process ..."
|
2021-08-04 00:18:30 +02:00
|
|
|
/home/admin/config.scripts/blitz.copychain.sh target
|
2020-11-10 23:40:54 +01:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
# special state: reindex was triggered
|
2019-04-16 19:55:25 +02:00
|
|
|
if [ "${state}" = "reindex" ]; then
|
|
|
|
echo "Re-Index in progress ... start monitoring:"
|
|
|
|
/home/admin/config.scripts/network.reindex.sh
|
2021-08-04 00:18:30 +02:00
|
|
|
exit
|
2019-04-16 19:55:25 +02:00
|
|
|
fi
|
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
# special state: copystation
|
2019-05-18 23:43:29 +02:00
|
|
|
if [ "${state}" = "copystation" ]; then
|
2021-08-27 09:59:21 +02:00
|
|
|
echo "Copy Station is Running ..."
|
2019-05-18 23:43:29 +02:00
|
|
|
echo "reboot to return to normal"
|
2019-05-19 02:20:32 +02:00
|
|
|
sudo /home/admin/XXcopyStation.sh
|
2019-05-18 23:43:29 +02:00
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
# prepare status file
|
|
|
|
# TODO: this is to be replaced and unified together with raspiblitz.info
|
|
|
|
# when we move to a background monitoring thread & redis for WebUI with v1.8
|
|
|
|
sudo touch /var/cache/raspiblitz/raspiblitz.status
|
|
|
|
sudo chown admin:admin /var/cache/raspiblitz/raspiblitz.status
|
|
|
|
sudo chmod 740 /var/cache/raspiblitz/raspiblitz.status
|
2019-04-16 19:55:25 +02:00
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
#####################################
|
|
|
|
# SSH MENU LOOP
|
|
|
|
# this loop runs until user exits or
|
|
|
|
# an error drops user to terminal
|
|
|
|
#####################################
|
2019-04-16 19:55:25 +02:00
|
|
|
|
2021-08-24 20:21:40 +02:00
|
|
|
echo "# start ssh menu loop"
|
2021-08-04 00:18:30 +02:00
|
|
|
exitMenuLoop=0
|
|
|
|
doneIBD=0
|
|
|
|
while [ ${exitMenuLoop} -eq 0 ]
|
|
|
|
do
|
2019-04-17 00:38:59 +02:00
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
#####################################
|
|
|
|
# Access fresh system info on every loop
|
2019-04-16 19:55:25 +02:00
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
# refresh system state information
|
|
|
|
source ${infoFile}
|
2019-04-16 19:55:25 +02:00
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
# gather fresh status scan and store results in memory
|
|
|
|
# TODO: move this into background loop and unify with redis data storage later
|
2021-08-24 20:57:33 +02:00
|
|
|
#echo "# blitz.statusscan.sh"
|
2021-08-29 10:20:38 +02:00
|
|
|
|
|
|
|
if [ -f /var/cache/raspiblitz/raspiblitz.status ]; then
|
|
|
|
|
|
|
|
# run statusscan with timeout - if status scan was not killed it will copy over the
|
2021-08-29 10:25:19 +02:00
|
|
|
timeout 10 /home/admin/config.scripts/blitz.statusscan.sh > /var/cache/raspiblitz/raspiblitz.status.tmp
|
2021-08-29 10:20:38 +02:00
|
|
|
result=$?
|
|
|
|
if [ "${result}" != "0" ]; then
|
|
|
|
# statusscan finished in under 10 seconds - use results
|
|
|
|
cp /var/cache/raspiblitz/raspiblitz.status.tmp /var/cache/raspiblitz/raspiblitz.status
|
|
|
|
else
|
|
|
|
# statusscan blocked and was killed - fallback to old results
|
2021-08-29 12:24:52 +02:00
|
|
|
echo "statusscan blocked (${result}) - fallback to old results"
|
2021-08-29 10:20:38 +02:00
|
|
|
sleep 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
# first time run statusscan without timeout
|
2021-08-29 10:23:07 +02:00
|
|
|
echo "# running statusscan for the first time ... can take time"
|
2021-08-29 10:25:19 +02:00
|
|
|
/home/admin/config.scripts/blitz.statusscan.sh > /var/cache/raspiblitz/raspiblitz.status
|
2021-08-29 10:20:38 +02:00
|
|
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
# load statusscan results
|
2021-08-04 00:18:30 +02:00
|
|
|
source /var/cache/raspiblitz/raspiblitz.status
|
2019-04-16 19:55:25 +02:00
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
#####################################
|
|
|
|
# ALWAYS: Handle System States
|
|
|
|
#####################################
|
2019-04-16 19:55:25 +02:00
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
############################
|
|
|
|
# LND Wallet Unlock
|
2019-04-16 19:55:25 +02:00
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
if [ "${lndActive}" == "1" ] && [ "${walletLocked}" == "1" ] && [ "${state}" == "ready" ]; then
|
2021-08-24 20:57:33 +02:00
|
|
|
#echo "# lnd.unlock.sh"
|
2021-08-04 00:18:30 +02:00
|
|
|
/home/admin/config.scripts/lnd.unlock.sh
|
|
|
|
fi
|
2019-04-16 19:55:25 +02:00
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
#####################################
|
|
|
|
# SETUP MENU
|
|
|
|
#####################################
|
|
|
|
|
|
|
|
# when is needed & bootstrap process signals that it waits for user dialog
|
|
|
|
if [ "${setupPhase}" != "done" ] && [ "${state}" == "waitsetup" ]; then
|
|
|
|
# push user to main menu
|
2021-08-24 20:21:40 +02:00
|
|
|
echo "# controlSetupDialog.sh"
|
2021-08-04 00:18:30 +02:00
|
|
|
/home/admin/setup.scripts/controlSetupDialog.sh
|
|
|
|
# use the exit code from setup menu as signal if menu loop should exited
|
|
|
|
# 0 = continue loop / everything else = break loop and exit to terminal
|
|
|
|
exitMenuLoop=$?
|
|
|
|
if [ "${exitMenuLoop}" != "0" ]; then break; fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# SETUP DONE DIALOGS
|
|
|
|
#####################################
|
|
|
|
|
|
|
|
# when is needed & bootstrap process signals that it waits for user dialog
|
|
|
|
if [ "${setupPhase}" != "done" ] && [ "${state}" == "waitfinal" ]; then
|
|
|
|
# push to final setup gui dialogs
|
2021-08-24 20:57:33 +02:00
|
|
|
#echo "# controlFinalDialog.sh"
|
2021-08-04 00:18:30 +02:00
|
|
|
/home/admin/setup.scripts/controlFinalDialog.sh
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
#####################################
|
|
|
|
# INITIAL BLOCKCHAIN SYNC (SUBLOOP)
|
|
|
|
#####################################
|
|
|
|
if [ "${setupPhase}" == "done" ] && [ "${state}" == "ready" ] && [ "${initialSync}" == "1" ]; then
|
|
|
|
echo "debug wait eventBlockchainSync.sh ..."
|
|
|
|
sleep 3
|
2021-08-24 20:57:33 +02:00
|
|
|
#echo "# eventBlockchainSync.sh ssh loop"
|
2021-08-04 00:18:30 +02:00
|
|
|
/home/admin/setup.scripts/eventBlockchainSync.sh ssh loop
|
|
|
|
continue
|
|
|
|
fi
|
2019-04-16 20:00:12 +02:00
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
#####################################
|
|
|
|
# MAIN MENU or BLOCKCHAIN SYNC
|
|
|
|
#####################################
|
|
|
|
|
|
|
|
# when setup is done & state is ready .. jump to main menu
|
|
|
|
if [ "${setupPhase}" == "done" ] && [ "${state}" == "ready" ]; then
|
|
|
|
# MAIN MENU
|
2021-08-24 20:21:40 +02:00
|
|
|
echo "# 00mainMenu.sh"
|
2021-08-04 00:18:30 +02:00
|
|
|
/home/admin/00mainMenu.sh
|
|
|
|
# use the exit code from main menu as signal if menu loop should exited
|
|
|
|
# 0 = continue loop / everything else = break loop and exit to terminal
|
|
|
|
exitMenuLoop=$?
|
|
|
|
if [ "${exitMenuLoop}" != "0" ]; then break; fi
|
2019-04-25 15:37:21 +02:00
|
|
|
fi
|
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
#####################################
|
|
|
|
# DURING SETUP: Handle System States
|
|
|
|
#####################################
|
2019-04-28 22:09:19 +02:00
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
if [ "${setupPhase}" != "done" ]; then
|
|
|
|
|
|
|
|
#echo "# DURING SETUP: Handle System State (${state})"
|
|
|
|
|
|
|
|
# when no HDD on Vagrant - just print info & exit (admin info & exit)
|
|
|
|
if [ "${state}" == "noHDD" ] && [ ${vagrant} -gt 0 ]; then
|
|
|
|
echo "***********************************************************"
|
|
|
|
echo "VAGRANT INFO"
|
|
|
|
echo "***********************************************************"
|
|
|
|
echo "To connect a HDD data disk to your VagrantVM:"
|
|
|
|
echo "- shutdown VM with command: off"
|
|
|
|
echo "- open your VirtualBox GUI and select RaspiBlitzVM"
|
|
|
|
echo "- change the 'mass storage' settings"
|
|
|
|
echo "- add a second 'Primary Slave' drive to the already existing controller"
|
|
|
|
echo "- close VirtualBox GUI and run: vagrant up & vagrant ssh"
|
|
|
|
echo "***********************************************************"
|
|
|
|
echo "You can either create a new dynamic VDI with around 900GB or download"
|
|
|
|
echo "a VDI with a presynced blockchain to speed up setup. If you dont have 900GB"
|
|
|
|
echo "space on your laptop you can store the VDI file on an external drive."
|
|
|
|
echo "***********************************************************"
|
|
|
|
exit 1
|
2019-04-28 22:09:19 +02:00
|
|
|
fi
|
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
# for all critical errors (admin info & exit)
|
|
|
|
if [ "${state}" == "errorHDD" ]; then
|
|
|
|
echo "***********************************************************"
|
|
|
|
echo "SETUP ERROR - please report to development team"
|
|
|
|
echo "***********************************************************"
|
|
|
|
echo "state(${state}) message(${message})"
|
|
|
|
if [ "${state}" == "errorHDD" ]; then
|
|
|
|
# print some debug detail info on HDD/SSD error
|
2021-08-24 20:21:40 +02:00
|
|
|
echo "# blitz.datadrive.sh status"
|
2021-08-04 00:18:30 +02:00
|
|
|
sudo /home/admin/config.scripts/blitz.datadrive.sh status
|
|
|
|
fi
|
|
|
|
echo "command to shutdown --> off"
|
|
|
|
exit 1
|
|
|
|
else
|
|
|
|
# every other state just push as event to SSH frontend
|
|
|
|
echo "debug wait eventInfoWait.sh ..."
|
|
|
|
sleep 3
|
|
|
|
/home/admin/setup.scripts/eventInfoWait.sh "${state}" "${message}"
|
|
|
|
fi
|
2020-09-23 14:00:50 +02:00
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
fi
|
2019-04-16 19:55:25 +02:00
|
|
|
|
2021-08-04 00:18:30 +02:00
|
|
|
done
|
|
|
|
|
|
|
|
echo "# menu loop received exit code ${exitMenuLoop} --> exit to terminal"
|
|
|
|
echo "***********************************"
|
|
|
|
echo "* RaspiBlitz Commandline"
|
|
|
|
echo "* Here be dragons .. have fun :)"
|
|
|
|
echo "***********************************"
|
|
|
|
if [ "${setupPhase}" == "done" ]; then
|
|
|
|
echo "Bitcoin command line options: ${network}-cli help"
|
|
|
|
if [ "${lightning}" == "lnd" ]; then
|
|
|
|
echo "LND command line options: lncli -h"
|
|
|
|
fi
|
|
|
|
if [ "${lightning}" == "cln" ]; then
|
|
|
|
echo "C-Lightning command line options: lightning-cli help"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Your setup is not finished."
|
|
|
|
echo "For setup logs: cat raspiblitz.log"
|
|
|
|
echo "or call the command 'debug' to see bigger report."
|
2019-04-16 20:02:10 +02:00
|
|
|
fi
|
2021-08-04 00:18:30 +02:00
|
|
|
echo "Back to menus use command: raspiblitz"
|
|
|
|
echo
|
|
|
|
exit 0
|