mirror of
https://github.com/raspiblitz/raspiblitz.git
synced 2025-09-20 13:02:21 +02:00
cln.backup.sh cln-import
This commit is contained in:
@@ -32,7 +32,7 @@ if [ ${mode} = "cln-export" ]; then
|
|||||||
|
|
||||||
# stop LND
|
# stop LND
|
||||||
echo "# Stopping cln..."
|
echo "# Stopping cln..."
|
||||||
sudo systemctl stop lightningd
|
sudo systemctl stop lightningd 1>/dev/null
|
||||||
sleep 5
|
sleep 5
|
||||||
echo "# OK"
|
echo "# OK"
|
||||||
echo
|
echo
|
||||||
@@ -104,6 +104,172 @@ if [ ${mode} = "cln-export-gui" ]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
################################
|
||||||
|
# CLN RESCUE FILE - IMPORT
|
||||||
|
################################
|
||||||
|
|
||||||
|
if [ ${mode} = "cln-import" ]; then
|
||||||
|
|
||||||
|
# 2nd PARAMETER: file to import (expect that the file was valid checked from calling script)
|
||||||
|
filename=$2
|
||||||
|
if [ "${filename}" == "" ]; then
|
||||||
|
echo "error='filename missing'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fileExists=$(sudo ls ${filename} 2>/dev/null | grep -c "${filename}")
|
||||||
|
if [ "${fileExists}" != "1" ]; then
|
||||||
|
echo "error='filename not found'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# stop LND
|
||||||
|
echo "# stopping cln..."
|
||||||
|
sudo systemctl stop lightningd 1>/dev/null
|
||||||
|
sleep 5
|
||||||
|
|
||||||
|
# clean DIR
|
||||||
|
echo "# cleaning old CLN data ..."
|
||||||
|
sudo rm -r /mnt/hdd/app-data/.lightning/* 1>/dev/null 2>/dev/null
|
||||||
|
|
||||||
|
# unpack zip
|
||||||
|
echo "# restoring CLN data from ${filename} ..."
|
||||||
|
sudo tar -xf ${filename} -C / 1>/dev/null
|
||||||
|
sudo chown -R bitcoin:bitcoin /mnt/hdd/app-data/.lightning 1>/dev/null
|
||||||
|
|
||||||
|
echo "# DONE - lightningd service is still stopped - start manually with command:"
|
||||||
|
echo "# sudo systemctl start lightningd"
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${mode} = "cln-import-gui" ]; then
|
||||||
|
|
||||||
|
# get by second parameter if this call if happening during setup or production
|
||||||
|
scenario=$2
|
||||||
|
if [ "${scenario}" != "setup" ] && [ "${scenario}" != "production" ]; then
|
||||||
|
echo "error='mising parameter'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# scenario setup needs a 3rd parameter - the RESULTFILE to store results in
|
||||||
|
if [ "${scenario}" == "setup" ]; then
|
||||||
|
RESULTFILE=$3
|
||||||
|
if [ "${RESULTFILE}" == "" ]; then
|
||||||
|
echo "error='mising parameter'"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# determine password info based on scenario
|
||||||
|
if [ "${scenario}" == "setup" ]; then
|
||||||
|
passwordInfo="password 'raspiblitz'"
|
||||||
|
else
|
||||||
|
passwordInfo="your Password A"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# get defaultUploadPath, localIP, etc
|
||||||
|
source <(sudo /home/admin/config.scripts/blitz.upload.sh prepare-upload)
|
||||||
|
|
||||||
|
filename=""
|
||||||
|
while [ "${filename}" == "" ]
|
||||||
|
do
|
||||||
|
clear
|
||||||
|
echo "**************************"
|
||||||
|
echo "* UPLOAD THE RESCUE FILE *"
|
||||||
|
echo "**************************"
|
||||||
|
echo "If you have a cln-rescue backup file on your laptop you can now"
|
||||||
|
echo "upload it and restore your latest C-Lightning state."
|
||||||
|
echo
|
||||||
|
echo "CAUTION: Dont restore outdated states - risk of loosing funds!"
|
||||||
|
echo
|
||||||
|
echo "To make upload open a new terminal on your laptop,"
|
||||||
|
echo "change into the directory where your cln-rescue file is and"
|
||||||
|
echo "COPY, PASTE AND EXECUTE THE FOLLOWING COMMAND:"
|
||||||
|
echo "scp -r ./cln-rescue-*.tar.gz ${defaultUploadUser}@${localip}:${defaultUploadPath}/"
|
||||||
|
echo ""
|
||||||
|
echo "Use ${passwordInfo} 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 cln-rescue)
|
||||||
|
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}"
|
||||||
|
echo "PRESS ENTER to continue & retry ... or 'x'+ ENTER to cancel"
|
||||||
|
read keyRetry
|
||||||
|
elif [ "${error}" == "multiple" ]; then
|
||||||
|
echo "!! WARNING !!"
|
||||||
|
echo "There are multiple cln-rescue files in directory ${defaultUploadPath}"
|
||||||
|
echo "Make sure you upload only one tar.gz-file and start again."
|
||||||
|
echo "PRESS ENTER to continue & retry ... or 'x'+ ENTER to cancel"
|
||||||
|
read keyRetry
|
||||||
|
elif [ "${error}" == "invalid" ]; then
|
||||||
|
echo "!! WARNING !!"
|
||||||
|
echo "The file uploaded is not a valid (complete upload failed or not correct file)."
|
||||||
|
echo "PRESS ENTER to continue & retry ... or 'x'+ ENTER to cancel"
|
||||||
|
read keyRetry
|
||||||
|
else
|
||||||
|
# create no result file and exit
|
||||||
|
echo "!! WARNING !! Unknown State (report to devs)"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "${keyRetry}" == "x" ] || [ "${keyRetry}" == "X" ] || [ "${keyRetry}" == "'x'" ]; then
|
||||||
|
# create no result file and exit
|
||||||
|
echo "# USER CANCEL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
done
|
||||||
|
|
||||||
|
# in setup scenario the final import is happening during provison
|
||||||
|
if [ "${scenario}" == "setup" ]; then
|
||||||
|
# just add lndrescue filename to give file
|
||||||
|
echo "# result in: ${RESULTFILE} (remember to make clean delete once processed)"
|
||||||
|
echo "clnrescue='${filename}'" >> $RESULTFILE
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
# in production now start restoring LND data based on file
|
||||||
|
source /mnt/hdd/raspiblitz.conf
|
||||||
|
|
||||||
|
# ask security question before deleting old wallet
|
||||||
|
echo "WARNING: This will delete/overwrite the C-Lightning state/funds of this RaspiBlitz."
|
||||||
|
echo
|
||||||
|
echo "Write the word 'override' and press ENTER to CONTINUE:"
|
||||||
|
read securityInput
|
||||||
|
if [ "${securityInput}" != "override" ] && [ "${securityInput}" != "'override'" ]; then
|
||||||
|
echo
|
||||||
|
echo "CANCELED import of uploaded rescue file"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo
|
||||||
|
|
||||||
|
# run import process
|
||||||
|
echo "OK deleting old CLN data & restoring imported rescue file ..."
|
||||||
|
source <(sudo /home/admin/config.scripts/cln.backup.sh cln-import ${filename})
|
||||||
|
|
||||||
|
# TODO: check if update of CLN is needed (see detailes in cln-import) for edge case
|
||||||
|
|
||||||
|
# TODO: auto-unlock for c-lightning?
|
||||||
|
# turn off auto-unlock if activated because password c might now change
|
||||||
|
# if [ "${autoUnlock}" == "on" ]; then
|
||||||
|
# /home/admin/config.scripts/cln.autounlock.sh off
|
||||||
|
# fi
|
||||||
|
|
||||||
|
# restarting lnd & give final info
|
||||||
|
sudo systemctl start lightningd
|
||||||
|
echo "DONE - lightningd is now restarting .. Password C is now like within your rescue file"
|
||||||
|
echo "Check that CLN is starting up correctly and your old channel & funds are restored."
|
||||||
|
echo "Take into account that some channels might have been force closed in the meanwhile."
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
####################################
|
####################################
|
||||||
# SEED WORDS - GUI PARTS
|
# SEED WORDS - GUI PARTS
|
||||||
####################################
|
####################################
|
||||||
|
@@ -507,7 +507,7 @@ if [ ${mode} = "seed-import-gui" ]; then
|
|||||||
sudo chown admin:admin /var/cache/raspiblitz/.seed.tmp
|
sudo chown admin:admin /var/cache/raspiblitz/.seed.tmp
|
||||||
|
|
||||||
# dialog to enter
|
# dialog to enter
|
||||||
dialog --backtitle "RaspiBlitz - LND Recover" --inputbox "Please enter/paste the SEED WORD LIST:\n(just the words, seperated by spaces, in correct order as numbered)" 9 78 2>/var/cache/raspiblitz/.seed.tmp
|
dialog --backtitle "RaspiBlitz - Seed Recover" --inputbox "Please enter/paste the SEED WORD LIST:\n(just the words, seperated by spaces, in correct order as numbered)" 9 78 2>/var/cache/raspiblitz/.seed.tmp
|
||||||
wordstring=$(cat /var/cache/raspiblitz/.seed.tmp | sed 's/[^a-zA-Z0-9 ]//g')
|
wordstring=$(cat /var/cache/raspiblitz/.seed.tmp | sed 's/[^a-zA-Z0-9 ]//g')
|
||||||
sudo shred -u /var/cache/raspiblitz/.seed.tmp 2>/dev/null
|
sudo shred -u /var/cache/raspiblitz/.seed.tmp 2>/dev/null
|
||||||
echo "processing ..."
|
echo "processing ..."
|
||||||
@@ -564,7 +564,7 @@ wordone wordtweo wordthree ...
|
|||||||
dialog --title "SEED PASSWORD" --yes-button "No extra Password" --no-button "Yes" --yesno "
|
dialog --title "SEED PASSWORD" --yes-button "No extra Password" --no-button "Yes" --yesno "
|
||||||
Are your seed words protected by an extra password?
|
Are your seed words protected by an extra password?
|
||||||
|
|
||||||
During wallet creation LND offers to set an extra password
|
During wallet creation its an option to set an extra password
|
||||||
to protect the seed words. Most users did not set this.
|
to protect the seed words. Most users did not set this.
|
||||||
" 11 65
|
" 11 65
|
||||||
if [ $? -eq 1 ]; then
|
if [ $? -eq 1 ]; then
|
||||||
|
@@ -14,7 +14,7 @@ enterSEED=0
|
|||||||
OPTIONS=()
|
OPTIONS=()
|
||||||
OPTIONS+=(NEW "Setup a brand new Lightning Node (DEFAULT)")
|
OPTIONS+=(NEW "Setup a brand new Lightning Node (DEFAULT)")
|
||||||
OPTIONS+=(OLD "I had an old Node I want to recover/restore")
|
OPTIONS+=(OLD "I had an old Node I want to recover/restore")
|
||||||
CHOICE=$(dialog --backtitle "RaspiBlitz" --clear --title "LND Setup" --menu "LND Data & Wallet" 11 60 6 "${OPTIONS[@]}" 2>&1 >/dev/tty)
|
CHOICE=$(dialog --backtitle "RaspiBlitz" --clear --title "C-Lightning Setup" --menu "C-Lightning Data & Wallet" 11 60 6 "${OPTIONS[@]}" 2>&1 >/dev/tty)
|
||||||
|
|
||||||
if [ "${CHOICE}" == "NEW" ]; then
|
if [ "${CHOICE}" == "NEW" ]; then
|
||||||
|
|
||||||
@@ -100,9 +100,7 @@ if [ ${uploadRESCUE} -eq 1 ]; then
|
|||||||
# run upload dialog and get result
|
# run upload dialog and get result
|
||||||
_temp="/var/cache/raspiblitz/temp/.temp.tmp"
|
_temp="/var/cache/raspiblitz/temp/.temp.tmp"
|
||||||
clear
|
clear
|
||||||
echo "TODO: cln.backup.sh cln-import-gui"
|
/home/admin/config.scripts/cln.backup.sh cln-import-gui setup $_temp
|
||||||
sleep 8
|
|
||||||
#/home/admin/config.scripts/cln.backup.sh cln-import-gui setup $_temp
|
|
||||||
source $_temp 2>/dev/null
|
source $_temp 2>/dev/null
|
||||||
sudo rm $_temp 2>/dev/null
|
sudo rm $_temp 2>/dev/null
|
||||||
|
|
||||||
@@ -124,10 +122,7 @@ if [ ${enterSEED} -eq 1 ]; then
|
|||||||
|
|
||||||
# start seed input and get results
|
# start seed input and get results
|
||||||
_temp="/var/cache/raspiblitz/.temp.tmp"
|
_temp="/var/cache/raspiblitz/.temp.tmp"
|
||||||
clear
|
/home/admin/config.scripts/cln.backup.sh seed-import-gui $_temp
|
||||||
echo "TODO: cln.backup.sh seed-import-gui"
|
|
||||||
sleep 8
|
|
||||||
#/home/admin/config.scripts/cln.backup.sh seed-import-gui $_temp
|
|
||||||
source $_temp 2>/dev/null
|
source $_temp 2>/dev/null
|
||||||
sudo rm $_temp 2>/dev/null
|
sudo rm $_temp 2>/dev/null
|
||||||
|
|
||||||
@@ -143,4 +138,6 @@ if [ ${enterSEED} -eq 1 ]; then
|
|||||||
|
|
||||||
# write the seed data into the setup state
|
# write the seed data into the setup state
|
||||||
echo "seedWords='${seedWords}'" >> $SETUPFILE
|
echo "seedWords='${seedWords}'" >> $SETUPFILE
|
||||||
|
echo "seedPassword='${seedPassword}'" >> $SETUPFILE
|
||||||
|
|
||||||
fi
|
fi
|
Reference in New Issue
Block a user