From 270440681936ce66f896e52b29c70c33f5351ae0 Mon Sep 17 00:00:00 2001 From: openoms <43343391+openoms@users.noreply.github.com> Date: Sat, 18 Dec 2021 22:07:37 +0000 Subject: [PATCH] Create CL wallet from seedwords before start (#2822) --- home.admin/00parallelMainnetServices.sh | 3 +++ home.admin/00settingsMenuBasics.sh | 5 +++- home.admin/config.scripts/cl.hsmtool.sh | 33 ++++++++++++++++++++++--- home.admin/config.scripts/cl.install.sh | 11 +++++++++ 4 files changed, 47 insertions(+), 5 deletions(-) diff --git a/home.admin/00parallelMainnetServices.sh b/home.admin/00parallelMainnetServices.sh index 3a0483701..482a48642 100644 --- a/home.admin/00parallelMainnetServices.sh +++ b/home.admin/00parallelMainnetServices.sh @@ -81,6 +81,9 @@ if [ "${cl}" != "${choice}" ]; then if [ "${choice}" = "on" ]; then if [ ${errorOnInstall} -eq 0 ]; then echo "# Successfully installed CL on $CHAIN" + # for mainnet only + # generate wallet from seedwords + /home/admin/config.scripts/cl.hsmtool.sh new $CHAIN else l1="# !!! FAIL on CL on $CHAIN install !!!" l2="# Try manual install on terminal after reboot with:" diff --git a/home.admin/00settingsMenuBasics.sh b/home.admin/00settingsMenuBasics.sh index d00a55f5e..f936446e2 100755 --- a/home.admin/00settingsMenuBasics.sh +++ b/home.admin/00settingsMenuBasics.sh @@ -418,11 +418,14 @@ if [ "${clNode}" != "${choice}" ]; then if [ "${choice}" = "on" ]; then echo "# turning ON" /home/admin/config.scripts/cl.install.sh on mainnet - sudo /home/admin/config.scripts/cl.install.sh display-seed mainnet + # generate wallet from seedwords or just display + /home/admin/config.scripts/cl.hsmtool.sh new mainnet if [ "${testnet}" == "on" ]; then + # no seed for testnet /home/admin/config.scripts/cl.install.sh on testnet fi if [ "${signet}" == "on" ]; then + # no seed for signet /home/admin/config.scripts/cl.install.sh on signet fi else diff --git a/home.admin/config.scripts/cl.hsmtool.sh b/home.admin/config.scripts/cl.hsmtool.sh index ee620a9aa..21910ebb7 100644 --- a/home.admin/config.scripts/cl.hsmtool.sh +++ b/home.admin/config.scripts/cl.hsmtool.sh @@ -17,7 +17,7 @@ if [ $# -lt 1 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ]||\ echo "cl.hsmtool.sh [new] [mainnet|testnet|signet] [?seedPassword]" echo "cl.hsmtool.sh [new-force] [mainnet|testnet|signet] [?seedPassword]" echo "There will be no seedPassword(passphrase) used by default" - echo "new-force will delete any old wallet and will work without dialog" + echo "new-force will backup the old wallet and will work without interaction" echo echo "cl.hsmtool.sh [seed] [mainnet|testnet|signet] [\"space-separated-seed-words\"] [?seedPassword]" echo "cl.hsmtool.sh [seed-force] [mainnet|testnet|signet] [\"space-separated-seed-words\"] [?seedPassword]" @@ -165,12 +165,37 @@ if [ "$1" = "new" ] || [ "$1" = "new-force" ] || [ "$1" = "seed" ] || [ "$1" = " # check/delete existing wallet if [ "$1" = "new-force" ] || [ "$1" = "seed-force" ]; then - echo "# deleting any old wallet ..." - sudo rm $hsmSecretPath 2>/dev/null + if sudo ls $hsmSecretPath 2>1 1>/dev/null; then + echo "# Moving the old wallet to backup" + now=$(date +"%Y_%m_%d_%H%M%S") + sudo mv $hsmSecretPath $hsmSecretPath.backup.${now} 2>/dev/null || exit 1 + fi else if sudo ls $hsmSecretPath 2>1 1>/dev/null; then echo "# The hsm_secret is already present at $hsmSecretPath." - exit 0 + if [ ${CHAIN} = "mainnet" ]; then + if sudo ls /home/bitcoin/.lightning/${CLNETWORK}/seedwords.info 2>1 1>/dev/null; then + echo "# There is a /home/bitcoin/.lightning/${CLNETWORK}/seedwords.info so don't create new" + # show seed + sudo /home/admin/config.scripts/cl.install.sh display-seed mainnet + exit 0 + else + # there should be no hsm_secret without seedwords.info, but protect this edge-case + whiptail --title " An hsm_secret is present " \ + --yes-button "New wallet" \ + --no-button "Keep no seed" \ + --yesno "The wallet was autogenerated by lightningd and there is no seedwords.info file.\nDo you want to generate a new wallet from seedwords?" 9 60 + if [ $? -eq 0 ]; then + echo "# yes-button -> New wallet" + echo "# Moving the old wallet to backup" + now=$(date +"%Y_%m_%d_%H%M%S") + sudo mv $hsmSecretPath $hsmSecretPath.backup.${now} 2>/dev/null || exit 1 + else + echo "# no-button -> Keep the hsm_secret" + exit 0 + fi + fi + fi fi fi diff --git a/home.admin/config.scripts/cl.install.sh b/home.admin/config.scripts/cl.install.sh index d067d78f2..bd7b09233 100644 --- a/home.admin/config.scripts/cl.install.sh +++ b/home.admin/config.scripts/cl.install.sh @@ -300,6 +300,17 @@ always-use-proxy=true sudo chown -R bitcoin:bitcoin /mnt/hdd/app-data/.lightning sudo chown -R bitcoin:bitcoin /home/bitcoin/ + ## Create a wallet from seedwords for mainnet + if [ ${CHAIN} = "mainnet" ]; then + hsmSecretPath="/home/bitcoin/.lightning/${CLNETWORK}/hsm_secret" + if sudo ls $hsmSecretPath; then + echo "# $hsmSecretPath is already present" + else + echo "Create a wallet from seedwords for mainnet" + /home/admin/config.scripts/cl.hsmtool.sh new-force mainnet + fi + fi + ################# # Backup plugin # #################