From 6455934bfcc241ffe764f77732268858b1d55fde Mon Sep 17 00:00:00 2001 From: Christian Rotzoll Date: Fri, 26 Apr 2019 16:36:03 +0200 Subject: [PATCH] lnd.rescue handling SCB up and down --- home.admin/70initLND.sh | 55 ++++------------- home.admin/config.scripts/lnd.rescue.sh | 78 +++++++++++++++++++++++-- 2 files changed, 85 insertions(+), 48 deletions(-) diff --git a/home.admin/70initLND.sh b/home.admin/70initLND.sh index f19c017..9240504 100755 --- a/home.admin/70initLND.sh +++ b/home.admin/70initLND.sh @@ -227,7 +227,7 @@ if [ ${walletExists} -eq 0 ]; then exit 1 fi - # WRNING ON ONLY SEED + # WARNING ON ONLY SEED if [ "${CHOICE}" == "ONLYSEED" ]; then whiptail --title "IMPORTANT INFO" --yes-button "Continue" --no-button "Go Back" --yesno " Using JUST SEED WORDS will only recover your on-chain funds. @@ -325,50 +325,17 @@ or having a complete LND rescue-backup from your old node. # fi if [ "${CHOICE}" == "SEED+SCB" ]; then - # get the channel.backup file - gotFile=-1 - localip=$(ip addr | grep 'state UP' -A2 | tail -n1 | awk '{print $2}' | cut -f1 -d'/') - while [ ${gotFile} -lt 1 ] - do - - # show info - clear - sleep 1 - echo "**********************************" - echo "* UPLOAD THE channel.backup FILE *" - echo "**********************************" - echo - if [ ${gotFile} -eq -1 ]; then - echo "If you have the channel.backup file on your laptop or on" - echo "another server you can now upload it to the RaspiBlitz." - elif [ ${gotFile} -eq 0 ]; then - echo "NO channel.backup FOUND IN /home/admin" - echo "Please try upload again." - fi - echo - echo "To make upload open a new terminal and change," - echo "into the directory where your lnd-rescue file is and" - echo "COPY, PASTE AND EXECUTE THE FOLLOWING COMMAND:" - echo "scp ./channel.backup admin@${localip}:/home/admin/" - echo "" - echo "Use password A to authenticate file transfere." - echo "PRESS ENTER when upload is done. Enter x & ENTER to cancel." - - # wait user interaction - echo "Please upload file. Press ENTER to try again or (x & ENTER) to cancel." - read key - if [ "${key}" == "x" ]; then - /home/admin/70initLND.sh - exit 1 - fi - - # test upload - gotFile=$(ls /home/admin/channel.backup | grep -c 'channel.backup') - - done + # let lnd.rescue script do the upload process + /home/admin/config.scripts/lnd.rescue.sh scb-up - clear - echo "OK - channel.backup file found." + # check exit code of script + if [ $? -eq 1 ]; then + echo "USER CANCEL --> back to menu" + /home/admin/70initLND.sh + exit 1 + else + echo "FILE UPLOADED --> will ne checked/activated after wallet restore from seed" + fi fi ##### FALLBACK UNTIL config.scripts/lnd.initwallet.py WORKS diff --git a/home.admin/config.scripts/lnd.rescue.sh b/home.admin/config.scripts/lnd.rescue.sh index 8af2631..4f68d92 100755 --- a/home.admin/config.scripts/lnd.rescue.sh +++ b/home.admin/config.scripts/lnd.rescue.sh @@ -4,8 +4,15 @@ source /mnt/hdd/raspiblitz.conf # command info if [ $# -eq 0 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]; then - echo "small rescue script to to backup or restore" - echo "lnd.rescue.sh [backup|restore] [?no-download]" + echo "# small rescue script to to backup or restore LND data" + echo "# -> backup all LND data in a tar.gz file for download:" + echo "# lnd.rescue.sh backup [?no-download]" + echo "# -> upload a LND data tar.gz file to replace LND data:" + echo "# lnd.rescue.sh restore" + echo "# -> download the LND channel.backup file from SD card:" + echo "# lnd.rescue.sh scb-down" + echo "# -> upload the LND channel.backup to recover wallet:" + echo "# lnd.rescue.sh scb-up" exit 1 fi @@ -67,10 +74,10 @@ elif [ ${mode} = "restore" ]; then # RESTORE ################################ - echo "*** LND.RESCUE --> RESTORE" + echo "# LND.RESCUE --> RESTORE" echo "" - # delete old backups + # delete old backups rm /home/admin/lnd-rescue-*.tar.gz filename="" @@ -169,6 +176,69 @@ elif [ ${mode} = "restore" ]; then echo "Keep in mind that some channels maybe forced closed in the meanwhile." echo +elif [ ${mode} = "scb-down" ]; then + + echo + echo "****************************" + echo "* DOWNLOAD THE BACKUP FILE *" + echo "****************************" + echo + echo "RUN THE FOLLOWING COMMAND ON YOUR LAPTOP IN NEW TERMINAL:" + echo "scp -r admin@${localip}:/home/admin/.lnd/data/chain/${network}/${chain}net/channel.backup ./" + echo "" + echo "Use password A to authenticate file transfere." + echo + echo "NOTE: Use this file when setting up a fresh RaspiBlitz by choosing" + echo "option OLD WALLET and then SCB+SEED -> Seed & channel.backup file" + echo "Will just recover on-chain & channel-funds, but closing all channels" + +elif [ ${mode} = "scb-up" ]; then + + gotFile=-1 + while [ ${gotFile} -lt 1 ] + do + + # show info + clear + sleep 1 + echo "**********************************" + echo "* UPLOAD THE channel.backup FILE *" + echo "**********************************" + echo + if [ ${gotFile} -eq -1 ]; then + echo "If you have the channel.backup file on your laptop or on" + echo "another server you can now upload it to the RaspiBlitz." + elif [ ${gotFile} -eq 0 ]; then + echo "NO channel.backup FOUND IN /home/admin" + echo "Please try upload again." + fi + echo + echo "To make upload open a new terminal and change," + echo "into the directory where your lnd-rescue file is and" + echo "COPY, PASTE AND EXECUTE THE FOLLOWING COMMAND:" + echo "scp ./channel.backup admin@${localip}:/home/admin/" + echo "" + echo "Use password A to authenticate file transfere." + echo "PRESS ENTER when upload is done. Enter x & ENTER to cancel." + + # wait user interaction + echo "Please upload file. Press ENTER to try again or (x & ENTER) to cancel." + read key + if [ "${key}" == "x" ]; then + # EXIT with CODE 1 --> USER CANCEL + echo "# CANCEL upload" + exit 1 + fi + + # test upload + gotFile=$(ls /home/admin/channel.backup | grep -c 'channel.backup') + + done + + # EXIT with CODE 1 --> FILE UPLOADED + echo "# OK channel.backup uploaded" + exit 0 + else echo "unknown parameter '${mode}' - exit" fi \ No newline at end of file