mirror of
https://github.com/raspiblitz/raspiblitz.git
synced 2025-10-09 20:32:52 +02:00
refactor bootstrap
This commit is contained in:
@@ -666,10 +666,6 @@ if [ "${scenario}" != "ready" ] ; then
|
|||||||
cp -a /var/cache/raspiblitz/hdd-inspect/raspiblitz.setup ${setupFile}
|
cp -a /var/cache/raspiblitz/hdd-inspect/raspiblitz.setup ${setupFile}
|
||||||
state="waitprovision"
|
state="waitprovision"
|
||||||
|
|
||||||
# TODO: REMOVE AFTER DEBUG
|
|
||||||
echo "DEBUG EXIT 3" >> ${logFile}
|
|
||||||
exit 0
|
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "INFO: 'raspiblitz.setup' does not exist - wait for user config" >> ${logFile}
|
echo "INFO: 'raspiblitz.setup' does not exist - wait for user config" >> ${logFile}
|
||||||
state="waitsetup"
|
state="waitsetup"
|
||||||
@@ -701,11 +697,36 @@ if [ "${scenario}" != "ready" ] ; then
|
|||||||
echo "LOADING 'raspiblitz.setup' ..." >> ${logFile}
|
echo "LOADING 'raspiblitz.setup' ..." >> ${logFile}
|
||||||
source ${setupFile}
|
source ${setupFile}
|
||||||
|
|
||||||
# when user agreed to system copy to bootable drive (flag from setupFile)
|
# when this is the boot of the new system (skip to provision)
|
||||||
if [ "${systemCopy}" = "1" ]; then
|
if [ "${systemCopy}" = "done" ]; then
|
||||||
|
scenario="setup"
|
||||||
|
setupCommand="skip"
|
||||||
|
bootFromStorage=0
|
||||||
|
|
||||||
#####################################
|
# system recommended setup:system but user decided against - downgrade to simple setup
|
||||||
# SYSTEM COPY OF FRESH SYSTEM
|
if [ "${scenario}" = "setup:system" ] && [ "${systemCopy}" = "no" ] && [ "${deleteData}" = "all" ]; then
|
||||||
|
scenario="setup"
|
||||||
|
setupCommand="setup"
|
||||||
|
bootFromStorage=0
|
||||||
|
|
||||||
|
# user agreed to system copy & delete all data
|
||||||
|
elif [ "${scenario}" = "setup:system" ] && [ "${systemCopy}" = "yes" ] && [ "${deleteData}" = "all" ]; then
|
||||||
|
setupCommand="setup"
|
||||||
|
|
||||||
|
# user agreed to run system from install medium and delete all data
|
||||||
|
elif [ "${scenario}" = "setup" ] && [ "${deleteData}" = "all" ]; then
|
||||||
|
setupCommand="setup"
|
||||||
|
bootFromStorage=0
|
||||||
|
|
||||||
|
# run recovery
|
||||||
|
elif [ "${scenario}" = "recover:system" ] || [ "${scenario}" = "recover" ]; then
|
||||||
|
setupCommand="recover"
|
||||||
|
fi
|
||||||
|
|
||||||
|
###############################################
|
||||||
|
# SYSTEM COPY OF FRESH SYSTEM (SETUP & RECOVER)
|
||||||
|
|
||||||
|
if [ "${setupCommand}" = "setup" ] || [ "${setupCommand}" = "recover" ]; then
|
||||||
|
|
||||||
echo "SYSTEM COPY OF FRESH SYSTEM" >> ${logFile}
|
echo "SYSTEM COPY OF FRESH SYSTEM" >> ${logFile}
|
||||||
/home/admin/_cache.sh set state "systemcopy"
|
/home/admin/_cache.sh set state "systemcopy"
|
||||||
@@ -713,11 +734,10 @@ if [ "${scenario}" != "ready" ] ; then
|
|||||||
|
|
||||||
# STORAGE
|
# STORAGE
|
||||||
if [ ${#storageDevice} -gt 0 ] && [ ${#storageMountedPath} -eq 0 ]; then
|
if [ ${#storageDevice} -gt 0 ] && [ ${#storageMountedPath} -eq 0 ]; then
|
||||||
/home/admin/_cache.sh set message "Init STORAGE Drive"
|
|
||||||
error=""
|
error=""
|
||||||
source <(/home/admin/config.scripts/blitz.data.sh setup STORAGE "${storageDevice}" "${combinedDataStorage}" "${bootFromStorage}")
|
source <(/home/admin/config.scripts/blitz.data.sh ${setupCommand} STORAGE "${storageDevice}" "${combinedDataStorage}" "${bootFromStorage}")
|
||||||
if [ "${error}" != "" ]; then
|
if [ "${error}" != "" ]; then
|
||||||
echo "FAIL: 'setup STORAGE' failed error(${error})" >> ${logFile}
|
echo "FAIL: '${setupCommand} STORAGE' failed error(${error})" >> ${logFile}
|
||||||
/home/admin/_cache.sh set state "error"
|
/home/admin/_cache.sh set state "error"
|
||||||
/home/admin/_cache.sh set message "${error}"
|
/home/admin/_cache.sh set message "${error}"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -726,11 +746,10 @@ if [ "${scenario}" != "ready" ] ; then
|
|||||||
|
|
||||||
# SYSTEM
|
# SYSTEM
|
||||||
if [ ${#systemDevice} -gt 0 ] && [ "${bootFromStorage}" = "0" ] && [ ${#systemWarning} -eq 0 ]; then
|
if [ ${#systemDevice} -gt 0 ] && [ "${bootFromStorage}" = "0" ] && [ ${#systemWarning} -eq 0 ]; then
|
||||||
/home/admin/_cache.sh set message "Init SYSTEM Drive"
|
|
||||||
error=""
|
error=""
|
||||||
source <(/home/admin/config.scripts/blitz.data.sh setup SYSTEM "${systemDevice}")
|
source <(/home/admin/config.scripts/blitz.data.sh ${setupCommand} SYSTEM "${systemDevice}")
|
||||||
if [ "${error}" != "" ]; then
|
if [ "${error}" != "" ]; then
|
||||||
echo "FAIL: 'setup SYSTEM' failed error(${error})" >> ${logFile}
|
echo "FAIL: '${setupCommand} SYSTEM' failed error(${error})" >> ${logFile}
|
||||||
/home/admin/_cache.sh set state "error"
|
/home/admin/_cache.sh set state "error"
|
||||||
/home/admin/_cache.sh set message "${error}"
|
/home/admin/_cache.sh set message "${error}"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -739,190 +758,66 @@ if [ "${scenario}" != "ready" ] ; then
|
|||||||
|
|
||||||
# DATA
|
# DATA
|
||||||
if [ ${#dataDevice} -gt 0 ] && [ ${#dataWarning} -eq 0 ]; then
|
if [ ${#dataDevice} -gt 0 ] && [ ${#dataWarning} -eq 0 ]; then
|
||||||
/home/admin/_cache.sh set message "Init DATA Drive"
|
|
||||||
error=""
|
error=""
|
||||||
source <(/home/admin/config.scripts/blitz.data.sh setup DATA "${systemDevice}")
|
source <(/home/admin/config.scripts/blitz.data.sh ${setupCommand} DATA "${systemDevice}")
|
||||||
if [ "${error}" != "" ]; then
|
if [ "${error}" != "" ]; then
|
||||||
echo "FAIL: 'setup DATA' failed error(${error})" >> ${logFile}
|
echo "FAIL: '${setupCommand} DATA' failed error(${error})" >> ${logFile}
|
||||||
/home/admin/_cache.sh set state "error"
|
/home/admin/_cache.sh set state "error"
|
||||||
/home/admin/_cache.sh set message "${error}"
|
/home/admin/_cache.sh set message "${error}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# put flag file into old system
|
# when system was isntalled on new boot drive
|
||||||
touch /home/admin/systemcopy.flag
|
if [ "${scenario}" = "setup:system" ] || [ "${scenario}" = "recover:system" ]; then
|
||||||
|
|
||||||
# put setupFile to new system (so after reboot it can auto-provision)
|
# mark systemCopy as done in raspiblitz.setup
|
||||||
source <(/home/admin/config.scripts/blitz.data.sh status)
|
if ! sed -i '' "s/^systemCopy=.*/systemCopy=done/" "${setupFile}"; then
|
||||||
mount /dev/${dataPartition} /mnt/disk_data
|
echo "error='failed to update systemCopy in setupFile'" >&2
|
||||||
echo "copy setupFile(${setupFile}) to /mnt/disk_data/app-data/raspiblitz.setup" >> ${logFile}
|
exit 1
|
||||||
cp ${setupFile} /mnt/disk_data/home/admin/raspiblitz.setup
|
fi
|
||||||
umount /mnt/disk_data
|
|
||||||
|
|
||||||
# TODO: disable old system boot
|
# put setupFile to new system (so after reboot it dows not need to ask user again)
|
||||||
|
source <(/home/admin/config.scripts/blitz.data.sh status)
|
||||||
|
mount /dev/${dataPartition} /mnt/disk_data
|
||||||
|
echo "copy setupFile(${setupFile}) to /mnt/disk_data/app-data/raspiblitz.setup" >> ${logFile}
|
||||||
|
cp ${setupFile} /mnt/disk_data/home/admin/raspiblitz.setup
|
||||||
|
umount /mnt/disk_data
|
||||||
|
|
||||||
# TODO: REMOVE AFTER DEBUG
|
# put flag file into old system
|
||||||
echo "DEBUG EXIT 1" >> ${logFile}
|
touch /home/admin/systemcopy.flag
|
||||||
exit 0
|
|
||||||
|
|
||||||
# reboot so that new system can start
|
# TODO: disable old system boot
|
||||||
/home/admin/_cache.sh set state "reboot"
|
sudo umount /dev/mmcblk0p1
|
||||||
/home/admin/_cache.sh set message "restarting system"
|
sudo parted --script /dev/mmcblk0 rm 1
|
||||||
shutdown -r now
|
|
||||||
exit 0
|
# reboot so that new system can start
|
||||||
|
/home/admin/_cache.sh set state "reboot"
|
||||||
|
/home/admin/_cache.sh set message "restarting system"
|
||||||
|
shutdown -r now
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
else
|
else
|
||||||
echo "Skipping System Copy" >> ${logFile}
|
echo "Skipping System Copy" >> ${logFile}
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
# TODO: REMOVE AFTER DEBUG
|
#############################################
|
||||||
echo "DEBUG EXIT 2" >> ${logFile}
|
# MIGRATION FILE UPLOAD
|
||||||
exit 0
|
#############################################
|
||||||
|
|
||||||
# on RECOVER/UPDATE: auto copy system
|
# TODO: MIGRATION FILE UPLOAD as a second UI waitloop (after storage setup )
|
||||||
if [ "${scenario}" = "recover:system" ]; then
|
|
||||||
|
|
||||||
/home/admin/_cache.sh set state "recover:system"
|
|
||||||
/home/admin/_cache.sh set message ""
|
|
||||||
|
|
||||||
|
|
||||||
# STORAGE
|
|
||||||
if [ ${#storageDevice} -gt 0 ] && [ "${storageMountedPath}" = "0" ]; then
|
|
||||||
/home/admin/_cache.sh set message "Init STORAGE Drive"
|
|
||||||
error=""
|
|
||||||
|
|
||||||
if [ "${error}" != "" ]; then
|
|
||||||
echo "FAIL: 'setup STORAGE' failed error(${error})" >> ${logFile}
|
|
||||||
/home/admin/_cache.sh set state "error"
|
|
||||||
/home/admin/_cache.sh set message "${error}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# SYSTEM
|
|
||||||
error=""
|
|
||||||
if [ ${#systemDevice} -gt 0 ] && [ "${bootFromStorage}" = "0" ]; then
|
|
||||||
/home/admin/_cache.sh set message "Udpating SYSTEM"
|
|
||||||
source <(/home/admin/config.scripts/blitz.data.sh recover SYSTEM "${systemDevice}")
|
|
||||||
else
|
|
||||||
/home/admin/_cache.sh set message "Udpating STORAGE"
|
|
||||||
source <(/home/admin/config.scripts/blitz.data.sh recover STORAGE "${storageDevice}" "${combinedDataStorage}" "${bootFromStorage}")
|
|
||||||
fi
|
|
||||||
if [ "${error}" != "" ]; then
|
|
||||||
echo "FAIL: 'setup SYSTEM' failed error(${error})" >> ${logFile}
|
|
||||||
/home/admin/_cache.sh set state "error"
|
|
||||||
/home/admin/_cache.sh set message "${error}"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
# TODO: DISABLE INSTALL MEDIUM
|
|
||||||
|
|
||||||
# reboot from updated system
|
|
||||||
/home/admin/_cache.sh set state "reboot"
|
|
||||||
/home/admin/_cache.sh set message "restarting system"
|
|
||||||
shutdown -r now
|
|
||||||
exit 0
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
# TODO REMOVE
|
|
||||||
/home/admin/_cache.sh set state "waitsetup"
|
|
||||||
/home/admin/_cache.sh set message "bootstrap-debug-exit"
|
|
||||||
exit 1
|
|
||||||
|
|
||||||
#############################################
|
#############################################
|
||||||
# PROVISION PROCESS
|
# PROVISION PROCESS
|
||||||
#############################################
|
#############################################
|
||||||
|
|
||||||
# refresh data from info file
|
# set flag that provision process was started on thsi system
|
||||||
source <(/home/admin/_cache.sh get state setupPhase)
|
|
||||||
echo "# PROVISION PROCESS with setupPhase(${setupPhase})" >> ${logFile}
|
|
||||||
|
|
||||||
# mark system on sd card as in setup process
|
|
||||||
echo "the provision process was started but did not finish yet" > /home/admin/provision.flag
|
echo "the provision process was started but did not finish yet" > /home/admin/provision.flag
|
||||||
|
|
||||||
# get fresh data from setup file & data drive
|
if [ "${scenario}" = "setup" ]; then
|
||||||
source <(/home/admin/config.scripts/blitz.datadrive.sh status)
|
|
||||||
|
|
||||||
# special setup tasks (triggered by api/webui thru setupfile)
|
|
||||||
|
|
||||||
# FORMAT DATA DRIVE
|
|
||||||
if [ "${formatHDD}" = "1" ]; then
|
|
||||||
echo "# special setup tasks: FORMAT DATA DRIVE" >> ${logFile}
|
|
||||||
|
|
||||||
# check if there is a flag set on sd card boot section to format as btrfs (experimental)
|
|
||||||
filesystem="ext4"
|
|
||||||
flagBTRFS=$(ls ${raspi_bootdir}/btrfs* 2>/dev/null | grep -c btrfs)
|
|
||||||
if [ "${flagBTRFS}" != "0" ]; then
|
|
||||||
echo "Found BTRFS flag ---> formatting with experimental BTRFS filesystem" >> ${logFile}
|
|
||||||
filesystem="btrfs"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# run formatting
|
|
||||||
error=""
|
|
||||||
/home/admin/_cache.sh set state "formathdd"
|
|
||||||
echo "Running Format: filesystem(${filesystem}) hddCandidate(${hddCandidate})" >> ${logFile}
|
|
||||||
source <(/home/admin/config.scripts/blitz.datadrive.sh format ${filesystem} ${hddCandidate})
|
|
||||||
if [ "${error}" != "" ]; then
|
|
||||||
echo "FAIL ON FORMATTING THE DRIVE:" >> ${logFile}
|
|
||||||
echo "${error}" >> ${logFile}
|
|
||||||
echo "Please report as issue on the raspiblitz github." >> ${logFile}
|
|
||||||
/home/admin/_cache.sh set state "errorHDD"
|
|
||||||
/home/admin/_cache.sh set message "Fail Format (${filesystem})"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
/home/admin/_cache.sh set setupPhase "setup"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# CLEAN DRIVE & KEEP BLOCKCHAIN
|
|
||||||
if [ "${cleanHDD}" = "1" ]; then
|
|
||||||
echo "# special setup tasks: CLEAN DRIVE & KEEP BLOCKCHAIN" >> ${logFile}
|
|
||||||
|
|
||||||
# when blockchain comes from another node migrate data first
|
|
||||||
if [ "${hddGotMigrationData}" != "" ]; then
|
|
||||||
clear
|
|
||||||
echo "Migrating Blockchain of ${hddGotMigrationData}'" >> ${logFile}
|
|
||||||
source <(/home/admin/config.scripts/blitz.migration.sh migration-${hddGotMigrationData})
|
|
||||||
if [ "${error}" != "0" ]; then
|
|
||||||
echo "MIGRATION OF BLOCKHAIN FAILED: ${err}" >> ${logFile}
|
|
||||||
echo "Format data disk on laptop & recover funds with fresh sd card using seed words + static channel backup." >> ${logFile}
|
|
||||||
/home/admin/_cache.sh set state "errorHDD"
|
|
||||||
/home/admin/_cache.sh set message "Fail Migrate Blockchain (${hddGotMigrationData})"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
fi
|
|
||||||
|
|
||||||
# delete everything but blockchain
|
|
||||||
echo "Deleting everything on HDD/SSD while keeping blockchain ..." >> ${logFile}
|
|
||||||
/home/admin/config.scripts/blitz.datadrive.sh tempmount 1>/dev/null 2>/dev/null
|
|
||||||
/home/admin/config.scripts/blitz.datadrive.sh clean all -keepblockchain >> ${logFile}
|
|
||||||
if [ "${error}" != "" ]; then
|
|
||||||
echo "CLEANING HDD FAILED:" >> ${logFile}
|
|
||||||
echo "${error}" >> ${logFile}
|
|
||||||
echo "Please report as issue on the raspiblitz github." >> ${logFile}
|
|
||||||
/home/admin/_cache.sh set state "errorHDD"
|
|
||||||
/home/admin/_cache.sh set message "Fail Cleaning HDD"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
/home/admin/config.scripts/blitz.datadrive.sh unmount >> ${logFile}
|
|
||||||
/home/admin/_cache.sh set setupPhase "setup"
|
|
||||||
|
|
||||||
sleep 2
|
|
||||||
|
|
||||||
fi
|
|
||||||
|
|
||||||
source <(/home/admin/_cache.sh get state setupPhase)
|
|
||||||
if [ "${setupPhase}" = "setup" ]; then
|
|
||||||
|
|
||||||
echo "# CREATING raspiblitz.conf from your setup choices" >> ${logFile}
|
echo "# CREATING raspiblitz.conf from your setup choices" >> ${logFile}
|
||||||
if [ "${network}" = "" ]; then
|
|
||||||
network="bitcoin"
|
|
||||||
fi
|
|
||||||
if [ "${chain}" = "" ]; then
|
|
||||||
chain="main"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# source the raspiblitz version
|
# source the raspiblitz version
|
||||||
source /home/admin/_version.info
|
source /home/admin/_version.info
|
||||||
@@ -939,13 +834,21 @@ exit 1
|
|||||||
echo "raspiBlitzVersion='${codeVersion}'" >> $TEMPCONFIGFILE
|
echo "raspiBlitzVersion='${codeVersion}'" >> $TEMPCONFIGFILE
|
||||||
echo "lcdrotate='1'" >> $TEMPCONFIGFILE
|
echo "lcdrotate='1'" >> $TEMPCONFIGFILE
|
||||||
echo "lightning='${lightning}'" >> $TEMPCONFIGFILE
|
echo "lightning='${lightning}'" >> $TEMPCONFIGFILE
|
||||||
echo "network='${network}'" >> $TEMPCONFIGFILE
|
echo "network='bitcoin'" >> $TEMPCONFIGFILE
|
||||||
echo "chain='${chain}'" >> $TEMPCONFIGFILE
|
echo "chain='main'" >> $TEMPCONFIGFILE
|
||||||
echo "hostname='${hostname}'" >> $TEMPCONFIGFILE
|
echo "hostname='${hostname}'" >> $TEMPCONFIGFILE
|
||||||
echo "runBehindTor='on'" >> $TEMPCONFIGFILE
|
echo "runBehindTor='on'" >> $TEMPCONFIGFILE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# make sure HDD is mounted (could be freshly formatted by user on last loop)
|
/home/admin/config.scripts/blitz.data.sh mount >> ${logFile}
|
||||||
|
if [ $? -eq 1 ]; then
|
||||||
|
echo "FAIL: blitz.data.sh mount failed" >> ${logFile}
|
||||||
|
/home/admin/_cache.sh set state "error"
|
||||||
|
/home/admin/_cache.sh set message "blitz.data.sh mount failed"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# make sure STORAGE is mounted (could be freshly formatted by user on last loop)
|
||||||
source <(/home/admin/config.scripts/blitz.datadrive.sh status)
|
source <(/home/admin/config.scripts/blitz.datadrive.sh status)
|
||||||
echo "Temp mounting (2) data drive (hddFormat='${hddFormat}')" >> ${logFile}
|
echo "Temp mounting (2) data drive (hddFormat='${hddFormat}')" >> ${logFile}
|
||||||
source <(/home/admin/config.scripts/blitz.datadrive.sh tempmount)
|
source <(/home/admin/config.scripts/blitz.datadrive.sh tempmount)
|
||||||
|
Reference in New Issue
Block a user