From d0094d806858e144dca31d0f485700198ef20305 Mon Sep 17 00:00:00 2001 From: anastasia prasolova Date: Tue, 1 Jun 2021 21:18:46 +0300 Subject: [PATCH] #70 automating password input to neo-go commands Signed-off-by: anastasia prasolova --- bin/config.sh | 8 +++++--- bin/deposit.sh | 4 +++- bin/passwd.exp | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) create mode 100755 bin/passwd.exp diff --git a/bin/config.sh b/bin/config.sh index 4bf3319..8f8f955 100755 --- a/bin/config.sh +++ b/bin/config.sh @@ -7,9 +7,11 @@ # NeoGo binary path. NEOGO="${NEOGO:-docker exec -it main_chain neo-go}" -# Wallet files to change config value +# Wallet files to change config value WALLET="${WALLET:-services/chain/node-wallet.json}" WALLET_IMG="${WALLET_IMG:-wallets/node-wallet.json}" +# Wallet password that would be entered automatically; '-' means no password +PASSWD="one" # NeoFS configuration record: key is a string and value is an int KEY=${1} @@ -23,7 +25,7 @@ ADDR=`cat ${WALLET} | jq -r .accounts[2].address` # Change config value in side chain echo "Changing ${KEY} configration value to ${VALUE}" -${NEOGO} contract invokefunction \ +./bin/passwd.exp ${PASSWD} ${NEOGO} contract invokefunction \ -w ${WALLET_IMG} \ -a ${ADDR} \ -r http://morph_chain.${LOCAL_DOMAIN}:30333 \ @@ -40,7 +42,7 @@ epoch | grep 'value' | awk -F'"' '{ print $4 }'` # Update epoch to apply new configuartion value echo "Updating NeoFS epoch to $((EPOCH+1))" -${NEOGO} contract invokefunction \ +./bin/passwd.exp ${PASSWD} ${NEOGO} contract invokefunction \ -w ${WALLET_IMG} \ -a ${ADDR} \ -r http://morph_chain.${LOCAL_DOMAIN}:30333 \ diff --git a/bin/deposit.sh b/bin/deposit.sh index 7462f18..6340fe4 100755 --- a/bin/deposit.sh +++ b/bin/deposit.sh @@ -8,6 +8,8 @@ NEOGO="${NEOGO:-docker exec -it main_chain neo-go}" # Wallet file to use for deposit GAS from WALLET="${WALLET:-wallets/wallet.json}" +# Wallet password that would be entered automatically; '-' means no password +PASSWD="-" # How much GAS to deposit. First cli argument or 50 by default DEPOSIT="${1:-50}" @@ -16,7 +18,7 @@ ADDR=`cat ${WALLET} | jq -r .accounts[0].address` CONTRACT_ADDR=`${NEOGO} util convert ${NEOFS_IR_CONTRACTS_NEOFS} | grep 'LE ScriptHash to Address' | awk '{print $5}' | grep -oP [A-z0-9]+` # Make deposit -${NEOGO} wallet nep17 transfer \ +./bin/passwd.exp ${PASSWD} ${NEOGO} wallet nep17 transfer \ -w ${WALLET} \ -r http://main_chain.${LOCAL_DOMAIN}:30333 \ --from ${ADDR} \ diff --git a/bin/passwd.exp b/bin/passwd.exp new file mode 100755 index 0000000..3c8abdc --- /dev/null +++ b/bin/passwd.exp @@ -0,0 +1,17 @@ +#!/usr/bin/expect + +set passwd [lindex $argv 0] +set args [lrange $argv 1 end] + +spawn -noecho {*}$args +expect -re {^.*assword.*$} + +if { $passwd == "-"} { + send -- "\r" +} else { + send -- "$passwd\r" +} + +expect EOF +lassign [wait] pid spawnid os_error_flag value +exit $value