-more script fixes

This commit is contained in:
Christian Grothoff 2023-07-25 14:10:48 +02:00
parent a1989efdab
commit 987878469d
No known key found for this signature in database
GPG Key ID: 939E6BE1E29FC3CC
3 changed files with 79 additions and 48 deletions

View File

@ -12,16 +12,41 @@
# #
set -eu set -eu
# Where do we write the result?
BASEDB="$1"
. setup.sh . 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 ..." echo -n "Testing for curl ..."
curl --help >/dev/null </dev/null || exit_skip " MISSING" curl --help >/dev/null </dev/null || exit_skip " MISSING"
echo " FOUND" echo " FOUND"
CONF="generate-auditor-basedb.conf"
# reset database # reset database
echo -n "Reset 'auditor-basedb' database at $PGHOST ..." echo -n "Reset 'auditor-basedb' database at $PGHOST ..."

View File

@ -59,17 +59,17 @@ LIBEUFIN_SETTLE_TIME=1
function stop_libeufin() function stop_libeufin()
{ {
echo -n "Stopping libeufin... " echo -n "Stopping libeufin... "
if test -f ${MY_TMP_DIR:-/}/libeufin-sandbox.pid if test -f "${MY_TMP_DIR:-/}/libeufin-sandbox.pid"
then 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" echo "Killing libeufin sandbox $PID"
rm "${MY_TMP_DIR}/libeufin-sandbox.pid" rm "${MY_TMP_DIR}/libeufin-sandbox.pid"
kill "$PID" 2> /dev/null || true kill "$PID" 2> /dev/null || true
wait "$PID" || true wait "$PID" || true
fi fi
if test -f ${MY_TMP_DIR:-/}/libeufin-nexus.pid if test -f "${MY_TMP_DIR:-/}/libeufin-nexus.pid"
then 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" echo "Killing libeufin nexus $PID"
rm "${MY_TMP_DIR}/libeufin-nexus.pid" rm "${MY_TMP_DIR}/libeufin-nexus.pid"
kill "$PID" 2> /dev/null || true kill "$PID" 2> /dev/null || true
@ -2238,7 +2238,6 @@ function check_with_database()
{ {
BASEDB="$1" BASEDB="$1"
CONF="$1.conf" CONF="$1.conf"
ORIGIN=$(pwd)
echo "Running test suite with database $BASEDB using configuration $CONF" echo "Running test suite with database $BASEDB using configuration $CONF"
MASTER_PRIV_FILE="${BASEDB}.mpriv" MASTER_PRIV_FILE="${BASEDB}.mpriv"
taler-config \ taler-config \
@ -2344,7 +2343,7 @@ export PGHOST
MYDIR="${MY_TMP_DIR}/basedb" MYDIR="${MY_TMP_DIR}/basedb"
mkdir -p "${MYDIR}" mkdir -p "${MYDIR}"
echo "Generating fresh database at $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 then
echo -n "Reset 'auditor-basedb' database at $PGHOST ..." echo -n "Reset 'auditor-basedb' database at $PGHOST ..."
dropdb "auditor-basedb" >/dev/null 2>/dev/null || true dropdb "auditor-basedb" >/dev/null 2>/dev/null || true

View File

@ -1,8 +1,7 @@
#!/bin/bash #!/bin/bash
# #
# This file is part of TALER # 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 # 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 # 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 # 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> # TALER; see the file COPYING. If not, If not, see <http://www.gnu.org/license>
# #
# shellcheck disable=SC2317
set -eu set -eu
@ -32,13 +32,13 @@ function exit_fail() {
# Cleanup to run whenever we exit # Cleanup to run whenever we exit
function cleanup() { function cleanup() {
if test ! -z "${POSTGRES_PATH:-}" if [ -n "${POSTGRES_PATH:-}" ]
then then
${POSTGRES_PATH}/pg_ctl -D $TMPDIR stop &> /dev/null || true "${POSTGRES_PATH}/pg_ctl" -D "$TMPDIR" stop &> /dev/null || true
fi fi
for n in `jobs -p` for n in $(jobs -p)
do do
kill $n 2> /dev/null || true kill "$n" 2> /dev/null || true
done done
wait wait
} }
@ -59,19 +59,25 @@ function check_with_database()
taler-exchange-dbinit -c test-sync-out.conf taler-exchange-dbinit -c test-sync-out.conf
echo -n "." 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 "." 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 # 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 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 do
echo -n "." echo -n "."
CIN=`echo "SELECT COUNT(*) FROM exchange.$table" | psql talercheck-in -Aqt` CIN=$(echo "SELECT COUNT(*) FROM exchange.$table" | psql talercheck-in -Aqt)
COUT=`echo "SELECT COUNT(*) FROM exchange.$table" | psql talercheck-out -Aqt` COUT=$(echo "SELECT COUNT(*) FROM exchange.$table" | psql talercheck-out -Aqt)
if test ${CIN} != ${COUT} if [ "${CIN}" != "${COUT}" ]
then then
dropdb talercheck-in dropdb talercheck-in
dropdb talercheck-out dropdb talercheck-out
@ -88,14 +94,6 @@ function check_with_database()
fail=0 fail=0
} }
# Postgres database to use
DB=auditor-basedb
# Configuration file to use
CONF=${DB}.conf
# test required commands exist # test required commands exist
echo "Testing for jq" echo "Testing for jq"
jq -h > /dev/null || exit_skip "jq required" 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" echo -n "Testing for Postgres"
# Available directly in path? # Available directly in path?
INITDB_BIN=$(command -v initdb) || true INITDB_BIN=$(command -v initdb) || true
if [[ ! -z "$INITDB_BIN" ]]; then if [[ -n "$INITDB_BIN" ]]; then
echo " FOUND (in path) at" $INITDB_BIN echo " FOUND (in path) at $INITDB_BIN"
else else
HAVE_INITDB=`find /usr -name "initdb" | head -1 2> /dev/null | grep postgres` || exit_skip " MISSING" HAVE_INITDB=$(find /usr -name "initdb" | head -1 2> /dev/null | grep postgres) || exit_skip " MISSING"
echo " FOUND at" `dirname $HAVE_INITDB` echo " FOUND at " "$(dirname "$HAVE_INITDB")"
INITDB_BIN=`echo $HAVE_INITDB | grep bin/initdb | grep postgres | sort -n | tail -n1` INITDB_BIN=$(echo "$HAVE_INITDB" | grep bin/initdb | grep postgres | sort -n | tail -n1)
fi fi
echo -n "Setting up Postgres DB" echo -n "Setting up Postgres DB"
POSTGRES_PATH=`dirname $INITDB_BIN` POSTGRES_PATH=$(dirname "$INITDB_BIN")
MYDIR=`mktemp -d /tmp/taler-auditor-basedbXXXXXX` MYDIR=$(mktemp -d /tmp/taler-auditor-basedbXXXXXX)
TMPDIR="$MYDIR/postgres/" TMPDIR="$MYDIR/postgres/"
mkdir -p $TMPDIR mkdir -p "$TMPDIR"
$INITDB_BIN --no-sync --auth=trust -D ${TMPDIR} > ${MYDIR}/postgres-dbinit.log 2> ${MYDIR}/postgres-dbinit.err "$INITDB_BIN" --no-sync --auth=trust -D "${TMPDIR}" \
> "${MYDIR}/postgres-dbinit.log" \
2> "${MYDIR}/postgres-dbinit.err"
echo " DONE" echo " DONE"
mkdir ${TMPDIR}/sockets mkdir "${TMPDIR}/sockets"
echo -n "Launching Postgres service" echo -n "Launching Postgres service"
cat - >> $TMPDIR/postgresql.conf <<EOF cat - >> "$TMPDIR/postgresql.conf" <<EOF
unix_socket_directories='${TMPDIR}/sockets' unix_socket_directories='${TMPDIR}/sockets'
fsync=off fsync=off
max_wal_senders=0 max_wal_senders=0
@ -135,23 +135,30 @@ synchronous_commit=off
wal_level=minimal wal_level=minimal
listen_addresses='' listen_addresses=''
EOF EOF
cat $TMPDIR/pg_hba.conf | grep -v host > $TMPDIR/pg_hba.conf.new grep -v host \
mv $TMPDIR/pg_hba.conf.new $TMPDIR/pg_hba.conf < "$TMPDIR/pg_hba.conf" \
${POSTGRES_PATH}/pg_ctl -D $TMPDIR -l /dev/null start > ${MYDIR}/postgres-start.log 2> ${MYDIR}/postgres-start.err > "$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" echo " DONE"
PGHOST="$TMPDIR/sockets" PGHOST="$TMPDIR/sockets"
export PGHOST export PGHOST
echo "Generating fresh database at $MYDIR" 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 then
check_with_database $MYDIR/auditor-basedb check_with_database "$MYDIR/auditor-basedb"
if test x$fail != x0 if [ x$fail != x0 ]
then then
exit $fail exit "$fail"
else else
echo "Cleaning up $MYDIR..." echo "Cleaning up $MYDIR..."
rm -rf $MYDIR || echo "Removing $MYDIR failed" rm -rf "$MYDIR" || echo "Removing $MYDIR failed"
fi fi
else else
echo "Generation failed" echo "Generation failed"