raspiblitz/home.admin/setup.scripts/setupDialogControl.sh

256 lines
7.3 KiB
Bash
Raw Normal View History

2021-05-03 14:00:01 +02:00
#!/bin/bash
# get basic system information
# these are the same set of infos the WebGUI dialog/controler has
source /home/admin/raspiblitz.info
# SETUPFILE
# this key/value file contains the state during the setup process
2021-05-03 15:24:54 +02:00
SETUPFILE="/var/cache/raspiblitz/temp/raspiblitz.setup"
2021-05-03 14:00:01 +02:00
2021-05-21 21:18:37 -05:00
# remember original setupphase
orgSetupPhase="${setupPhase}"
2021-05-03 17:16:28 +02:00
# init SETUPFILE & temp dir on mem drive
2021-05-03 15:24:54 +02:00
sudo mkdir /var/cache/raspiblitz/temp
sudo chown admin:admin /var/cache/raspiblitz/temp
2021-05-03 14:28:50 +02:00
sudo rm $SETUPFILE 2>/dev/null
2021-05-03 14:00:01 +02:00
echo "# RASPIBLITZ SETUP STATE" > $SETUPFILE
2021-05-03 14:28:50 +02:00
sudo chown admin:admin $SETUPFILE
sudo chmod 777 $SETUPFILE
2021-05-03 14:00:01 +02:00
############################################
2021-05-21 11:52:20 -05:00
# QuickOption: Update
if [ "${setupPhase}" == "update" ]; then
2021-05-21 20:23:26 -05:00
# show update dialog
/home/admin/setup.scripts/dialogUpdate.sh
if [ "$?" == "0" ]; then
# proceed with provision (mark Password A to be set)
echo "# OK update process starting .."
echo "setPasswordA=1" >> $SETUPFILE
else
# default to normal setup options
2021-05-21 11:52:20 -05:00
setupPhase="setup"
2021-05-21 20:23:26 -05:00
echo "# you refused recovery option - defaulting to normal setup"
2021-05-03 14:00:01 +02:00
fi
fi
2021-05-21 11:52:20 -05:00
############################################
# QuickOption: Recovery
if [ "${setupPhase}" == "recovery" ]; then
2021-05-21 20:23:26 -05:00
# show recovery dialog
/home/admin/setup.scripts/dialogRecovery.sh
if [ "$?" == "0" ]; then
# proceed with provision (mark Password A to be set)
echo "# OK recover process starting .."
echo "setPasswordA=1" >> $SETUPFILE
else
# default to normal setup options
2021-05-21 11:52:20 -05:00
setupPhase="setup"
echo "# you refused recovery option - defaulting to normal setup"
fi
fi
############################################
# QuickOption: Migration from other node
if [ "${setupPhase}" == "migration" ]; then
2021-05-21 20:23:26 -05:00
# show recovery dialog
2021-05-03 14:00:01 +02:00
echo "# Starting migration dialog ..."
2021-05-21 11:52:20 -05:00
/home/admin/setup.scripts/dialogMigration.sh ${migrationOS}
2021-05-21 20:23:26 -05:00
if [ "$?" == "0" ]; then
# mark migration to happen on provision
echo "migrationOS='umbrel'" >> $SETUPFILE
echo "migrationVersion='${migrationVersion}'" >> $SETUPFILE
# user needs to reset password A, B & C
echo "setPasswordA=1" >> $SETUPFILE
echo "setPasswordB=1" >> $SETUPFILE
echo "setPasswordC=1" >> $SETUPFILE
else
# on cancel - default to normal setup
2021-05-21 11:52:20 -05:00
setupPhase="setup"
echo "# you refused node migration option - defaulting to normal setup"
2021-05-03 14:00:01 +02:00
exit 1
fi
2021-05-21 11:52:20 -05:00
fi
############################################
2021-05-21 20:23:26 -05:00
# DEFAULT: Basic Setup menu
2021-05-21 11:52:20 -05:00
# user might default to from quick options
if [ "${setupPhase}" == "setup" ]; then
echo "# Starting basic setup dialog ..."
/home/admin/setup.scripts/dialogBasicSetup.sh
2021-05-21 20:23:26 -05:00
menuresult=$?
2021-05-21 11:52:20 -05:00
2021-05-21 20:23:26 -05:00
# exit to terminal
if [ "${menuresult}" == "3" ]; then
2021-05-21 20:46:18 -05:00
exit 1
2021-05-21 20:23:26 -05:00
fi
2021-05-21 11:52:20 -05:00
2021-05-21 20:23:26 -05:00
# shutdown without changes
if [ "${menuresult}" == "2" ]; then
sudo shutdown now
exit 0
fi
2021-05-03 14:00:01 +02:00
2021-05-22 12:31:43 -05:00
###############################################
# FORMAT DRIVE on NEW SETUP or MIGRATION UPLOAD
if [ "${menuresult}" == "0" ] || [ "${menuresult}" == "1" ]; then
# check if there is a blockchain to use (so HDD is already formatted)
# thats also true if the node is coming from another nodeOS
existingBlockchain=""
if [ "${hddBlocksLitecoin}" == "1" ]; then
existingBlockchain="LITECOIN"
fi
if [ "${hddBlocksBitcoin}" == "1" ] || [ "${hddGotMigrationData}" != "" ]; then
existingBlockchain="BITCOIN"
fi
# ask user about possible existing blockchain and formatting HDD
/home/admin/setup.scripts/dialogDeleteData.sh "${existingBlockchain}"
userChoice=$?
if [ "${userChoice}" == "1" ]; then
# FORMAT DATA DRIVE
echo "TODO: Format HDD/SSD"
# DEBUG EXIT
exit 1
if [ "${userChoice}" == "2" ]; then
# KEEP BLOCKCHAIN + DLETE ALL THE REST
# when blockchain comes from another node migrate data first
if [ "${hddGotMigrationData}" != "" ]; then
echo "TODO: Migrate data from '{hddGotMigrationData}'"
fi
# delete everything but blockchain
echo "TODO: Delete everything but blockchain"
# by keeping that blockchain - user choosed already the blockchain type
if [ "${hddBlocksLitecoin}" == "1" ]; then
echo "network=litecoin" >> $SETUPFILE
else
echo "network=bitcoin" >> $SETUPFILE
fi
# DEBUG EXIT
exit 1
else
# STOP SETUP - loop back to setup menu start
exit 0
fi
fi
############################################
# UPLOAD MIGRATION
2021-05-21 20:23:26 -05:00
if [ "${menuresult}" == "1" ]; then
/home/admin/setup.scripts/dialogMigration.sh raspiblitz
if [ "$?" == "1" ]; then
2021-05-21 20:46:18 -05:00
# upload did not worked .. exit with 0 to restart process from outside loop
2021-05-22 12:31:43 -05:00
echo "Upload failed ... return to menu"
sleep 2
2021-05-21 20:23:26 -05:00
exit 0
fi
# user needs to reset password A
echo "setPasswordA=1" >> $SETUPFILE
2021-05-21 11:52:20 -05:00
fi
2021-05-03 14:00:01 +02:00
############################################
2021-05-21 20:23:26 -05:00
# FRESH SETUP
if [ "${menuresult}" == "0" ]; then
2021-05-03 14:00:01 +02:00
2021-05-21 20:23:26 -05:00
############################################
# Choosing Blockchain & Lightning
2021-05-03 14:00:01 +02:00
2021-05-21 20:23:26 -05:00
echo "# Starting Blockchain & Lightning selection ..."
/home/admin/setup.scripts/dialogBlockchainLightning.sh
if [ "$?" == "1" ]; then
2021-05-21 20:46:18 -05:00
# exit with 0 to restart process from outside loop
2021-05-21 20:23:26 -05:00
exit 0
fi
2021-05-03 14:00:01 +02:00
2021-05-21 20:23:26 -05:00
############################################
# Setting Name for Node
2021-05-03 14:13:54 +02:00
2021-05-21 20:23:26 -05:00
echo "# Starting name dialog ..."
/home/admin/setup.scripts/dialogName.sh
2021-05-03 14:13:54 +02:00
2021-05-21 20:23:26 -05:00
############################################
# Lightning Wallet (new or restore) do this before passwords
# because password C not needed if LND rescue file is uploaded
2021-05-03 14:13:54 +02:00
2021-05-21 20:23:26 -05:00
lightningWalletDone=0
while [ "${lightningWalletDone}" == "0" ]
do
echo "# Starting lightning wallet dialog ..."
/home/admin/setup.scripts/dialogLightningWallet.sh
# only if dialog exited clean end loop
if [ "$?" == "0" ]; then
lightningWalletDone=1
fi
2021-05-03 14:21:29 +02:00
2021-05-21 20:23:26 -05:00
# allow user to cancel to terminal on dialog main menu
# all other cancels have other exit codes
if [ "$?" == "1" ]; then
echo "# you selected cancel - sending exit code 1"
exit 1
fi
2021-05-03 14:00:01 +02:00
2021-05-21 20:23:26 -05:00
done
2021-05-03 14:00:01 +02:00
2021-05-21 20:23:26 -05:00
echo "# CREATING raspiblitz.conf from your setup choices"
2021-05-03 14:56:39 +02:00
2021-05-21 20:23:26 -05:00
# source the raspiblitz version
source /home/admin/_version.info
2021-05-03 14:00:01 +02:00
2021-05-21 20:23:26 -05:00
# source the setup state fresh
source $SETUPFILE
2021-05-03 14:56:39 +02:00
2021-05-21 20:23:26 -05:00
# prepare config file
CONFIGFILE="/mnt/hdd/raspiblitz.conf"
sudo rm $CONFIGFILE 2>/dev/null
sudo chown admin:admin $CONFIGFILE
sudo chmod 777 $CONFIGFILE
# write basic config file data
echo "# RASPIBLITZ CONFIG FILE" > $CONFIGFILE
echo "raspiBlitzVersion='${codeVersion}'" >> $CONFIGFILE
echo "lcdrotate=1" >> $CONFIGFILE
echo "lightning=${lightning}" >> $CONFIGFILE
echo "network=${network}" >> $CONFIGFILE
echo "chain=main" >> $CONFIGFILE
echo "runBehindTor=on" >> $CONFIGFILE
# user needs to set all passwords
echo "setPasswordA=1" >> $SETUPFILE
echo "setPasswordB=1" >> $SETUPFILE
echo "setPasswordC=1" >> $SETUPFILE
fi
2021-05-03 14:00:01 +02:00
2021-05-21 11:52:20 -05:00
fi
2021-05-03 14:56:39 +02:00
2021-05-21 11:52:20 -05:00
############################################
# Enter Passwords
# for fresh setup & migration
2021-05-03 14:00:01 +02:00
2021-05-21 11:52:20 -05:00
echo "# Starting passwords dialog ..."
/home/admin/setup.scripts/dialogPasswords.sh
2021-05-03 14:00:01 +02:00
2021-05-21 11:52:20 -05:00
# set flag for bootstrap process to kick-off provision process
sudo sed -i "s/^state=.*/state=waitprovision/g" /home/admin/raspiblitz.info
2021-05-03 14:00:01 +02:00
clear
echo "# setup dialog done - results in:"
echo "# $SETUPFILE"
echo "# $CONFIGFILE"