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

176 lines
6 KiB
Bash
Raw Normal View History

2021-05-01 00:23:49 +02:00
#!/bin/bash
2021-05-03 14:00:01 +02:00
# TODO: also the raspiblitz-migration & other-node-migration might need to be adapted to work with an already mounted HDD later
2021-05-01 00:23:49 +02:00
2021-05-03 14:00:01 +02:00
# get basic system information
# these are the same set of infos the WebGUI dialog/controler has
2021-05-01 00:23:49 +02:00
source /home/admin/raspiblitz.info
2021-05-03 14:00:01 +02:00
# 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:32:36 +02:00
source $SETUPFILE
2021-05-01 00:23:49 +02:00
2021-05-03 14:00:01 +02:00
#########################
# Parameters
# this is useful for testing the dialog outside of the setup process
# normally migrationOS & migrationVersion are provided by raspiblitz.info or raspiblitz.setup
2021-05-01 00:23:49 +02:00
2021-05-03 14:00:01 +02:00
# 1st PARAMATER (optional): [raspiblitz|mynode|umbrel]
if [ "${migrationOS}" == "" ]; then
migrationOS="$1"
fi
2021-05-01 00:23:49 +02:00
2021-05-03 14:00:01 +02:00
# 2nd PARAMATER (optional): the version of the former fullnode OS if available
if [ "${migrationVersion}" == "" ]; then
migrationVersion="$2"
fi
# check parameter values
2021-05-01 01:08:59 +02:00
if [ "${migrationOS}" != "raspiblitz" ] && [ "${migrationOS}" != "mynode" ] && [ "${migrationOS}" != "umbrel" ]; then
2021-05-03 14:00:01 +02:00
echo "# FAIL: the given migrationOS '${migrationOS}' is not supported yet"
2021-05-01 00:23:49 +02:00
exit 1
fi
####################################################
# RASPIBLITZ
# migrating from other hardware with migration file
####################################################
if [ "${migrationOS}" == "raspiblitz" ]; then
2021-05-02 00:50:00 +02:00
# get defaultUploadPath, localIP, etc
2021-05-02 01:35:28 +02:00
source <(sudo /home/admin/config.scripts/blitz.upload.sh prepare-upload)
filename=""
while [ "${filename}" == "" ]
do
clear
echo "*****************************"
echo "* UPLOAD THE MIGRATION FILE *"
echo "*****************************"
echo "If you have a migration file on your laptop you can now"
echo "upload it and restore on the new HDD/SSD."
echo
echo "ON YOUR LAPTOP open a new terminal and change into"
echo "the directory where your migration file is and"
echo "COPY, PASTE AND EXECUTE THE FOLLOWING COMMAND:"
echo "scp -r ./raspiblitz-*.tar.gz ${defaultUploadUser}@${localip}:${defaultUploadPath}/"
echo ""
echo "Use password 'raspiblitz' to authenticate file transfer."
echo "PRESS ENTER when upload is done."
read key
# check upload (will return filename or error)
source <(sudo /home/admin/config.scripts/blitz.upload.sh check-upload migration)
if [ "${filename}" != "" ]; then
echo "OK - File found: ${filename}"
echo "PRESS ENTER to continue."
read key
elif [ "${error}" == "not-found" ]; then
echo "!! WARNING !!"
echo "There was no upload found in ${defaultUploadPath}"
2021-05-03 15:54:45 +02:00
echo "PRESS ENTER to continue & retry ... or 'x'+ ENTER to cancel"
read keyRetry
2021-05-02 01:35:28 +02:00
elif [ "${error}" == "multiple" ]; then
echo "!! WARNING !!"
echo "There are multiple lnd-rescue files in directory ${defaultUploadPath}"
echo "Make sure you upload only one tar.gz-file and start again."
2021-05-03 15:54:45 +02:00
echo "PRESS ENTER to continue & retry ... or 'x'+ ENTER to cancel"
read keyRetry
2021-05-02 01:35:28 +02:00
elif [ "${error}" == "invalid" ]; then
echo "!! WARNING !!"
echo "The file uploaded is not a valid (complete upload failed or not correct file)."
2021-05-03 15:54:45 +02:00
echo "PRESS ENTER to continue & retry ... or 'x'+ ENTER to cancel"
read keyRetry
2021-05-02 01:35:28 +02:00
else
2021-05-03 15:54:45 +02:00
# create no result file and exit
2021-05-03 14:00:01 +02:00
echo "!! WARNING !! Unknown State (report to devs) error(${error})"
2021-05-02 01:35:28 +02:00
exit 1
fi
2021-05-03 15:54:45 +02:00
if [ "${keyRetry}" == "x" ] || [ "${keyRetry}" == "X" ] || [ "${keyRetry}" == "'x'" ]; then
# create no result file and exit
echo "# USER CANCEL"
exit 1
fi
2021-05-02 01:35:28 +02:00
done
2021-05-01 00:23:49 +02:00
2021-05-03 14:00:01 +02:00
# migration OS & Version were already set earlier in setup process - now add migration filename
echo "migrationFile='${filename}'" >> $SETUPFILE
2021-05-01 00:23:49 +02:00
# user needs to reset password A
2021-05-03 14:00:01 +02:00
echo "setPasswordA=1" >> $SETUPFILE
exit 0
2021-05-01 00:23:49 +02:00
fi
####################################################
# UMBREL
# migrating from Umbrel to RaspiBlitz
####################################################
if [ "${migrationOS}" == "umbrel" ]; then
# infodialog
2021-05-01 00:36:12 +02:00
whiptail --title " UMBREL --> RASPIBLITZ " --yes-button "Start Migration" --no-button "Shutdown" --yesno "RaspiBlitz found data from UMBREL
2021-05-01 00:23:49 +02:00
You can migrate your blockchain & LND data (funds & channels) over to RaspiBlitz.
Please make sure to have your UMBREL seed words & static channel backup file (just in case). Also any data of additional apps you had installed on UMBREL might get lost.
Do you want to start migration to RaspiBlitz now?
" 16 58
2021-05-03 14:00:01 +02:00
if [ "$?" != "0" ]; then
# user cancel - signal by exit code
2021-05-01 00:23:49 +02:00
exit 1
fi
2021-05-03 14:00:01 +02:00
# write migration info
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
exit 0
2021-05-01 00:23:49 +02:00
fi
####################################################
# MYNODE
# migrating from myNode to RaspiBlitz
####################################################
if [ "${migrationOS}" == "mynode" ]; then
# infodialog
2021-05-01 00:36:12 +02:00
whiptail --title " MYNODE --> RASPIBLITZ " --yes-button "Start Migration" --no-button "Shutdown" --yesno "RaspiBlitz found data from MYNODE
2021-05-01 00:23:49 +02:00
You can migrate your blockchain & LND data (funds & channels) over to RaspiBlitz.
Please make sure to have your MYNODE seed words & static channel backup file (just in case). Also any data of additional apps you had installed on MYNODE might get lost.
Do you want to start migration to RaspiBlitz now?
" 16 58
2021-05-03 14:00:01 +02:00
if [ "$?" != "0" ]; then
# user cancel - signal by exit code
2021-05-01 00:23:49 +02:00
exit 1
fi
2021-05-03 14:00:01 +02:00
# write migration info
echo "migrationOS='mynode'" >> $SETUPFILE
echo "migrationVersion='${migrationVersion}'" >> $SETUPFILE
2021-05-01 00:23:49 +02:00
# user needs to reset password A
2021-05-03 14:00:01 +02:00
echo "setPasswordA=1" >> $SETUPFILE
echo "setPasswordB=1" >> $SETUPFILE
echo "setPasswordC=1" >> $SETUPFILE
exit 0
2021-05-01 00:23:49 +02:00
2021-05-01 01:06:55 +02:00
fi
2021-05-03 14:00:01 +02:00
echo "FAIL: Exited in unknown state from migration dialog."
exit 1