aboutsummaryrefslogtreecommitdiff
path: root/docker/hybrid/images/merchant/startup.sh
blob: b6b2ca83a7558ebd64825b27f2f1b2868b8e4459 (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
#!/bin/bash

set -eu
export LD_LIBRARY_PATH=/usr/local/lib

# Values from config file mounted at run time:
CURRENCY=`taler-config -c /config/deployment.conf -s taler-deployment -o currency`
BACKEND_APIKEY=`taler-config -c /config/deployment.conf -s taler-deployment -o merchant-apikey`
EXCHANGE_URL="http://exchange/"
DB_PASSWORD=`taler-config -c /config/deployment.conf -s taler-deployment -o db-password`
BLOG_IBAN=DE940993
GNUNET_IBAN=DE463312
DEFAULT_IBAN=DE474361

while ! pg_isready -h talerdb -d taler; do
  echo DB not ready yet.
  sleep 2
done
echo Now DB is ready.

# FIXME: wallets external to the containers put localhost'ed
# exchanges along a /pay request.  That breaks here, since the
# exchange listens from another container.  The following
# command routes every request to 5555 (port on the host
# system that points to a contained exchange AND where the
# merchant tries to /deposit), to the container where the exchange listens.
socat TCP-LISTEN:5555,fork,reuseaddr TCP:exchange:80 &

# FIXME: browsers can only get redirected to merchant backends
# as they appear outside of the container (port 5556).  OTOH,
# merchant frontends can only talk to backends as they appear
# _inside_ the container (port 80).  Config, ultimately, must
# specify backends as they appear outside, otherwise frontends
# would redirect browsers with in-container addresses, that
# would make the backend not reached.  The following redirection
# allows to bridge the external merchant port to the internal,
# to make frontends reach the backend.
socat TCP-LISTEN:5556,fork,reuseaddr TCP:localhost:80 &

echo Checking exchange at: ${EXCHANGE_URL}
for n in `seq 1 20`
  do
    echo "."
    sleep 0.4
    OK=1
    wget ${EXCHANGE_URL} -o /dev/null -O /dev/null >/dev/null && break
    OK=0
  done
  if [ 1 != $OK ]
  then
      echo "ERROR: exchange unreachable."
      exit 1
  fi
echo Echange reachable.

EXCHANGE_MASTER_PUB=$(curl -s ${EXCHANGE_URL}keys | jq -r .master_public_key)
echo Found Exchange Pub: $EXCHANGE_MASTER_PUB
sed -i "s;__EXCHANGE_URL__;${EXCHANGE_URL};" /config/taler.conf
sed -i "s/__EXCHANGE_PUB__/${EXCHANGE_MASTER_PUB}/" /config/taler.conf
sed -i "s/__CURRENCY__/${CURRENCY}/" /config/taler.conf
sed -i "s/__BACKEND_APIKEY__/${BACKEND_APIKEY}/" /config/taler.conf
sed -i "s;__DB_PASSWORD__;${DB_PASSWORD};" /config/taler.conf
echo -n "Reset database..."
taler-merchant-dbinit -L DEBUG -c /config/taler.conf --reset
echo DONE
echo -n "Launch merchant backend..."
taler-merchant-httpd -c /config/taler.conf 2>&1 | \
  rotatelogs -e /logs/taler-merchant-httpd-%Y-%m-%d 86400 &
echo DONE
sleep 1
echo -n "Create default instance..."
curl -s -H "Content-Type: application/json" -X POST -d '{"auth":{"method":"external"},"payto_uris":["payto://iban/SANDBOXX/'$DEFAULT_IBAN'?receiver-name=Merchant43"],"id":"default","name":"default","address":{},"jurisdiction":{},"default_max_wire_fee":"'${CURRENCY}':1", "default_max_deposit_fee":"'${CURRENCY}':1","default_wire_fee_amortization":1,"default_wire_transfer_delay":{"d_us" : 1},"default_pay_delay":{"d_us": 3600000000}}' http://merchant/management/instances
echo DONE
echo -n "Create blog instance..."
curl -s -H "Content-Type: application/json" -X POST -d '{"auth":{"method":"external"},"payto_uris":["payto://iban/SANDBOXX/'$BLOG_IBAN'?receiver-name=BlogCompany"],"id":"blog","name":"default","address":{},"jurisdiction":{},"default_max_wire_fee":"'${CURRENCY}':1", "default_max_deposit_fee":"'${CURRENCY}':1","default_wire_fee_amortization":1,"default_wire_transfer_delay":{"d_us" : 1000000},"default_pay_delay":{"d_us": 3600000000}}' http://merchant/management/instances
echo DONE
echo -n "Create donations instance..."
curl -s -H "Content-Type: application/json" -X POST -d '{"auth":{"method":"external"},"payto_uris":["payto://iban/SANDBOXX/'$GNUNET_IBAN'?receiver-name=GNUnet"],"id":"GNUnet","name":"default","address":{},"jurisdiction":{},"default_max_wire_fee":"'${CURRENCY}':1", "default_max_deposit_fee":"'${CURRENCY}':1","default_wire_fee_amortization":1,"default_wire_transfer_delay":{"d_us" : 1000000},"default_pay_delay":{"d_us": 3600000000}}' http://merchant/management/instances
echo DONE

echo -n "Launch blog..."
${HOME}/.local/bin/taler-merchant-demos -c /config/taler.conf --http-port 8080 blog &
echo DONE
echo -n "Launch donations..."
${HOME}/.local/bin/taler-merchant-demos -c /config/taler.conf --http-port 8081 donations &
echo DONE

wait