summaryrefslogtreecommitdiff
path: root/docker/demo/images/libeufin/startup.sh
blob: e2e1d39b614eb9c5a8abba390572e0ee0a774cda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#!/bin/bash

set -o pipefail
set -eu
export JAVA_OPTS="-Xss4m -XX:MaxJavaStackTraceDepth=1073741823"

MAYBE_VOLUME_MOUNTPOINT="/data/libeufin"
export LIBEUFIN_SANDBOX_DB_CONNECTION="jdbc:sqlite:${MAYBE_VOLUME_MOUNTPOINT}/sandbox.sqlite3"
export LIBEUFIN_NEXUS_DB_CONNECTION="jdbc:sqlite:${MAYBE_VOLUME_MOUNTPOINT}/nexus.sqlite3"
# This file indicates that data preparation ran already
# once.  It helps against some non idempotent commands.
INIT_MARKER=${MAYBE_VOLUME_MOUNTPOINT}/init-done
export LD_LIBRARY_PATH=/usr/local/lib # helps taler-config
CURRENCY=`taler-config -c /config/deployment.conf -s taler-deployment -o currency`
SANDBOX_PORT=15000
NEXUS_PORT=15001
SANDBOX_BASE_URL="http://localhost:${SANDBOX_PORT}"
EXCHANGE_URL=`taler-config -c /config/deployment.conf -s taler-deployment -o default-exchange`
CAPTCHA_URL=`taler-config -c /config/deployment.conf -s taler-deployment -o bank-url`
# As wanted by the Libeufin CLI:
export LIBEUFIN_SANDBOX_URL="${SANDBOX_BASE_URL}/demobanks/default"
export LIBEUFIN_NEXUS_URL="http://localhost:${NEXUS_PORT}"

# invoke: username password iban name
register_sandbox_account() {
  export LIBEUFIN_SANDBOX_USERNAME=$1
  export LIBEUFIN_SANDBOX_PASSWORD=$2
  # A unavailable username upon registration should
  # fail, hence non idempotence is acceptable here.
  test -a $INIT_MARKER || libeufin-cli sandbox demobank register --name "$4" --iban $3
  unset LIBEUFIN_SANDBOX_USERNAME
  unset LIBEUFIN_SANDBOX_PASSWORD
}

# takes port and service name
is_serving() {
  echo Is $1 serving?
  for n in `seq 1 80`
    do
      echo "."
      sleep 0.1
      OK=1
      wget $1 -o /dev/null -O /dev/null >/dev/null && break
      OK=0
    done
    if [ 1 != $OK ]
    then
        echo "$2 unreachable."
        exit 1
    fi
  echo $2 reachable.
}
EXCHANGE_IBAN=DE159593

mkdir -p ${MAYBE_VOLUME_MOUNTPOINT}
export LIBEUFIN_SANDBOX_ADMIN_PASSWORD=secret
echo -n "Creating ${CURRENCY} default demobank (CAPTCHA URL: ${CAPTCHA_URL})..."
test -a $INIT_MARKER || libeufin-sandbox config \
  --currency ${CURRENCY} \
  --with-signup-bonus \
  --captcha-url ${CAPTCHA_URL} \
  default
echo DONE
echo -n "Specify default exchange..."
test -a $INIT_MARKER || libeufin-sandbox default-exchange \
  ${EXCHANGE_URL} \
  "payto://iban/SANDBOXX/${EXCHANGE_IBAN}?receiver-name=Exchange+Company"
echo DONE

# Provide navigation bar links.
export TALER_ENV_URL_MERCHANT_BLOG=`taler-config -c /config/deployment.conf -s taler-deployment -o blog-url`
export TALER_ENV_URL_MERCHANT_DONATIONS=`taler-config -c /config/deployment.conf -s taler-deployment -o donations-url`
export TALER_ENV_URL_MERCHANT_SURVEY=`taler-config -c /config/deployment.conf -s taler-deployment -o survey-url`
export TALER_ENV_URL_INTRO=`taler-config -c /config/deployment.conf -s taler-deployment -o landing-url`
export TALER_ENV_URL_BANK=`taler-config -c /config/deployment.conf -s taler-deployment -o bank-url`

echo -n "Launching Sandbox..."
libeufin-sandbox serve --no-localhost-only --port $SANDBOX_PORT 2>&1 | \
  rotatelogs -e /logs/libeufin-sandbox-serve-%Y-%m-%d.log 86400 &
echo DONE
is_serving "${LIBEUFIN_SANDBOX_URL}/integration-api/config" Sandbox

source create_bank_accounts.sh

echo -n "Create exchange EBICS subscriber at Sandbox.."
export LIBEUFIN_SANDBOX_USERNAME=admin
export LIBEUFIN_SANDBOX_PASSWORD=secret
echo -n "Create EBICS host at Sandbox.."
test -a $INIT_MARKER || libeufin-cli sandbox --sandbox-url $SANDBOX_BASE_URL ebicshost create --host-id talerebics
echo DONE
echo -n "Create exchange's EBICS subscriber at Sandbox.."
test -a $INIT_MARKER || libeufin-cli sandbox \
  demobank new-ebicssubscriber --host-id talerebics \
  --user-id exchangeebics --partner-id talerpartner \
  --bank-account $EXCHANGE_SANDBOX_USERNAME
echo DONE
## NEXUS SETUP
EXCHANGE_NEXUS_USERNAME=`taler-config -c /config/deployment.conf -s taler-deployment -o exchange-nexus-username`
EXCHANGE_NEXUS_PASSWORD=`taler-config -c /config/deployment.conf -s taler-deployment -o exchange-nexus-password`


echo -n "Creating Nexus superuser..."
# Idempotent in the sense that if the user is found,
# they'll get the password changed.
libeufin-nexus superuser $EXCHANGE_NEXUS_USERNAME \
  --password $EXCHANGE_NEXUS_PASSWORD
echo DONE
echo -n "Launching Nexus..."
libeufin-nexus serve --no-localhost-only --port $NEXUS_PORT 2>&1 | \
  rotatelogs -e /logs/libeufin-nexus-serve-%Y-%m-%d.log 86400 &
echo DONE
is_serving $LIBEUFIN_NEXUS_URL Nexus

export LIBEUFIN_NEXUS_USERNAME=$EXCHANGE_NEXUS_USERNAME
export LIBEUFIN_NEXUS_PASSWORD=$EXCHANGE_NEXUS_PASSWORD

echo -n Creating a EBICS connection at Nexus..
# Not idempotent: the implementation does check if
# a connection with the requested name exists, and
# returns "409 Conflict".  FIXME
test -a $INIT_MARKER || libeufin-cli connections new-ebics-connection \
  --ebics-url "${SANDBOX_BASE_URL}/ebicsweb" \
  --host-id talerebics \
  --partner-id talerpartner \
  --ebics-user-id exchangeebics \
  talerconn
echo DONE
echo -n Setup EBICS keying..
# idempotent (noop if 'talerconn' is found)
libeufin-cli connections connect talerconn > /dev/null 
echo DONE
echo -n Download bank account name from Sandbox..
# idempotent (only stores new bank account names)
libeufin-cli connections download-bank-accounts talerconn
echo DONE
echo -n Importing bank account info into Nexus..
# idempotent
NEXUS_IMPORTED_BANKACCOUNT=nexus-bankaccount
libeufin-cli connections import-bank-account \
  --offered-account-id $EXCHANGE_SANDBOX_USERNAME \
  --nexus-bank-account-id $NEXUS_IMPORTED_BANKACCOUNT \
  talerconn
echo DONE
echo -n Setup payments submission task..
# Tries every second.
# Not idempotent, FIXME
test -a $INIT_MARKER || libeufin-cli accounts task-schedule \
  --task-type submit \
  --task-name exchange-payments \
  --task-cronspec "* * *" \
  $NEXUS_IMPORTED_BANKACCOUNT
echo DONE
# Tries every second.  Ask C52
echo -n Setup history fetch task..
# Not idempotent, FIXME
test -a $INIT_MARKER || libeufin-cli accounts task-schedule \
  --task-type fetch \
  --task-name exchange-history \
  --task-cronspec "* * *" \
  --task-param-level report \
  --task-param-range-type latest \
  $NEXUS_IMPORTED_BANKACCOUNT
echo DONE
echo -n Create the Taler facade at Nexus..
# Not idempotent, in the sense that a duplicate
# facade will be created. FIXME
FACADE_NAME=taler-facade
test -a $INIT_MARKER || libeufin-cli facades \
  new-taler-wire-gateway-facade \
  --currency ${CURRENCY} --facade-name $FACADE_NAME \
  talerconn $NEXUS_IMPORTED_BANKACCOUNT
echo DONE
# starting the SPA
BLOG_URL=`taler-config -c /config/deployment.conf -s taler-deployment -o blog-url`
DONATIONS_URL=`taler-config -c /config/deployment.conf -s taler-deployment -o donations-url`
SURVEY_URL=`taler-config -c /config/deployment.conf -s taler-deployment -o survey-url`
LANDING_URL=`taler-config -c /config/deployment.conf -s taler-deployment -o landing-url`
BANK_WEBUI_URL=`taler-config -c /config/deployment.conf -s taler-deployment -o bank-url`
BANK_BACKEND_URL=`taler-config -c /config/deployment.conf -s taler-deployment -o bank-backend-url`

sed -i "s;__LANDING_URL__;${LANDING_URL};" /usr/local/share/taler/demobank-ui/demobank-ui-settings.js
sed -i "s;__BLOG_URL__;${BLOG_URL};" /usr/local/share/taler/demobank-ui/demobank-ui-settings.js
sed -i "s;__DONATIONS_URL__;${DONATIONS_URL};" /usr/local/share/taler/demobank-ui/demobank-ui-settings.js
sed -i "s;__SURVEY_URL__;${SURVEY_URL};" /usr/local/share/taler/demobank-ui/demobank-ui-settings.js
sed -i "s;__BANK_WEBUI_URL__;${BANK_WEBUI_URL};" /usr/local/share/taler/demobank-ui/demobank-ui-settings.js
sed -i "s;__BANK_BACKEND_URL__;${BANK_BACKEND_URL};" /usr/local/share/taler/demobank-ui/demobank-ui-settings.js

nginx -c /nginx.conf 2>&1 | rotatelogs -e /logs/bank-ui-%Y-%m-%d.log 86400 &
touch $INIT_MARKER

wait