setup.sh (2884B)
1 #!/bin/sh 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 # Wait for the 'READY:' line. Reading until EOF instead of using 47 # 'sed -u /READY:/ q' lets us tell "the system came up" apart from 48 # "taler-unified-setup.sh died first": on EOF without READY the test 49 # would otherwise carry on against services that are not running and 50 # fail much later with a confusing error. 51 READY=0 52 while IFS= read -r LINE <&4 53 do 54 printf '%s\n' "$LINE" 55 case "$LINE" in 56 READY:*) 57 READY=1 58 break 59 ;; 60 esac 61 done 62 # Close FD4 63 exec 4>&- 64 if [ "$READY" != "1" ] 65 then 66 SETUP_STATUS=0 67 wait "$SETUP_PID" || SETUP_STATUS=$? 68 unset SETUP_PID 69 if [ "$SETUP_STATUS" = "77" ] 70 then 71 exit_skip "taler-unified-setup.sh could not launch the test system" 72 fi 73 exit_fail "taler-unified-setup.sh died with status $SETUP_STATUS before the test system was ready" 74 fi 75 echo "Test system ready" >&2 76 } 77 78 # Exit, with status code "skip" (no 'real' failure) 79 function exit_fail() { 80 echo "$@" >&2 81 exit 1 82 } 83 84 # Exit, with status code "skip" (no 'real' failure) 85 function exit_skip() { 86 echo "SKIPPING: $1" 87 exit 77 88 } 89 90 function get_payto_uri() { 91 libeufin-bank create-account -u "$1" -p "$2" --name "$1" 2> /dev/null 92 } 93 94 echo -n "Checking for curl ..." 95 curl --version 2> /dev/null > /dev/null || exit_skip " no curl" 96 echo " OK" 97 echo -n "Checking for jq ..." 98 jq --version 2> /dev/null > /dev/null || exit_skip " no jq" 99 echo " OK"