setup.sh (2680B)
1 #!/usr/bin/env 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 unset XDG_DATA_HOME 14 unset XDG_CONFIG_HOME 15 16 17 # Cleanup to run whenever we exit 18 function exit_cleanup() 19 { 20 if [ ! -z ${SETUP_PID+x} ] 21 then 22 echo "Killing taler-unified-setup ($SETUP_PID)" >&2 23 kill -TERM "$SETUP_PID" 2> /dev/null || true 24 wait "$SETUP_PID" 2> /dev/null || true 25 fi 26 } 27 28 # Install cleanup handler (except for kill -9) 29 trap exit_cleanup EXIT 30 31 function setup() 32 { 33 echo "Starting test system ..." >&2 34 # Create a named pipe in a temp directory we own. 35 FIFO_DIR=$(mktemp -p "${TMPDIR:-/tmp}" -d fifo-XXXXXX) 36 FIFO_OUT=$(echo "$FIFO_DIR/out") 37 mkfifo "$FIFO_OUT" 38 # Open pipe as FD 3 (RW) and FD 4 (RO) 39 exec 3<> "$FIFO_OUT" 4< "$FIFO_OUT" 40 rm -rf "$FIFO_DIR" 41 # We require '-W' for our termination logic to work. 42 taler-unified-setup.sh -W "$@" >&3 & 43 SETUP_PID=$! 44 # Close FD3 45 exec 3>&- 46 # Pass the setup's output through until it announces READY:. Note that 47 # reaching end-of-pipe is NOT success: that is what happens when 48 # taler-unified-setup.sh dies during startup, and continuing then makes 49 # the test fail much later against a system that was never brought up, 50 # hiding the actual error. So insist on having seen the marker. 51 SETUP_READY=0 52 while IFS= read -r line <&4 53 do 54 printf '%s\n' "$line" 55 case "$line" in 56 *READY:*) 57 SETUP_READY=1 58 break 59 ;; 60 esac 61 done 62 # Close FD4 63 exec 4>&- 64 if [ "1" != "$SETUP_READY" ] 65 then 66 exit_fail "taler-unified-setup.sh failed to start the test system" 67 fi 68 echo "Test system ready" >&2 69 } 70 71 # Exit, with status code "skip" (no 'real' failure) 72 function exit_fail() { 73 echo "$@" >&2 74 exit 1 75 } 76 77 # Exit, with status code "skip" (no 'real' failure) 78 function exit_skip() { 79 echo "SKIPPING: $1" 80 exit 77 81 } 82 83 function get_payto_uri() { 84 libeufin-bank create-account -u "$1" -p "$2" --name "$1" 2> /dev/null 85 } 86 87 echo -n "Checking for curl ..." 88 curl --version 2> /dev/null > /dev/null || exit_skip " no curl" 89 echo " OK" 90 echo -n "Checking for jq ..." 91 jq --version 2> /dev/null > /dev/null || exit_skip " no jq" 92 echo " OK"