summaryrefslogtreecommitdiff
path: root/nlnet/task5/long-poll/start.sh
diff options
context:
space:
mode:
Diffstat (limited to 'nlnet/task5/long-poll/start.sh')
-rwxr-xr-xnlnet/task5/long-poll/start.sh134
1 files changed, 134 insertions, 0 deletions
diff --git a/nlnet/task5/long-poll/start.sh b/nlnet/task5/long-poll/start.sh
new file mode 100755
index 0000000..46a0af2
--- /dev/null
+++ b/nlnet/task5/long-poll/start.sh
@@ -0,0 +1,134 @@
+#!/bin/bash
+
+set -eu
+
+service postgresql start
+sudo -u postgres createuser -s root
+createdb libeufincheck
+
+wire_transfer () {
+ RESERVE_PUB=$(gnunet-ecc -g1 /tmp/www &> /dev/null && gnunet-ecc -p /tmp/www)
+ DB_CONN="postgresql:///libeufincheck"
+ libeufin-sandbox \
+ make-transaction \
+ --credit-account=sandbox-user \
+ --debit-account=admin MANA:2 \
+ $RESERVE_PUB
+}
+
+WITH_TASKS=1
+echo RUNNING SANDBOX-NEXUS EBICS PAIR
+jq --version &> /dev/null || (echo "'jq' command not found"; exit 77)
+curl --version &> /dev/null || (echo "'curl' command not found"; exit 77)
+
+DB_CONN="postgresql:///libeufincheck"
+export LIBEUFIN_SANDBOX_DB_CONNECTION=$DB_CONN
+export LIBEUFIN_NEXUS_DB_CONNECTION=$DB_CONN
+
+echo -n Delete previous data...
+libeufin-sandbox reset-tables
+libeufin-nexus reset-tables
+echo DONE
+echo -n Configure the default demobank with MANA...
+libeufin-sandbox config --with-signup-bonus --currency MANA default
+echo DONE
+echo -n Setting the default exchange at Sandbox...
+libeufin-sandbox \
+ default-exchange \
+ "https://exchange.example.com/" \
+ "payto://iban/NOTUSED"
+echo DONE
+echo -n Start the bank...
+export LIBEUFIN_SANDBOX_ADMIN_PASSWORD=foo
+libeufin-sandbox serve > sandbox.log 2>&1 &
+SANDBOX_PID=$!
+echo DONE
+echo -n Wait for the bank...
+curl --max-time 4 --retry-all-errors --retry-connrefused --retry-delay 1 --retry 10 http://localhost:5000/ &> /dev/null
+echo DONE
+echo -n Make one superuser at Nexus...
+libeufin-nexus superuser test-user --password x
+echo DONE
+echo -n Launching Nexus...
+libeufin-nexus serve &> nexus.log &
+NEXUS_PID=$!
+echo DONE
+echo -n Waiting for Nexus...
+curl --max-time 4 --retry-all-errors --retry-connrefused --retry-delay 1 --retry 10 http://localhost:5001/ &> /dev/null
+echo DONE
+
+echo -n "Register the Sandbox account..."
+export LIBEUFIN_SANDBOX_USERNAME=sandbox-user
+export LIBEUFIN_SANDBOX_PASSWORD=foo
+libeufin-cli \
+ sandbox --sandbox-url http://localhost:5000/ \
+ demobank \
+ register
+echo DONE
+echo -n Creating the x-libeufin-bank connection at Nexus...
+export LIBEUFIN_NEXUS_USERNAME=test-user
+export LIBEUFIN_NEXUS_PASSWORD=x
+export LIBEUFIN_NEXUS_URL=http://localhost:5001
+# echoing the password to STDIN, as that is a "prompt" option.
+libeufin-cli connections new-xlibeufinbank-connection \
+ --bank-url "http://localhost:5000/demobanks/default/access-api" \
+ --username sandbox-user \
+ --password foo \
+ wwwconn
+echo DONE
+echo -n Connecting the x-libeufin-bank connection...
+libeufin-cli connections connect wwwconn
+echo DONE
+# Importing the bank account under a local name at Nexus.
+echo -n Importing the x-libeufin-bank account locally..
+libeufin-cli connections import-bank-account \
+ --offered-account-id sandbox-user \
+ --nexus-bank-account-id foo-at-nexus wwwconn
+echo DONE
+echo -n Create the Taler facade at Nexus...
+libeufin-cli facades \
+ new-taler-wire-gateway-facade \
+ --currency TESTKUDOS --facade-name test-facade \
+ wwwconn foo-at-nexus
+echo DONE
+if test 1 = $WITH_TASKS; then
+ echo -n Creating submit transactions task..
+ libeufin-cli accounts task-schedule \
+ --task-type submit \
+ --task-name www-payments \
+ --task-cronspec "* * *" \
+ foo-at-nexus || true
+ # Tries every second. Ask C52
+ echo DONE
+ echo -n Creating fetch transactions task..
+ # Not idempotent, FIXME #7739
+ libeufin-cli accounts task-schedule \
+ --task-type fetch \
+ --task-name www-history \
+ --task-cronspec "* * *" \
+ --task-param-level statement \
+ --task-param-range-type since-last \
+ foo-at-nexus || true
+ echo DONE
+else
+ echo NOT creating background tasks!
+fi
+
+echo
+echo Services are online! The following shell offers a 'wire_transfer'
+echo command that wires money to Nexus 'test-user'. Give it after having
+echo connected an HTTP client that long-polls to Nexus. As an example, a
+echo 100 seconds long-poller to Nexus is the following command:
+echo curl -v -u test-user:x "'http://localhost:5001/facades/test-facade/taler-wire-gateway/history/incoming?delta=5&long_poll_ms=100000'"
+echo
+echo Hint: after having issued the previous command and having observed
+echo that it actually long-polls, press CTRL-Z to send it in the background,
+echo "then wire the funds to the long-poller with 'wire_transfer',"
+echo "and finally give 'fg 1' to bring the long-poller in the foreground."
+echo If the client now shows a response, then the long-polling mechanism
+echo worked.
+echo
+
+cd /
+export -f wire_transfer
+bash