#2070 Implement myNode migration (#2187)

This commit is contained in:
/rootzoll 2021-04-17 01:09:06 +02:00 committed by GitHub
parent fd713adfb3
commit c6c8989f01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 205 additions and 73 deletions

View File

@ -76,8 +76,8 @@ Do you want to start migration to RaspiBlitz now?
echo "******************************************************"
echo "OK MIGRATION --> will now reboot and update/recover"
echo "******************************************************"
#sudo shutdown -h -r now
#sleep 100
sudo shutdown -h -r now
sleep 100
exit 0
else
echo "******************************************************"

View File

@ -5,8 +5,64 @@ source /home/admin/raspiblitz.info
source /mnt/hdd/raspiblitz.conf
# show password info dialog
resetAlsoPasswordB=$(sudo cat /mnt/hdd/bitcoin/bitcoin.conf | grep -c "rpcpassword=passwordB")
if [ ${resetAlsoPasswordB} -eq 0 ]; then
resetAlsoPasswordB=$(sudo cat /mnt/hdd/bitcoin/bitcoin.conf 2>/dev/null | grep -c "rpcpassword=passwordB")
resetAlsoPasswordC=$(sudo ls /mnt/hdd/passwordc.flag 2>/dev/null | grep -c ".flag")
if [ ${resetAlsoPasswordC} -gt 0 ]; then
# password A + B + C
dialog --backtitle "RaspiBlitz - Migration Setup" --msgbox "Your migration to RaspiBlitz is almost done.
You need to set a new Password A, B & C:
A) Main User Password (SSH, WebUI, ..)
B) RPC & APP Password (Additional Apps, ..)
C) Lightning Wallet Unlock Password
Follow Password Rules: Minimal of 8 chars,
no spaces and only special characters - or .
Write them down & store them in a safe place.
" 17 52
# call set password a script
sudo /home/admin/config.scripts/blitz.setpassword.sh a
dialog --backtitle "RaspiBlitz" --msgbox "OK - password A was set\nfor all users pi, admin, root & bitcoin" 6 52
sudo /home/admin/config.scripts/blitz.setpassword.sh b
dialog --backtitle "RaspiBlitz" --msgbox "OK - password B was set\nit will be used by additional apps you install." 6 52
oldPasswordC=$(sudo cat /mnt/hdd/passwordc.flag)
sudo /home/admin/config.scripts/blitz.setpassword.sh c $oldPasswordC
if [ "$?" != "0" ]; then
dialog --backtitle "RaspiBlitz - Setup" --msgbox "Please write down your Password C:\n${oldPasswordC}" 10 52
else
dialog --backtitle "RaspiBlitz" --msgbox "OK - password C was set\nuse it to unlock your Lightning Wallet after restarts." 6 52
fi
elif [ ${resetAlsoPasswordB} -gt 0 ]; then
# password A + B
dialog --backtitle "RaspiBlitz - Migration Setup" --msgbox "Your migration to RaspiBlitz is almost done.
You need to set a new Password A & B:
A) Main User Password (SSH, WebUI, ..)
B) RPC & APP Password (Additional Apps, ..)
Passwords C (for your Lightning wallet) stays to the password you set before.
Follow Password Rules: Minimal of 8 chars,
no spaces and only special characters - or .
Write them down & store them in a safe place.
" 17 52
# call set password a script
sudo /home/admin/config.scripts/blitz.setpassword.sh a
dialog --backtitle "RaspiBlitz" --msgbox "OK - password A was set\nfor all users pi, admin, root & bitcoin" 6 52
sudo /home/admin/config.scripts/blitz.setpassword.sh b
dialog --backtitle "RaspiBlitz" --msgbox "OK - password B was set\nit will be used by additional apps you install." 6 52
else
# just password A
dialog --backtitle "RaspiBlitz - Recover Setup" --msgbox "Your previous RaspiBlitz config was recovered.
@ -23,30 +79,11 @@ Write them down & store them in a safe place.
# call set password a script
sudo /home/admin/config.scripts/blitz.setpassword.sh a
else
# password A + B
dialog --backtitle "RaspiBlitz - Recover Setup" --msgbox "Your previous RaspiBlitz config was recovered.
You need to set a new Password A & B:
A) Main User Password (SSH, WebUI, ..)
B) RPC & APP Password (Additional Apps, ..)
Passwords C (for your Lightning wallet) stays to the password you set before.
Follow Password Rules: Minimal of 8 chars,
no spaces and only special characters - or .
Write them down & store them in a safe place.
" 17 52
# call set password a script
sudo /home/admin/config.scripts/blitz.setpassword.sh a
sudo /home/admin/config.scripts/blitz.setpassword.sh b
fi
# sucess info dialog
dialog --backtitle "RaspiBlitz" --msgbox "OK - password A was set\nfor all users pi, admin, root & bitcoin" 6 52
fi
# activate lnd & bitcoin service
echo "Enabling Services"
sudo systemctl daemon-reload

View File

@ -259,7 +259,7 @@ if [ "$1" = "status" ]; then
if [ ${isUmbrelHDD} -gt 0 ]; then
hddGotMigrationData="umbrel"
fi
isMyNodeHDD=$(sudo ls /mnt/storage/bitcoin/bitcoin.conf 2>/dev/null | grep -c '.conf')
isMyNodeHDD=$(sudo ls /mnt/storage/mynode/bitcoin/bitcoin.conf 2>/dev/null | grep -c '.conf')
if [ ${isMyNodeHDD} -gt 0 ]; then
hddGotMigrationData="mynode"
fi

View File

@ -89,7 +89,7 @@ migrate_raspiblitz_conf () {
echo "network=bitcoin" >> /home/admin/raspiblitz.conf
echo "chain=main" >> /home/admin/raspiblitz.conf
echo "hostname=${nodename}" >> /home/admin/raspiblitz.conf
echo "displayClass=hdmi" >> /home/admin/raspiblitz.conf
echo "displayClass=lcd" >> /home/admin/raspiblitz.conf
echo "lcdrotate=1" >> /home/admin/raspiblitz.conf
echo "runBehindTor=on" >> /home/admin/raspiblitz.conf
sudo mv /home/admin/raspiblitz.conf /mnt/hdd/raspiblitz.conf
@ -176,9 +176,6 @@ if [ "$1" = "migration-mynode" ]; then
source <(sudo /home/admin/config.scripts/blitz.datadrive.sh status)
echo "IMPORTANT TODO -> take care about lnd wallet password - see: https://btc21.de/bitcoin/raspiblitz-migration/"
exit 1
# can olny migrate unmonted data disks
if [ "${isMounted}" == "1" ]; then
echo "err='cannot migrate mounted drive'"
@ -224,9 +221,11 @@ if [ "$1" = "migration-mynode" ]; then
sudo chown bitcoin:bitcoin -R /mnt/hdd/lnd
migrate_lnd_conf
# copy lnd wallet password - so that user can set own on final setup
sudo cp /mnt/hdd/mynode/settings/.lndpw /mnt/hdd/passwordc.flag
# backup & rename the rest of the data
sudo mv /mnt/hdd/mynode /mnt/hdd/backup_migration
sudo rm
# call function for final migration
migrate_raspiblitz_conf

View File

@ -3,7 +3,9 @@
# command info
if [ "$1" = "-h" ] || [ "$1" = "-help" ]; then
echo "small config script to set a passwords A,B,C & D"
echo "blitz.setpassword.sh [?a|b|c|d] [?newpassword] "
echo "blitz.setpassword.sh a [?newpassword] "
echo "blitz.setpassword.sh b [?newpassword] "
echo "blitz.setpassword.sh c [?oldpassword] [?newpassword] "
echo "or just as a password enter dialog (result as file)"
echo "blitz.setpassword.sh [x] [text] [result-file] [?empty-allowed]"
echo "exits on 0 = needs reboot"
@ -29,18 +31,9 @@ if [ ${#chain} -eq 0 ]; then
chain="main"
fi
# 1. parameter [?a|b|c|d]
# 1. parameter [?a|b|c]
abcd=$1
# 2. parameter [?newpassword]
newPassword=$2
# 4. parameter [?newpassword]
emptyAllowed=0
if [ "$4" == "empty-allowed" ]; then
emptyAllowed=1
fi
# run interactive if no further parameters
OPTIONS=()
if [ ${#abcd} -eq 0 ]; then
@ -48,7 +41,6 @@ if [ ${#abcd} -eq 0 ]; then
OPTIONS+=(A "Master User Password / SSH")
OPTIONS+=(B "RPC Password (blockchain/lnd)")
OPTIONS+=(C "LND Wallet Password")
OPTIONS+=(D "LND Seed Password")
CHOICE=$(dialog --clear \
--backtitle "RaspiBlitz" \
--title "Set Password" \
@ -83,6 +75,8 @@ echo ""
# PASSWORD A
if [ "${abcd}" = "a" ]; then
newPassword=$2
# if no password given by parameter - ask by dialog
if [ ${#newPassword} -eq 0 ]; then
clear
@ -158,6 +152,8 @@ if [ "${abcd}" = "a" ]; then
# PASSWORD B
elif [ "${abcd}" = "b" ]; then
newPassword=$2
# if no password given by parameter - ask by dialog
if [ ${#newPassword} -eq 0 ]; then
clear
@ -298,50 +294,104 @@ EOF
# PASSWORD C
elif [ "${abcd}" = "c" ]; then
if [ ${#newPassword} -gt 0 ]; then
echo "New password C cannot be set thru paramter .. will start interactive password setting."
echo "PRESS ENTER to continue"
read key
oldPassword=$2
newPassword=$3
if [ "${oldPassword}" == "" ]; then
# ask user for old password c
clear
oldPassword=$(whiptail --passwordbox "\nEnter old Password C:\n" 10 52 "" --title "Old Password C" --backtitle "RaspiBlitz - Passwords" 3>&1 1>&2 2>&3)
if [ $? -eq 1 ] || [ "${oldPassword}" == "" ]; then
sudo /home/admin/config.scripts/blitz.setpassword.sh c
fi
echo "OK ... processing"
fi
clear
echo ""
echo "****************************************************************************"
echo "Change LND Wallet Password --> lncli --chain=${network} --network=${chain}net changepassword"
echo "****************************************************************************"
echo "This is your Password C on the RaspiBlitz to unlock your LND wallet."
echo "If you had Auto-Unlock active - you need to re-activate after this."
echo "****************************************************************************"
if [ "${newPassword}" == "" ]; then
clear
# ask user for new password c
newPassword=$(whiptail --passwordbox "\nEnter new Password C:\n" 10 52 "" --title "New Password C" --backtitle "RaspiBlitz - Passwords" 3>&1 1>&2 2>&3)
if [ $? -eq 1 ] || [ "${newPassword}" == "" ]; then
sudo /home/admin/config.scripts/blitz.setpassword.sh c ${oldPassword}
exit 0
fi
# check new password does not contain bad characters
clearedResult=$(echo "${newPassword}" | tr -dc '[:alnum:]-.' | tr -d ' ')
if [ ${#clearedResult} != ${#newPassword} ] || [ ${#clearedResult} -eq 0 ]; then
dialog --backtitle "RaspiBlitz - Setup" --msgbox "FAIL -> Contains bad characters (spaces, special chars)" 6 52
sudo /home/admin/config.scripts/blitz.setpassword.sh c ${oldPassword}
exit 0
fi
# check new password longer than 8
if [ ${#newPassword} -lt 8 ]; then
dialog --backtitle "RaspiBlitz - Setup" --msgbox "FAIL -> Password length under 8" 6 52
sudo /home/admin/config.scripts/blitz.setpassword.sh c ${oldPassword}
exit 1
fi
# ask user to retype new password c
newPassword2=$(whiptail --passwordbox "\nEnter again new Password C:\n" 10 52 "" --title "New Password C (repeat)" --backtitle "RaspiBlitz - Passwords" 3>&1 1>&2 2>&3)
if [ $? -eq 1 ] || [ "${newPassword}" == "" ]; then
sudo /home/admin/config.scripts/blitz.setpassword.sh c ${oldPassword}
exit 0
fi
echo "OK ... processing"
# check if passwords match
if [ "${newPassword}" != "${newPassword2}" ]; then
dialog --backtitle "RaspiBlitz - Setup" --msgbox "FAIL -> Passwords dont Match" 6 52
sudo /home/admin/config.scripts/blitz.setpassword.sh c ${oldPassword}
exit 0
fi
echo "OK ... processing"
fi
#echo "oldPassword: ${oldPassword}"
#echo "newPassword: ${newPassword}"
echo "# Make sure Auto-Unlocks off"
sudo /home/admin/config.scripts/lnd.autounlock.sh off
echo "LND needs to be restarted to lock wallet first .. (please wait)"
sudo systemctl restart lnd
sleep 6
sleep 2
err=""
source <(sudo /home/admin/config.scripts/lnd.initwallet.py 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
echo "# FAIL: Was not able to change password"
exit 1
fi
# old manual way
# clear
# echo ""
# echo "****************************************************************************"
# echo "Change LND Wallet Password --> lncli --chain=${network} --network=${chain}net changepassword"
# echo "****************************************************************************"
# echo "This is your Password C on the RaspiBlitz to unlock your LND wallet."
# echo "If you had Auto-Unlock active - you need to re-activate after this."
# echo "****************************************************************************"
# sleep 6
# let LND-CLI handle the password change
sudo -u bitcoin lncli --chain=${network} --network=${chain}net changepassword
# deactivate AUTO-UNLOCK if activated
echo ""
echo "# Make sure Auto-Unlocks off"
sudo /home/admin/config.scripts/lnd.autounlock.sh off
# sudo -u bitcoin lncli --chain=${network} --network=${chain}net changepassword
# final user output
echo ""
echo "OK"
exit 0
############################
# PASSWORD D
elif [ "${abcd}" = "d" ]; then
echo "#### NOTICE ####"
echo "Sorry - the password D cannot be changed. Its the password you set on creating your wallet to protect your seed (the list of words)."
exit 1
############################
# PASSWORD X
elif [ "${abcd}" = "x" ]; then
emptyAllowed=0
if [ "$4" == "empty-allowed" ]; then
emptyAllowed=1
fi
# second parameter is the flexible text
text=$2
resultFile=$3

View File

@ -18,6 +18,7 @@ if len(sys.argv) <= 1 or sys.argv[1] in ["-h", "--help", "help"]:
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("err='missing parameters'")
sys.exit(1)
@ -138,9 +139,35 @@ def scb(stub, wallet_password="", seed_words="", seed_password="", file_path_scb
print("err='TODO: implement creating from seed/scb'")
sys.exit(1)
def change_password(stub, wallet_password="", wallet_password_new=""):
request = lnrpc.ChangePasswordRequest(
current_password=wallet_password.encode(),
new_password=wallet_password_new.encode()
)
try:
response = stub.ChangePassword(request)
print("# ok - password changed")
#print(response.admin_macaroon)
except grpc.RpcError as rpc_error_call:
code = rpc_error_call.code()
print(code, file=sys.stderr)
details = rpc_error_call.details()
print("err='RPCError ChangePassword'")
print("errMore=\"" + details + "\"")
print("# make sure wallet is locked when trying to change password'", file=sys.stderr)
sys.exit(1)
except:
e = sys.exc_info()[0]
print(e, file=sys.stderr)
print("err='ChangePassword'")
sys.exit(1)
def parse_args():
wallet_password = ""
wallet_password_new = ""
seed_words = ""
seed_password = ""
filepath_scb = ""
@ -152,12 +179,27 @@ def parse_args():
print("err='wallet password is too short'")
sys.exit(1)
else:
print("err='wallet password is too short'")
print("err='missing parameters'")
sys.exit(1)
if len(sys.argv) > 3:
seed_password = sys.argv[3]
elif mode == "change-password":
if len(sys.argv) > 3:
wallet_password = sys.argv[2]
if len(wallet_password) < 8:
print("err='wallet password is too short'")
sys.exit(1)
wallet_password_new = sys.argv[3]
if len(wallet_password_new ) < 8:
print("err='wallet password new is too short'")
sys.exit(1)
else:
print("err='missing parameters'")
sys.exit(1)
elif mode == "seed" or mode == "scb":
if len(sys.argv) > 2:
@ -206,7 +248,7 @@ def parse_args():
print("err='unknown mode parameter - run without any parameters to see options'")
sys.exit(1)
return wallet_password, seed_words, seed_password, filepath_scb
return wallet_password, seed_words, seed_password, filepath_scb, wallet_password_new
def main():
@ -216,7 +258,7 @@ def main():
channel = grpc.secure_channel('localhost:10009', ssl_creds)
stub = rpcstub.WalletUnlockerStub(channel)
wallet_password, seed_words, seed_password, file_path_scb = parse_args()
wallet_password, seed_words, seed_password, file_path_scb, wallet_password_new = parse_args()
if mode == "new":
print("# *** CREATING NEW LND WALLET ***")
@ -230,6 +272,10 @@ def main():
print("# *** RECOVERING LND WALLET FROM SEED + SCB ***")
scb(stub, wallet_password, seed_words, seed_password, file_path_scb)
elif mode == "change-password":
print("# *** SETTING NEW PASSWORD FOR WALLET ***")
change_password(stub, wallet_password, wallet_password_new)
if __name__ == '__main__':
main()