Skip to content

Commit

Permalink
Merge pull request #5116 from ghubstan/01-fix-bash-syntax
Browse files Browse the repository at this point in the history
Fix bash syntax inconsistencies
  • Loading branch information
sqrrm authored Feb 3, 2021
2 parents 9252d4b + 30a0f99 commit 803e400
Show file tree
Hide file tree
Showing 4 changed files with 157 additions and 155 deletions.
87 changes: 44 additions & 43 deletions apitest/scripts/limit-order-simulation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,57 +34,58 @@
#
# `$ apitest/scripts/limit-order-simulation.sh -l 40000 -d sell -c fr -m 0.00 -a 0.125`

APP_BASE_NAME=$(basename "$0")
APP_HOME=$(pwd -P)
APITEST_SCRIPTS_HOME="${APP_HOME}/apitest/scripts"
APITEST_SCRIPTS_HOME="$APP_HOME/apitest/scripts"

source "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh"
source "${APITEST_SCRIPTS_HOME}/trade-simulation-utils.sh"
source "$APITEST_SCRIPTS_HOME/trade-simulation-env.sh"
source "$APITEST_SCRIPTS_HOME/trade-simulation-utils.sh"

checksetup
parselimitorderopts "$@"

printdate "Started ${APP_BASE_NAME} with parameters:"
printdate "Started $APP_BASE_NAME with parameters:"
printscriptparams
printbreak

editpaymentaccountform "$COUNTRY_CODE"
exitoncommandalert $?
cat "${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM}"
cat "$APITEST_SCRIPTS_HOME/$F2F_ACCT_FORM"
printbreak

# Create F2F payment accounts for $COUNTRY_CODE, and get the $CURRENCY_CODE.
printdate "Creating Alice's face to face ${COUNTRY_CODE} payment account."
CMD="${CLI_BASE} --port=${ALICE_PORT} createpaymentacct --payment-account-form=${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM}"
printdate "ALICE CLI: ${CMD}"
CMD_OUTPUT=$(createpaymentacct "${CMD}")
printdate "Creating Alice's face to face $COUNTRY_CODE payment account."
CMD="$CLI_BASE --port=$ALICE_PORT createpaymentacct --payment-account-form=$APITEST_SCRIPTS_HOME/$F2F_ACCT_FORM"
printdate "ALICE CLI: $CMD"
CMD_OUTPUT=$(createpaymentacct "$CMD")
exitoncommandalert $?
echo "${CMD_OUTPUT}"
ALICE_ACCT_ID=$(getnewpaymentacctid "${CMD_OUTPUT}")
echo "$CMD_OUTPUT"
ALICE_ACCT_ID=$(getnewpaymentacctid "$CMD_OUTPUT")
exitoncommandalert $?
CURRENCY_CODE=$(getnewpaymentacctcurrency "${CMD_OUTPUT}")
CURRENCY_CODE=$(getnewpaymentacctcurrency "$CMD_OUTPUT")
exitoncommandalert $?
printdate "ALICE F2F payment-account-id = ${ALICE_ACCT_ID}, currency-code = ${CURRENCY_CODE}."
printdate "ALICE F2F payment-account-id = $ALICE_ACCT_ID, currency-code = $CURRENCY_CODE."
printbreak

printdate "Creating Bob's face to face ${COUNTRY_CODE} payment account."
CMD="${CLI_BASE} --port=${BOB_PORT} createpaymentacct --payment-account-form=${APITEST_SCRIPTS_HOME}/${F2F_ACCT_FORM}"
printdate "BOB CLI: ${CMD}"
CMD_OUTPUT=$(createpaymentacct "${CMD}")
printdate "Creating Bob's face to face $COUNTRY_CODE payment account."
CMD="$CLI_BASE --port=$BOB_PORT createpaymentacct --payment-account-form=$APITEST_SCRIPTS_HOME/$F2F_ACCT_FORM"
printdate "BOB CLI: $CMD"
CMD_OUTPUT=$(createpaymentacct "$CMD")
exitoncommandalert $?
echo "${CMD_OUTPUT}"
BOB_ACCT_ID=$(getnewpaymentacctid "${CMD_OUTPUT}")
echo "$CMD_OUTPUT"
BOB_ACCT_ID=$(getnewpaymentacctid "$CMD_OUTPUT")
exitoncommandalert $?
CURRENCY_CODE=$(getnewpaymentacctcurrency "${CMD_OUTPUT}")
CURRENCY_CODE=$(getnewpaymentacctcurrency "$CMD_OUTPUT")
exitoncommandalert $?
printdate "BOB F2F payment-account-id = ${BOB_ACCT_ID}, currency-code = ${CURRENCY_CODE}."
printdate "BOB F2F payment-account-id = $BOB_ACCT_ID, currency-code = $CURRENCY_CODE."
printbreak

# Bob & Alice now have matching payment accounts, now loop until the price limit is reached, then create an offer.
if [ "$DIRECTION" = "BUY" ]
then
printdate "Create a BUY / ${CURRENCY_CODE} offer when the market price falls to or below ${LIMIT_PRICE} ${CURRENCY_CODE}."
printdate "Create a BUY / $CURRENCY_CODE offer when the market price falls to or below $LIMIT_PRICE $CURRENCY_CODE."
else
printdate "Create a SELL / ${CURRENCY_CODE} offer when the market price rises to or above ${LIMIT_PRICE} ${CURRENCY_CODE}."
printdate "Create a SELL / $CURRENCY_CODE offer when the market price rises to or above $LIMIT_PRICE $CURRENCY_CODE."
fi

DONE=0
Expand Down Expand Up @@ -112,33 +113,33 @@ while : ; do
sleep "$WAIT"
done

printdate "ALICE: Creating ${DIRECTION} ${CURRENCY_CODE} offer with payment acct ${ALICE_ACCT_ID}."
CMD="$CLI_BASE --port=${ALICE_PORT} createoffer"
CMD+=" --payment-account=${ALICE_ACCT_ID}"
CMD+=" --direction=${DIRECTION}"
CMD+=" --currency-code=${CURRENCY_CODE}"
CMD+=" --amount=${AMOUNT}"
if [ -z "${MKT_PRICE_MARGIN}" ]; then
CMD+=" --fixed-price=${FIXED_PRICE}"
printdate "ALICE: Creating $DIRECTION $CURRENCY_CODE offer with payment acct $ALICE_ACCT_ID."
CMD="$CLI_BASE --port=$ALICE_PORT createoffer"
CMD+=" --payment-account=$ALICE_ACCT_ID"
CMD+=" --direction=$DIRECTION"
CMD+=" --currency-code=$CURRENCY_CODE"
CMD+=" --amount=$AMOUNT"
if [ -z "$MKT_PRICE_MARGIN" ]; then
CMD+=" --fixed-price=$FIXED_PRICE"
else
CMD+=" --market-price-margin=${MKT_PRICE_MARGIN}"
CMD+=" --market-price-margin=$MKT_PRICE_MARGIN"
fi
CMD+=" --security-deposit=50.0"
CMD+=" --fee-currency=BSQ"
printdate "ALICE CLI: ${CMD}"
OFFER_ID=$(createoffer "${CMD}")
printdate "ALICE CLI: $CMD"
OFFER_ID=$(createoffer "$CMD")
exitoncommandalert $?
printdate "ALICE: Created offer with id: ${OFFER_ID}."
printdate "ALICE: Created offer with id: $OFFER_ID."
printbreak
sleeptraced 3

# Show Alice's new offer.
printdate "ALICE: Looking at her new ${DIRECTION} ${CURRENCY_CODE} offer."
CMD="$CLI_BASE --port=${ALICE_PORT} getmyoffer --offer-id=${OFFER_ID}"
printdate "ALICE CLI: ${CMD}"
printdate "ALICE: Looking at her new $DIRECTION $CURRENCY_CODE offer."
CMD="$CLI_BASE --port=$ALICE_PORT getmyoffer --offer-id=$OFFER_ID"
printdate "ALICE CLI: $CMD"
OFFER=$($CMD)
exitoncommandalert $?
echo "${OFFER}"
echo "$OFFER"
printbreak
sleeptraced 7

Expand All @@ -149,11 +150,11 @@ printbreak
sleeptraced 5

# Show Alice's offer in Bob's CLI.
printdate "BOB: Looking at ${DIRECTION} ${CURRENCY_CODE} offers."
CMD="$CLI_BASE --port=${BOB_PORT} getoffers --direction=${DIRECTION} --currency-code=${CURRENCY_CODE}"
printdate "BOB CLI: ${CMD}"
printdate "BOB: Looking at $DIRECTION $CURRENCY_CODE offers."
CMD="$CLI_BASE --port=$BOB_PORT getoffers --direction=$DIRECTION --currency-code=$CURRENCY_CODE"
printdate "BOB CLI: $CMD"
OFFERS=$($CMD)
exitoncommandalert $?
echo "${OFFERS}"
echo "$OFFERS"

exit 0
32 changes: 16 additions & 16 deletions apitest/scripts/trade-simulation-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ checksetup() {
--registration-key=6ac43ea1df2a290c1c8391736aa42e4339c5cb4f110ff0257a13b63211977b7a"
exit 1;
}
printdate "Checking ${APP_HOME} for some expected directories and files."
if [ -d "${APP_HOME}/apitest" ]; then
printdate "Checking $APP_HOME for some expected directories and files."
if [ -d "$APP_HOME/apitest" ]; then
printdate "Subproject apitest exists.";
else
printdate "Error: Subproject apitest not found, maybe because you are not running the script from the project root dir."
exit 1
fi
if [ -f "${APP_HOME}/bisq-cli" ]; then
if [ -f "$APP_HOME/bisq-cli" ]; then
printdate "The bisq-cli script exists.";
else
printdate "Error: The bisq-cli script not found, maybe because you are not running the script from the project root dir."
Expand Down Expand Up @@ -181,12 +181,12 @@ parselimitorderopts() {

checkbitcoindrunning() {
# There may be a '+' char in the path and we have to escape it for pgrep.
if [[ ${APP_HOME} == *"+"* ]]; then
ESCAPED_APP_HOME=$(escapepluschar "${APP_HOME}")
if [[ $APP_HOME == *"+"* ]]; then
ESCAPED_APP_HOME=$(escapepluschar "$APP_HOME")
else
ESCAPED_APP_HOME="${APP_HOME}"
ESCAPED_APP_HOME="$APP_HOME"
fi
if pgrep -f "bitcoind -datadir=${ESCAPED_APP_HOME}/apitest/build/resources/main/Bitcoin-regtest" > /dev/null ; then
if pgrep -f "bitcoind -datadir=$ESCAPED_APP_HOME/apitest/build/resources/main/Bitcoin-regtest" > /dev/null ; then
printdate "The regtest bitcoind node is running on host."
else
printdate "Error: regtest bitcoind node is not running on host, exiting."
Expand All @@ -196,24 +196,24 @@ checkbitcoindrunning() {

printscriptparams() {
if [ -n "${LIMIT_PRICE+1}" ]; then
echo " LIMIT_PRICE = ${LIMIT_PRICE}"
echo " LIMIT_PRICE = $LIMIT_PRICE"
fi

echo " DIRECTION = ${DIRECTION}"
echo " COUNTRY_CODE = ${COUNTRY_CODE}"
echo " FIXED_PRICE = ${FIXED_PRICE}"
echo " MKT_PRICE_MARGIN = ${MKT_PRICE_MARGIN}"
echo " AMOUNT = ${AMOUNT}"
echo " DIRECTION = $DIRECTION"
echo " COUNTRY_CODE = $COUNTRY_CODE"
echo " FIXED_PRICE = $FIXED_PRICE"
echo " MKT_PRICE_MARGIN = $MKT_PRICE_MARGIN"
echo " AMOUNT = $AMOUNT"

if [ -n "${BOB_ROLE+1}" ]; then
echo " BOB_ROLE = ${BOB_ROLE}"
echo " BOB_ROLE = $BOB_ROLE"
fi

if [ -n "${ALICE_ROLE+1}" ]; then
echo " ALICE_ROLE = ${ALICE_ROLE}"
echo " ALICE_ROLE = $ALICE_ROLE"
fi

if [ -n "${WAIT+1}" ]; then
echo " WAIT = ${WAIT}"
echo " WAIT = $WAIT"
fi
}
42 changes: 21 additions & 21 deletions apitest/scripts/trade-simulation-utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# This file must be sourced by the main driver.

source "${APITEST_SCRIPTS_HOME}/trade-simulation-env.sh"
source "$APITEST_SCRIPTS_HOME/trade-simulation-env.sh"

printdate() {
echo "[$(date)] $@"
Expand Down Expand Up @@ -46,10 +46,10 @@ exitoncommandalert() {
registerdisputeagents() {
# Silently register dev dispute agents. It's easy to forget.
REG_KEY="6ac43ea1df2a290c1c8391736aa42e4339c5cb4f110ff0257a13b63211977b7a"
CMD="${CLI_BASE} --port=${ARBITRATOR_PORT} registerdisputeagent --dispute-agent-type=mediator --registration-key=${REG_KEY}"
CMD="$CLI_BASE --port=$ARBITRATOR_PORT registerdisputeagent --dispute-agent-type=mediator --registration-key=$REG_KEY"
SILENT=$($CMD)
commandalert $? "Could not register dev/test mediator."
CMD="${CLI_BASE} --port=${ARBITRATOR_PORT} registerdisputeagent --dispute-agent-type=refundagent --registration-key=${REG_KEY}"
CMD="$CLI_BASE --port=$ARBITRATOR_PORT registerdisputeagent --dispute-agent-type=refundagent --registration-key=$REG_KEY"
SILENT=$($CMD)
commandalert $? "Could not register dev/test refundagent."
# Do something with $SILENT to keep codacy happy.
Expand All @@ -59,7 +59,7 @@ registerdisputeagents() {
getbtcoreaddress() {
CMD="bitcoin-cli -regtest -rpcport=19443 -rpcuser=apitest -rpcpassword=apitest getnewaddress"
NEW_ADDRESS=$($CMD)
echo "${NEW_ADDRESS}"
echo "$NEW_ADDRESS"
}

genbtcblocks() {
Expand All @@ -74,7 +74,7 @@ genbtcblocks() {
for i in $(seq -f "%02g" 1 "$NUM_BLOCKS")
do
NEW_BLOCK_HASH=$(genbtcblock "$CMD")
printdate "Block Hash #$i:${NEW_BLOCK_HASH}"
printdate "Block Hash #$i:$NEW_BLOCK_HASH"
sleep "$SECONDS_BETWEEN_BLOCKS"
done
}
Expand All @@ -88,12 +88,12 @@ genbtcblock() {
escapepluschar() {
STRING="$1"
NEW_STRING=$(echo "${STRING//+/\\+}")
echo "${NEW_STRING}"
echo "$NEW_STRING"
}

printbalances() {
PORT="$1"
printcmd "${CLI_BASE} --port=${PORT} getbalance"
printcmd "$CLI_BASE --port=$PORT getbalance"
$CLI_BASE --port="$PORT" getbalance
}

Expand All @@ -102,54 +102,54 @@ getpaymentaccountmethods() {
CMD_OUTPUT=$($CMD)
commandalert $? "Could not get payment method ids."
printdate "Payment Method IDs:"
echo "${CMD_OUTPUT}"
echo "$CMD_OUTPUT"
}

getpaymentaccountform() {
CMD="$1"
CMD_OUTPUT=$($CMD)
commandalert $? "Could not get new payment account form."
echo "${CMD_OUTPUT}"
echo "$CMD_OUTPUT"
}

editpaymentaccountform() {
COUNTRY_CODE="$1"
CMD="python3 ${APITEST_SCRIPTS_HOME}/editf2faccountform.py $COUNTRY_CODE"
CMD="python3 $APITEST_SCRIPTS_HOME/editf2faccountform.py $COUNTRY_CODE"
CMD_OUTPUT=$($CMD)
commandalert $? "Could not edit payment account form."
printdate "Saved payment account form as ${F2F_ACCT_FORM}."
printdate "Saved payment account form as $F2F_ACCT_FORM."
}

getnewpaymentacctid() {
CREATE_PAYMENT_ACCT_OUTPUT="$1"
PAYMENT_ACCT_DETAIL=$(echo -e "${CREATE_PAYMENT_ACCT_OUTPUT}" | sed -n '3p')
PAYMENT_ACCT_DETAIL=$(echo -e "$CREATE_PAYMENT_ACCT_OUTPUT" | sed -n '3p')
ACCT_ID=$(echo -e "$PAYMENT_ACCT_DETAIL" | awk '{print $NF}')
echo "${ACCT_ID}"
echo "$ACCT_ID"
}

getnewpaymentacctcurrency() {
CREATE_PAYMENT_ACCT_OUTPUT="$1"
PAYMENT_ACCT_DETAIL=$(echo -e "${CREATE_PAYMENT_ACCT_OUTPUT}" | sed -n '3p')
PAYMENT_ACCT_DETAIL=$(echo -e "$CREATE_PAYMENT_ACCT_OUTPUT" | sed -n '3p')
# This is brittle; it requires the account name field to have N words,
# e.g, "Face to Face Payment Account" as defined in editf2faccountform.py.
CURRENCY_CODE=$(echo -e "$PAYMENT_ACCT_DETAIL" | awk '{print $6}')
echo "${CURRENCY_CODE}"
echo "$CURRENCY_CODE"
}

createpaymentacct() {
CMD="$1"
CMD_OUTPUT=$($CMD)
commandalert $? "Could not create new payment account."
echo "${CMD_OUTPUT}"
echo "$CMD_OUTPUT"
}

getpaymentaccounts() {
PORT="$1"
printcmd "${CLI_BASE} --port=${PORT} getpaymentaccts"
printcmd "$CLI_BASE --port=$PORT getpaymentaccts"
CMD="$CLI_BASE --port=$PORT getpaymentaccts"
CMD_OUTPUT=$($CMD)
commandalert $? "Could not get payment accounts."
echo "${CMD_OUTPUT}"
echo "$CMD_OUTPUT"
}

createoffer() {
Expand All @@ -160,9 +160,9 @@ createoffer() {
# return from this function now, passing the error status code to the caller.
commandalert $? "Could not create offer."

OFFER_DETAIL=$(echo -e "${OFFER_DESC}" | sed -n '2p')
NEW_OFFER_ID=$(echo -e "${OFFER_DETAIL}" | awk '{print $NF}')
echo "${NEW_OFFER_ID}"
OFFER_DETAIL=$(echo -e "$OFFER_DESC" | sed -n '2p')
NEW_OFFER_ID=$(echo -e "$OFFER_DETAIL" | awk '{print $NF}')
echo "$NEW_OFFER_ID"
}

getcurrentprice() {
Expand Down
Loading

0 comments on commit 803e400

Please sign in to comment.