From 7afc192edbb2c42cf63198c20573c6441fff8ec4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matev=C5=BE=20Jekovec?= Date: Fri, 11 Aug 2023 12:57:37 +0200 Subject: [PATCH] debug --- scripts/gen_example.sh | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/scripts/gen_example.sh b/scripts/gen_example.sh index 6f9541c2..969b2130 100755 --- a/scripts/gen_example.sh +++ b/scripts/gen_example.sh @@ -7,8 +7,9 @@ set -euo pipefail OASIS_CMD=$(readlink -f ./oasis) IN=$(readlink -f $1) +touch "$2" # XXX MacOS: readlink -f does not work if file does not exist. readlink -m is not implemented yet. OUT=$(readlink -f $2) -EXAMPLE_NAME=$(echo $(basename $(dirname $IN))) +EXAMPLE_NAME="$(basename $(dirname $IN))" USER_CFG_DIR="${HOME}/.config/oasis" CUSTOM_CFG_DIR="$(dirname $IN)/config" CFG_DIR="/tmp/cli_examples/${EXAMPLE_NAME}" @@ -27,7 +28,7 @@ fi # Prepare clean config file for the example or take the example-specific one, if it exists. function init_cfg() { # Init config in the first scenario step only. - if [ "$IN" != "$(ls $(dirname $IN)/* | head -n1)" ]; then + if [ "$IN" != "$(ls $(dirname $IN)/*.in | head -n1)" ]; then return fi @@ -75,26 +76,12 @@ export TZ=UTC # Execute the Oasis CLI and store the PID. cd $(dirname ${IN}) -${CMD} > ${OUT} & +${CMD} > ${OUT} -PID=$! -while ! test -f ${OUT} || ! grep -q "Sign this transaction" "${OUT}" && ps -p ${PID} > /dev/null -do - sleep 0.5 -done - -kill -9 ${PID} 2&>/dev/null || true - -# Trim the transaction submission notice (In case you are using a hardware-based signer...). -if [ "$YES_FLAG" != "" ] -then - head -n -1 ${OUT} > ${OUT}.tmp - mv ${OUT}.tmp ${OUT} -fi - -# Trim "Sign this transaction" prompt, if present. -if tail -n 1 ${OUT} | grep -q "Sign this transaction" +# Trim last two lines, if in non-interactive mode ("Sign this transaction?" and "In case you are using a hardware-based signer..."). +if [ "$YES_FLAG" != "" ] && [ grep -q "Sign this transaction?" "${OUT}" ] then - head -n -1 ${OUT} > ${OUT}.tmp + OUT_LINES=$(($(wc -l ${OUT} | cut -d ' ' -f 1)-2)) # XXX MacOS: head -n -2 is not implemented yet + head -n ${OUT_LINES} ${OUT} > ${OUT}.tmp mv ${OUT}.tmp ${OUT} fi