exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

setup.sh (3061B)


      1 #!/bin/bash
      2 # This file is in the public domain
      3 
      4 # Script to be inlined into the main test scripts. Defines function 'setup()'
      5 # which wraps around 'taler-unified-setup.sh' to launch GNU Taler services.
      6 # Call setup() with the arguments to pass to 'taler-unified-setup'. setup()
      7 # will then launch GNU Taler, wait for the process to be complete before
      8 # returning. The script will also install an exit handler to ensure the GNU
      9 # Taler processes are stopped when the shell exits.
     10 
     11 set -eu
     12 
     13 # Cleanup to run whenever we exit
     14 function exit_cleanup() {
     15   if [ ! -z ${SETUP_PID+x} ]; then
     16     echo "Killing taler-unified-setup ($SETUP_PID)" >&2
     17     kill -TERM "$SETUP_PID" 2>/dev/null || true
     18     wait "$SETUP_PID" 2>/dev/null || true
     19   fi
     20 }
     21 
     22 # Install cleanup handler (except for kill -9)
     23 trap exit_cleanup EXIT
     24 
     25 function setup() {
     26   echo "Starting test system ..." >&2
     27   # Create a named pipe in a temp directory we own.
     28   FIFO_DIR=$(mktemp -d fifo-XXXXXX)
     29   FIFO_OUT=$(echo "$FIFO_DIR/out")
     30   mkfifo "$FIFO_OUT"
     31   # Open pipe as FD 3 (RW) and FD 4 (RO)
     32   exec 3<>"$FIFO_OUT" 4<"$FIFO_OUT"
     33   rm -rf "$FIFO_DIR"
     34   # We require '-W' for our termination logic to work.
     35   taler-unified-setup.sh -r merchant-exchange-default \
     36                          -W "$@" \
     37     > >(tee taler-unified-setup.log >&3) &
     38   SETUP_PID=$!
     39   # Close FD3
     40   exec 3>&-
     41   sed -u '/<<READY>>/ q' <&4
     42   # Close FD4
     43   exec 4>&-
     44   echo "Test system ready" >&2
     45 }
     46 
     47 # Exit, with status code "skip" (no 'real' failure)
     48 function exit_fail() {
     49   echo "$@" >&2
     50   exit 1
     51 }
     52 
     53 # Exit, with status code "skip" (no 'real' failure)
     54 function exit_skip() {
     55   echo "SKIPPING: $1"
     56   exit 77
     57 }
     58 
     59 function get_payto_uri() {
     60   export LIBEUFIN_SANDBOX_USERNAME="$1"
     61   export LIBEUFIN_SANDBOX_PASSWORD="$2"
     62   export LIBEUFIN_SANDBOX_URL="http://localhost:18082"
     63   echo "get_payto_uri currently not implemented"
     64   exit 1
     65   #    libeufin-cli sandbox demobank info --bank-account "$1" | jq --raw-output '.paytoUri'
     66 }
     67 
     68 # Stop libeufin-bank (if running)
     69 function stop_libeufin() {
     70   if [ -f "${MY_TMP_DIR:-/}/libeufin-bank.pid" ]; then
     71     PID=$(cat "${MY_TMP_DIR}/libeufin-bank.pid" 2>/dev/null)
     72     echo -n "Stopping libeufin $PID... "
     73     rm "${MY_TMP_DIR}/libeufin-bank.pid"
     74     kill "$PID" 2>/dev/null || true
     75     wait "$PID" || true
     76     echo "DONE"
     77   fi
     78 }
     79 
     80 function launch_libeufin() {
     81   echo "launching libeufin-bank"
     82   libeufin-bank serve \
     83     -c "$CONF" \
     84     -L "INFO" \
     85     >"${MY_TMP_DIR}/libeufin-bank-stdout.log" \
     86     2>"${MY_TMP_DIR}/libeufin-bank-stderr.log" &
     87   echo $! >"${MY_TMP_DIR}/libeufin-bank.pid"
     88   BANK_PORT=$(taler-exchange-config -c "$CONF" -s "libeufin-bank" -o "PORT")
     89   BANK_URL="http://localhost:${BANK_PORT}/"
     90   for n in $(seq 1 100); do
     91     echo -n "."
     92     sleep 0.2
     93     wget --timeout=1 \
     94       --tries=3 \
     95       --waitretry=0 \
     96       -a wget-bank-check.log \
     97       -o /dev/null \
     98       -O /dev/null \
     99       "${BANK_URL}config" || continue
    100     OK="1"
    101     break
    102   done
    103   if [ "1" != "$OK" ]; then
    104     echo "Failed to launch libeufin-bank"
    105     exit 1
    106   fi
    107   echo "launched libeufin-bank"
    108 }