diff options
author | Christian Grothoff <christian@grothoff.org> | 2023-07-25 14:10:48 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2023-07-25 14:10:48 +0200 |
commit | 987878469d6a3c14addd251e45f65241467e010c (patch) | |
tree | 9dc3ce8264a056c2011de4e37dc89e3e346e9011 /src/auditor | |
parent | a1989efdab77c0e2e0628b6d52d7195fe50eb588 (diff) |
-more script fixes
Diffstat (limited to 'src/auditor')
-rwxr-xr-x | src/auditor/generate-auditor-basedb.sh | 33 | ||||
-rwxr-xr-x | src/auditor/test-auditor.sh | 11 | ||||
-rwxr-xr-x | src/auditor/test-sync.sh | 83 |
3 files changed, 79 insertions, 48 deletions
diff --git a/src/auditor/generate-auditor-basedb.sh b/src/auditor/generate-auditor-basedb.sh index 55127fffb..1e2286239 100755 --- a/src/auditor/generate-auditor-basedb.sh +++ b/src/auditor/generate-auditor-basedb.sh @@ -12,16 +12,41 @@ # set -eu -# Where do we write the result? -BASEDB="$1" - . setup.sh +CONF="generate-auditor-basedb.conf" +# Parse command-line options +while getopts ':c:d:h' OPTION; do + case "$OPTION" in + c) + CONF="$OPTARG" + ;; + d) + BASEDB="$OPTARG" + ;; + h) + echo 'Supported options:' +# shellcheck disable=SC2016 + echo ' -c $CONF -- set configuration' +# shellcheck disable=SC2016 + echo ' -d $DB -- set database name' + ;; + ?) + exit_fail "Unrecognized command line option" + ;; + esac +done + +# Where do we write the result? +if [ -z ${BASEDB:+} ] +then + exit_fail "-d option required" +fi + echo -n "Testing for curl ..." curl --help >/dev/null </dev/null || exit_skip " MISSING" echo " FOUND" -CONF="generate-auditor-basedb.conf" # reset database echo -n "Reset 'auditor-basedb' database at $PGHOST ..." diff --git a/src/auditor/test-auditor.sh b/src/auditor/test-auditor.sh index fb350a794..dbbe74899 100755 --- a/src/auditor/test-auditor.sh +++ b/src/auditor/test-auditor.sh @@ -59,17 +59,17 @@ LIBEUFIN_SETTLE_TIME=1 function stop_libeufin() { echo -n "Stopping libeufin... " - if test -f ${MY_TMP_DIR:-/}/libeufin-sandbox.pid + if test -f "${MY_TMP_DIR:-/}/libeufin-sandbox.pid" then - PID=$(cat ${MY_TMP_DIR}/libeufin-sandbox.pid 2> /dev/null) + PID=$(cat "${MY_TMP_DIR}/libeufin-sandbox.pid" 2> /dev/null) echo "Killing libeufin sandbox $PID" rm "${MY_TMP_DIR}/libeufin-sandbox.pid" kill "$PID" 2> /dev/null || true wait "$PID" || true fi - if test -f ${MY_TMP_DIR:-/}/libeufin-nexus.pid + if test -f "${MY_TMP_DIR:-/}/libeufin-nexus.pid" then - PID=$(cat ${MY_TMP_DIR}/libeufin-nexus.pid 2> /dev/null) + PID=$(cat "${MY_TMP_DIR}/libeufin-nexus.pid" 2> /dev/null) echo "Killing libeufin nexus $PID" rm "${MY_TMP_DIR}/libeufin-nexus.pid" kill "$PID" 2> /dev/null || true @@ -2238,7 +2238,6 @@ function check_with_database() { BASEDB="$1" CONF="$1.conf" - ORIGIN=$(pwd) echo "Running test suite with database $BASEDB using configuration $CONF" MASTER_PRIV_FILE="${BASEDB}.mpriv" taler-config \ @@ -2344,7 +2343,7 @@ export PGHOST MYDIR="${MY_TMP_DIR}/basedb" mkdir -p "${MYDIR}" echo "Generating fresh database at $MYDIR" -if faketime -f '-1 d' ./generate-auditor-basedb.sh "$MYDIR/$DB" +if faketime -f '-1 d' ./generate-auditor-basedb.sh -d "$MYDIR/$DB" then echo -n "Reset 'auditor-basedb' database at $PGHOST ..." dropdb "auditor-basedb" >/dev/null 2>/dev/null || true diff --git a/src/auditor/test-sync.sh b/src/auditor/test-sync.sh index cda25189a..9f1255b7c 100755 --- a/src/auditor/test-sync.sh +++ b/src/auditor/test-sync.sh @@ -1,8 +1,7 @@ #!/bin/bash - # # This file is part of TALER -# Copyright (C) 2014-2021 Taler Systems SA +# Copyright (C) 2014-2023 Taler Systems SA # # TALER is free software; you can redistribute it and/or modify it under the # terms of the GNU General Public License as published by the Free Software @@ -15,6 +14,7 @@ # You should have received a copy of the GNU General Public License along with # TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/license> # +# shellcheck disable=SC2317 set -eu @@ -32,13 +32,13 @@ function exit_fail() { # Cleanup to run whenever we exit function cleanup() { - if test ! -z "${POSTGRES_PATH:-}" + if [ -n "${POSTGRES_PATH:-}" ] then - ${POSTGRES_PATH}/pg_ctl -D $TMPDIR stop &> /dev/null || true + "${POSTGRES_PATH}/pg_ctl" -D "$TMPDIR" stop &> /dev/null || true fi - for n in `jobs -p` + for n in $(jobs -p) do - kill $n 2> /dev/null || true + kill "$n" 2> /dev/null || true done wait } @@ -59,19 +59,25 @@ function check_with_database() taler-exchange-dbinit -c test-sync-out.conf echo -n "." - psql -Aqt talercheck-in -q -1 -f $1.sql >/dev/null || exit_skip "Failed to load database" + psql -Aqt talercheck-in \ + -q -1 \ + -f "$1.sql" \ + >/dev/null \ + || exit_skip "Failed to load database" echo -n "." - taler-auditor-sync -s test-sync-in.conf -d test-sync-out.conf -t + taler-auditor-sync \ + -s test-sync-in.conf \ + -d test-sync-out.conf -t # cs_nonce_locks excluded: no point for table in denominations denomination_revocations wire_targets reserves reserves_in reserves_close reserves_out auditors auditor_denom_sigs exchange_sign_keys signkey_revocations extensions policy_details policy_fulfillments known_coins refresh_commitments refresh_revealed_coins refresh_transfer_keys deposits refunds wire_out aggregation_tracking wire_fee recoup recoup_refresh do echo -n "." - CIN=`echo "SELECT COUNT(*) FROM exchange.$table" | psql talercheck-in -Aqt` - COUT=`echo "SELECT COUNT(*) FROM exchange.$table" | psql talercheck-out -Aqt` + CIN=$(echo "SELECT COUNT(*) FROM exchange.$table" | psql talercheck-in -Aqt) + COUT=$(echo "SELECT COUNT(*) FROM exchange.$table" | psql talercheck-out -Aqt) - if test ${CIN} != ${COUT} + if [ "${CIN}" != "${COUT}" ] then dropdb talercheck-in dropdb talercheck-out @@ -88,14 +94,6 @@ function check_with_database() fail=0 } - - -# Postgres database to use -DB=auditor-basedb - -# Configuration file to use -CONF=${DB}.conf - # test required commands exist echo "Testing for jq" jq -h > /dev/null || exit_skip "jq required" @@ -111,23 +109,25 @@ taler-wallet-cli -h >/dev/null </dev/null 2>/dev/null || exit_skip "taler-wallet echo -n "Testing for Postgres" # Available directly in path? INITDB_BIN=$(command -v initdb) || true -if [[ ! -z "$INITDB_BIN" ]]; then - echo " FOUND (in path) at" $INITDB_BIN +if [[ -n "$INITDB_BIN" ]]; then + echo " FOUND (in path) at $INITDB_BIN" else - HAVE_INITDB=`find /usr -name "initdb" | head -1 2> /dev/null | grep postgres` || exit_skip " MISSING" - echo " FOUND at" `dirname $HAVE_INITDB` - INITDB_BIN=`echo $HAVE_INITDB | grep bin/initdb | grep postgres | sort -n | tail -n1` + HAVE_INITDB=$(find /usr -name "initdb" | head -1 2> /dev/null | grep postgres) || exit_skip " MISSING" + echo " FOUND at " "$(dirname "$HAVE_INITDB")" + INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres | sort -n | tail -n1) fi echo -n "Setting up Postgres DB" -POSTGRES_PATH=`dirname $INITDB_BIN` -MYDIR=`mktemp -d /tmp/taler-auditor-basedbXXXXXX` +POSTGRES_PATH=$(dirname "$INITDB_BIN") +MYDIR=$(mktemp -d /tmp/taler-auditor-basedbXXXXXX) TMPDIR="$MYDIR/postgres/" -mkdir -p $TMPDIR -$INITDB_BIN --no-sync --auth=trust -D ${TMPDIR} > ${MYDIR}/postgres-dbinit.log 2> ${MYDIR}/postgres-dbinit.err +mkdir -p "$TMPDIR" +"$INITDB_BIN" --no-sync --auth=trust -D "${TMPDIR}" \ + > "${MYDIR}/postgres-dbinit.log" \ + 2> "${MYDIR}/postgres-dbinit.err" echo " DONE" -mkdir ${TMPDIR}/sockets +mkdir "${TMPDIR}/sockets" echo -n "Launching Postgres service" -cat - >> $TMPDIR/postgresql.conf <<EOF +cat - >> "$TMPDIR/postgresql.conf" <<EOF unix_socket_directories='${TMPDIR}/sockets' fsync=off max_wal_senders=0 @@ -135,23 +135,30 @@ synchronous_commit=off wal_level=minimal listen_addresses='' EOF -cat $TMPDIR/pg_hba.conf | grep -v host > $TMPDIR/pg_hba.conf.new -mv $TMPDIR/pg_hba.conf.new $TMPDIR/pg_hba.conf -${POSTGRES_PATH}/pg_ctl -D $TMPDIR -l /dev/null start > ${MYDIR}/postgres-start.log 2> ${MYDIR}/postgres-start.err +grep -v host \ + < "$TMPDIR/pg_hba.conf" \ + > "$TMPDIR/pg_hba.conf.new" +mv "$TMPDIR/pg_hba.conf.new" "$TMPDIR/pg_hba.conf" +"${POSTGRES_PATH}/pg_ctl" \ + -D "$TMPDIR" \ + -l /dev/null \ + start \ + > "${MYDIR}/postgres-start.log" \ + 2> "${MYDIR}/postgres-start.err" echo " DONE" PGHOST="$TMPDIR/sockets" export PGHOST echo "Generating fresh database at $MYDIR" -if faketime -f '-1 d' ./generate-auditor-basedb.sh $MYDIR/auditor-basedb +if faketime -f '-1 d' ./generate-auditor-basedb.sh -d "$MYDIR/auditor-basedb" then - check_with_database $MYDIR/auditor-basedb - if test x$fail != x0 + check_with_database "$MYDIR/auditor-basedb" + if [ x$fail != x0 ] then - exit $fail + exit "$fail" else echo "Cleaning up $MYDIR..." - rm -rf $MYDIR || echo "Removing $MYDIR failed" + rm -rf "$MYDIR" || echo "Removing $MYDIR failed" fi else echo "Generation failed" |