From 3a88ca57899e7a4bfbe106334208912f010b253b Mon Sep 17 00:00:00 2001 From: rootzoll Date: Sun, 12 Sep 2021 21:41:48 +0200 Subject: [PATCH] prepare lnd wallet creation if running as second --- home.admin/00settingsMenuBasics.sh | 1 + home.admin/_provision.setup.sh | 6 +- home.admin/_provision_.sh | 2 +- .../config.scripts/blitz.setpassword.sh | 2 +- home.admin/config.scripts/lnd.initwallet.py | 71 ++++++++++++------- home.admin/config.scripts/lnd.install.sh | 44 +++++++++++- 6 files changed, 94 insertions(+), 32 deletions(-) diff --git a/home.admin/00settingsMenuBasics.sh b/home.admin/00settingsMenuBasics.sh index 475676751..ac7745659 100755 --- a/home.admin/00settingsMenuBasics.sh +++ b/home.admin/00settingsMenuBasics.sh @@ -364,6 +364,7 @@ if [ "${lndNode}" != "${choice}" ]; then if [ "${choice}" = "on" ]; then echo "# turning ON" /home/admin/config.scripts/lnd.install.sh on mainnet + sudo /home/admin/config.scripts/lnd.install.sh display-seed mainnet if [ "${testnet}" == "on" ]; then /home/admin/config.scripts/lnd.install.sh on testnet fi diff --git a/home.admin/_provision.setup.sh b/home.admin/_provision.setup.sh index d2c51c65e..3b5f2813d 100755 --- a/home.admin/_provision.setup.sh +++ b/home.admin/_provision.setup.sh @@ -275,7 +275,7 @@ if [ "${lightning}" == "lnd" ]; then echo "WALLET --> SEED + SCB " >> ${logFile} sudo sed -i "s/^message=.*/message='LND Wallet (SEED & SCB)'/g" ${infoFile} - sudo /home/admin/config.scripts/lnd.initwallet.py scb ${passwordC} "${seedWords}" "${staticchannelbackup}" ${seedPassword} + sudo /home/admin/config.scripts/lnd.initwallet.py mainnet scb ${passwordC} "${seedWords}" "${staticchannelbackup}" ${seedPassword} if [ "${err}" != "" ]; then sed -i "s/^state=.*/state=error/g" ${infoFile} sed -i "s/^message=.*/message='setup: lnd wallet SCB failed'/g" ${infoFile} @@ -291,7 +291,7 @@ if [ "${lightning}" == "lnd" ]; then echo "WALLET --> SEED" >> ${logFile} sudo sed -i "s/^message=.*/message='LND Wallet (SEED)'/g" ${infoFile} - sudo /home/admin/config.scripts/lnd.initwallet.py seed ${passwordC} "${seedWords}" ${seedPassword} + sudo /home/admin/config.scripts/lnd.initwallet.py mainnet seed ${passwordC} "${seedWords}" ${seedPassword} if [ "${err}" != "" ]; then sed -i "s/^state=.*/state=error/g" ${infoFile} sed -i "s/^message=.*/message='setup: lnd wallet SEED failed'/g" ${infoFile} @@ -307,7 +307,7 @@ if [ "${lightning}" == "lnd" ]; then echo "WALLET --> NEW" >> ${logFile} sudo sed -i "s/^message=.*/message='LND Wallet (NEW)'/g" ${infoFile} - source <(sudo /home/admin/config.scripts/lnd.initwallet.py new ${passwordC}) + source <(sudo /home/admin/config.scripts/lnd.initwallet.py mainnet new ${passwordC}) if [ "${err}" != "" ]; then sed -i "s/^state=.*/state=error/g" ${infoFile} sed -i "s/^message=.*/message='setup: lnd wallet SEED failed'/g" ${infoFile} diff --git a/home.admin/_provision_.sh b/home.admin/_provision_.sh index 95901b0c4..49e02ebb6 100755 --- a/home.admin/_provision_.sh +++ b/home.admin/_provision_.sh @@ -786,7 +786,7 @@ if [ "${lightning}" == "lnd" ];then if [ "${passwordFlagExists}" == "1" ]; then echo "Found /mnt/hdd/passwordc.flag .. changing password" >> ${logFile} oldPasswordC=$(sudo cat /mnt/hdd/passwordc.flag) - sudo /home/admin/config.scripts/lnd.initwallet.py change-password "${oldPasswordC}" "${passwordC}" >> ${logFile} + sudo /home/admin/config.scripts/lnd.initwallet.py mainnet change-password "${oldPasswordC}" "${passwordC}" >> ${logFile} sudo shred -u /mnt/hdd/passwordc.flag else echo "No /mnt/hdd/passwordc.flag" >> ${logFile} diff --git a/home.admin/config.scripts/blitz.setpassword.sh b/home.admin/config.scripts/blitz.setpassword.sh index 5642064d7..177e2d590 100755 --- a/home.admin/config.scripts/blitz.setpassword.sh +++ b/home.admin/config.scripts/blitz.setpassword.sh @@ -365,7 +365,7 @@ elif [ "${abcd}" = "c" ]; then sleep 2 err="" - source <(sudo /home/admin/config.scripts/lnd.initwallet.py change-password $oldPassword $newPassword) + source <(sudo /home/admin/config.scripts/lnd.initwallet.py mainnet change-password $oldPassword $newPassword) if [ "${err}" != "" ]; then dialog --backtitle "RaspiBlitz - Setup" --msgbox "FAIL -> Was not able to change password\n\n${err}\n${errMore}" 10 52 clear diff --git a/home.admin/config.scripts/lnd.initwallet.py b/home.admin/config.scripts/lnd.initwallet.py index 6e6fcf54f..5759d3cca 100755 --- a/home.admin/config.scripts/lnd.initwallet.py +++ b/home.admin/config.scripts/lnd.initwallet.py @@ -15,10 +15,10 @@ if sys.version_info < (3, 0): # display config script info if len(sys.argv) <= 1 or sys.argv[1] in ["-h", "--help", "help"]: print("# creating or recovering the LND wallet") - print("# lnd.initwallet.py new [walletpassword] [?seedpassword]") - print("# lnd.initwallet.py seed [walletpassword] [\"seeds-words-seperated-spaces\"] [?seedpassword]") - print("# lnd.initwallet.py scb [walletpassword] [\"seeds-words-seperated-spaces\"] [filepathSCB] [?seedpassword]") - print("# lnd.initwallet.py change-password [walletpassword-old] [walletpassword-new]") + print("# lnd.initwallet.py new [mainnet|testnet|signet] [walletpassword] [?seedpassword]") + print("# lnd.initwallet.py seed [mainnet|testnet|signet] [walletpassword] [\"seeds-words-seperated-spaces\"] [?seedpassword]") + print("# lnd.initwallet.py scb [mainnet|testnet|signet] [walletpassword] [\"seeds-words-seperated-spaces\"] [filepathSCB] [?seedpassword]") + print("# lnd.initwallet.py change-password [mainnet|testnet|signet] [walletpassword-old] [walletpassword-new]") print("err='missing parameters'") sys.exit(1) @@ -166,15 +166,22 @@ def change_password(stub, wallet_password="", wallet_password_new=""): sys.exit(1) def parse_args(): + network = "" wallet_password = "" wallet_password_new = "" seed_words = "" seed_password = "" filepath_scb = "" + if len(sys.argv) > 2: + network = sys.argv[2] + else: + print("err='missing parameters'") + sys.exit(1) + if mode == "new": - if len(sys.argv) > 2: - wallet_password = sys.argv[2] + if len(sys.argv) > 3: + wallet_password = sys.argv[3] if len(wallet_password) < 8: print("err='wallet password is too short'") sys.exit(1) @@ -182,17 +189,17 @@ def parse_args(): print("err='missing parameters'") sys.exit(1) - if len(sys.argv) > 3: - seed_password = sys.argv[3] + if len(sys.argv) > 4: + seed_password = sys.argv[4] elif mode == "change-password": - if len(sys.argv) > 3: - wallet_password = sys.argv[2] + if len(sys.argv) > 4: + wallet_password = sys.argv[3] if len(wallet_password) < 8: print("err='wallet password is too short'") sys.exit(1) - wallet_password_new = sys.argv[3] + wallet_password_new = sys.argv[4] if len(wallet_password_new ) < 8: print("err='wallet password new is too short'") sys.exit(1) @@ -202,8 +209,8 @@ def parse_args(): elif mode == "seed" or mode == "scb": - if len(sys.argv) > 2: - wallet_password = sys.argv[2] + if len(sys.argv) > 3: + wallet_password = sys.argv[3] if len(wallet_password) < 8: print("err='wallet password is too short'") sys.exit(1) @@ -211,8 +218,8 @@ def parse_args(): print("err='not correct amount of parameter - missing wallet password'") sys.exit(1) - if len(sys.argv) > 3: - seed_word_str = sys.argv[3] + if len(sys.argv) > 4: + seed_word_str = sys.argv[4] seed_words = seed_word_str.split(" ") if len(seed_words) < 24: print("err='not 24 seed words separated by just spaces (surrounded with \")'") @@ -223,13 +230,13 @@ def parse_args(): if mode == "seed": - if len(sys.argv) > 4: - seed_password = sys.argv[4] + if len(sys.argv) > 5: + seed_password = sys.argv[5] elif mode == "scb": - if len(sys.argv) > 4: - filepath_scb = sys.argv[4] + if len(sys.argv) > 5: + filepath_scb = sys.argv[5] scb_file = Path(filepath_scb) if scb_file.is_file(): print("# OK SCB file exists") @@ -240,26 +247,40 @@ def parse_args(): print("err='not correct amount of parameter - missing seed filepathSCB'") sys.exit(1) - if len(sys.argv) > 5: - seed_password = sys.argv[4] + if len(sys.argv) > 6: + seed_password = sys.argv[5] else: print("err='unknown mode parameter - run without any parameters to see options'") sys.exit(1) - return wallet_password, seed_words, seed_password, filepath_scb, wallet_password_new + return network, wallet_password, seed_words, seed_password, filepath_scb, wallet_password_new def main(): + + network, wallet_password, seed_words, seed_password, file_path_scb, wallet_password_new = parse_args() + + grpcEndpoint="localhost:0" + if network == "mainnet": + grpcEndpoint="localhost:10009" + elif network == "testnet": + grpcEndpoint="localhost:11009" + elif network == "signet": + grpcEndpoint="localhost:13009" + print("err='lnd does not support signet yet'") + sys.exit(1) + else: + print("err='chain not supported'") + sys.exit(1) + os.environ['GRPC_SSL_CIPHER_SUITES'] = 'HIGH+ECDSA' cert = open('/mnt/hdd/lnd/tls.cert', 'rb').read() ssl_creds = grpc.ssl_channel_credentials(cert) - channel = grpc.secure_channel('localhost:10009', ssl_creds) + channel = grpc.secure_channel(grpcEndpoint, ssl_creds) stub = rpcstub.WalletUnlockerStub(channel) - wallet_password, seed_words, seed_password, file_path_scb, wallet_password_new = parse_args() - if mode == "new": print("# *** CREATING NEW LND WALLET ***") new(stub, wallet_password) diff --git a/home.admin/config.scripts/lnd.install.sh b/home.admin/config.scripts/lnd.install.sh index 96edb26ac..a3d617445 100644 --- a/home.admin/config.scripts/lnd.install.sh +++ b/home.admin/config.scripts/lnd.install.sh @@ -4,7 +4,7 @@ if [ $# -lt 2 ] || [ "$1" = "-h" ] || [ "$1" = "-help" ];then echo echo "Install or remove LND services on parallel chains" - echo "lnd.install.sh [on|off] [mainnet|testnet|signet]" + echo "lnd.install.sh [on|off|display-seed] [mainnet|testnet|signet]" echo exit 1 fi @@ -57,7 +57,6 @@ source /home/admin/raspiblitz.info if ! grep -Eq "^${netprefix}lnd=" /mnt/hdd/raspiblitz.conf; then echo "${netprefix}lnd=off" >> /mnt/hdd/raspiblitz.conf fi - source /mnt/hdd/raspiblitz.conf # switch on @@ -179,6 +178,47 @@ alias ${netprefix}lncli=\"sudo -u bitcoin /usr/local/bin/lncli\ exit 0 fi +if [ "$1" = "display-seed" ]; then + + # check if sudo + if [ "$EUID" -ne 0 ]; then + echo "Please run as root (with sudo)" + exit 1 + fi + + # get network and aliasses from second parameter (default mainnet) + displayNetwork=$2 + if [ "${displayNetwork}" == "" ]; then + displayNetwork="mainnet" + fi + + # check if seedword file exists + seedwordFile="/mnt/hdd/lnd/data/chain/${network}/${CHAIN}/seedwords.info" + echo "# seewordFile(${seedwordFile})" + seedwordFileExists=$(ls ${seedwordFile} 2>/dev/null | grep -c "seedwords.info") + echo "# seewordFileExists(${seewordFileExists})" + if [ "${seedwordFileExists}" == "1" ]; then + source ${seedwordFile} + #echo "# seedwords(${seedwords})" + #echo "# seedwords6x4(${seedwords6x4})" + ack=0 + while [ ${ack} -eq 0 ] + do + whiptail --title "LND ${displayNetwork} Wallet" \ + --msgbox "This is your LND ${displayNetwork} wallet seed. Store these numbered words in a safe location:\n\n${seedwords6x4}" 13 76 + whiptail --title "Please Confirm" --yes-button "Show Again" --no-button "CONTINUE" --yesno " Are you sure that you wrote down the word list?" 8 55 + if [ $? -eq 1 ]; then + ack=1 + fi + done + else + walletFile="/mnt/hdd/lnd/data/chain/${network}/${CHAIN}/wallet.db" + whiptail --title "LND ${displayNetwork} Wallet Info" --msgbox "Your LND ${displayNetwork} wallet was already created before - there are no seed words available.\n\nTo secure your wallet secret you can manually backup the file: ${walletFile}" 11 76 + fi + + exit 0 +fi + # switch off if [ "$1" = "0" ] || [ "$1" = "off" ]; then