diff --git a/home.admin/setup.scripts/dialogLightningWallet-cln.sh b/home.admin/setup.scripts/dialogLightningWallet-cln.sh new file mode 100644 index 000000000..650c8d144 --- /dev/null +++ b/home.admin/setup.scripts/dialogLightningWallet-cln.sh @@ -0,0 +1,146 @@ +# 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 +SETUPFILE="/var/cache/raspiblitz/temp/raspiblitz.setup" +source $SETUPFILE + +# flags for sub dialogs after choice +uploadRESCUE=0 +enterSEED=0 + +OPTIONS=() +OPTIONS+=(NEW "Setup a brand new Lightning Node (DEFAULT)") +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) + +if [ "${CHOICE}" == "NEW" ]; then + + # clear setup state from all fomer possible choices (previous loop) + sudo sed -i '/^setPasswordA=/d' $SETUPFILE + sudo sed -i '/^setPasswordB=/d' $SETUPFILE + sudo sed -i '/^setPasswordC=/d' $SETUPFILE + + # mark all passwords to be set at the end + echo "setPasswordA=1" >> $SETUPFILE + echo "setPasswordB=1" >> $SETUPFILE + echo "setPasswordC=1" >> $SETUPFILE + +elif [ "${CHOICE}" == "OLD" ]; then + + CHOICE="" + while [ "${CHOICESUB}" == "" ] + do + + # get more details what kind of old lightning wallet user has + OPTIONS=() + OPTIONS+=(CLNRESCUE "CLN tar.gz-Backupfile (BEST)") + OPTIONS+=(ONLYSEED "Only Seed Word List (FALLBACK)") + CHOICESUB=$(dialog --backtitle "RaspiBlitz" --clear --title "RECOVER CLN DATA & WALLET" --menu "Data you have to recover from?" 11 60 6 "${OPTIONS[@]}" 2>&1 >/dev/tty) + + if [ "${CHOICESUB}" == "CLNRESCUE" ]; then + + # just activate LND rescue upload + uploadRESCUE=1 + + # clear setup state from all fomer possible choices (previous loop) + sudo sed -i '/^setPasswordA=/d' $SETUPFILE + sudo sed -i '/^setPasswordB=/d' $SETUPFILE + sudo sed -i '/^setPasswordC=/d' $SETUPFILE + + # dont set password c anymore - mark the rest + echo "setPasswordA=1" >> $SETUPFILE + echo "setPasswordB=1" >> $SETUPFILE + + elif [ "${CHOICESUB}" == "ONLYSEED" ]; then + + # let people know about just seed backup + whiptail --title "IMPORTANT INFO" --yes-button "JUST SEED" --no-button "Go Back" --yesno " +Using JUST SEED WORDS will only recover your on-chain funds. +To recover also your channel funds a complete rescue-backup +from your old node would be recommended. + " 11 65 + + if [ $? -eq 1 ]; then + # when user wants to go back + CHOICESUB="" + else + # activate SEED input & SCB upload + enterSEED=1 + + # clear setup state from all fomer possible choices (previous loop) + sudo sed -i '/^setPasswordA=/d' $SETUPFILE + sudo sed -i '/^setPasswordB=/d' $SETUPFILE + sudo sed -i '/^setPasswordC=/d' $SETUPFILE + + # mark all passwords to be set at the end + echo "setPasswordA=1" >> $SETUPFILE + echo "setPasswordB=1" >> $SETUPFILE + echo "setPasswordC=1" >> $SETUPFILE + + fi + + else + # user cancel - signal to outside app by exit code (2 = submenu) + exit 2 + fi + + done + +else + # user cancel - signal to outside app by exit code (1 = mainmenu) + exit 1 +fi + +# UPLOAD LND RESCUE FILE dialog (if activated by dialogs above) +if [ ${uploadRESCUE} -eq 1 ]; then + + # run upload dialog and get result + _temp="/var/cache/raspiblitz/temp/.temp.tmp" + clear + echo "TODO: cln.backup.sh cln-import-gui" + sleep 8 + #/home/admin/config.scripts/cln.backup.sh cln-import-gui setup $_temp + source $_temp 2>/dev/null + sudo rm $_temp 2>/dev/null + + # if user canceled upload + if [ "${clnrescue}" == "" ]; then + # signal cancel to the calling script by exit code (3 = exit on lndrescue) + exit 3 + fi + + # clear setup state from all fomer possible choices (previous loop) + sudo sed -i '/^clnrescue=/d' $SETUPFILE + + # store result in setup state + echo "clnrescue='${lndrescue}'" >> $SETUPFILE +fi + +# INPUT LIGHTNING SEED dialog (if activated by dialogs above) +if [ ${enterSEED} -eq 1 ]; then + + # start seed input and get results + _temp="/var/cache/raspiblitz/.temp.tmp" + clear + 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 + sudo rm $_temp 2>/dev/null + + # if user canceled the seed input + if [ "${seedWords}" == "" ]; then + # signal cancel to the calling script by exit code (4 = exit on seedwords) + exit 4 + fi + + # clear setup state from all fomer possible choices (previous loop) + sudo sed -i '/^seedWords=/d' $SETUPFILE + sudo sed -i '/^seedPassword=/d' $SETUPFILE + + # write the seed data into the setup state + echo "seedWords='${seedWords}'" >> $SETUPFILE +fi \ No newline at end of file diff --git a/home.admin/setup.scripts/dialogLightningWallet.sh b/home.admin/setup.scripts/dialogLightningWallet-lnd.sh similarity index 100% rename from home.admin/setup.scripts/dialogLightningWallet.sh rename to home.admin/setup.scripts/dialogLightningWallet-lnd.sh diff --git a/home.admin/setup.scripts/setupDialogControl.sh b/home.admin/setup.scripts/setupDialogControl.sh index fb1ca9fe4..e48ea8aef 100755 --- a/home.admin/setup.scripts/setupDialogControl.sh +++ b/home.admin/setup.scripts/setupDialogControl.sh @@ -225,20 +225,37 @@ if [ "${setupPhase}" == "setup" ]; then # because password C not needed if LND rescue file is uploaded lightningWalletDone=0 + source ${SETUPFILE} + if [ "${lightning}" == "" ]; then lightningWalletDone=1; fi while [ "${lightningWalletDone}" == "0" ] do - echo "# Starting lightning wallet dialog ..." - /home/admin/setup.scripts/dialogLightningWallet.sh + if [ "${lightning}" == "lnd" ]; then - # only if dialog exited clean end loop - if [ "$?" == "0" ]; then + echo "# Starting lightning wallet dialog for LND ..." + /home/admin/setup.scripts/dialogLightningWallet-lnd.sh + dialogResult=$? + + elif [ "${lightning}" == "cln" ]; then + + echo "# Starting lightning wallet dialog for C-LIGHTNING ..." + /home/admin/setup.scripts/dialogLightningWallet-cln.sh + dialogResult=$? + + else + echo "FAIL: unkown lightning implementation (${lightning})" + lightningWalletDone=1 + sleep 8 + fi + + # break loop only if a clean exit + if [ "${dialogResult}" == "0" ]; then lightningWalletDone=1 fi # allow user to cancel to terminal on dialog main menu # all other cancels have other exit codes - if [ "$?" == "1" ]; then + if [ "${dialogResult}" == "1" ]; then echo "# you selected cancel - sending exit code 1" exit 1 fi