summaryrefslogtreecommitdiff
path: root/docker/hybrid/images/merchant/startup.sh
blob: c067e54170011a1874e2a5afd1237c4592169fa4 (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
#!/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`
BACKEND_URL=`taler-config -c /config/deployment.conf -s taler-deployment -o merchant-url`
EXCHANGE_URL=`taler-config -c /config/deployment.conf -s taler-deployment -o default-exchange`
DB_PASSWORD=`taler-config -c /config/deployment.conf -s taler-deployment -o db-password`

BLOG_IBAN=DE940993
GNUNET_IBAN=DE463312
DEFAULT_IBAN=DE474361
TOR_IBAN=DE358263
TALER_IBAN=DE102893
SURVEY_IBAN=DE731371

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 &

is_serving () {
echo Checking $1
for n in `seq 1 50`
  do
    echo "."
    sleep 0.5
    OK=1
    wget $1 -o /dev/null -O /dev/null >/dev/null && break
    OK=0
  done
  if [ 1 != $OK ]
  then
      echo "ERROR: $1 unreachable."
      exit 1
  fi
}

is_serving ${EXCHANGE_URL}

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;__BACKEND_URL__;${BACKEND_URL};" /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

source /create_instances.sh

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 "Launch blog..."
${HOME}/.local/bin/taler-merchant-demos -c /config/taler.conf --http-port 8080 blog 2>&1 | rotatelogs -e /logs/blog-%Y-%m-%d 86400 &
echo DONE
echo -n "Launch donations..."
${HOME}/.local/bin/taler-merchant-demos -c /config/taler.conf --http-port 8081 donations 2>&1 | rotatelogs -e /logs/donations-%Y-%m-%d 86400 &
echo DONE
echo -n "Launch Survey..."
${HOME}/.local/bin/taler-merchant-demos -c /config/taler.conf --http-port 8082 survey 2>&1 | rotatelogs -e /logs/survey-%Y-%m-%d 86400 &
echo DONE
echo -n "Launch Landing..."
${HOME}/.local/bin/taler-merchant-demos -c /config/taler.conf --http-port 8083 landing 2>&1 | rotatelogs -e /logs/landing-%Y-%m-%d 86400 &
echo DONE

echo -n Creating a reserve for tips...

PAYTO_RESERVE=$(
  taler-merchant-setup-reserve \
    --amount ${CURRENCY}:20 \
    --exchange-url ${EXCHANGE_URL} \
    --merchant-url http://localhost/instances/survey/ \
    --apikey "Bearer {BACKEND_APIKEY}" \
    --wire-method iban
)

SANDBOX_URL="http://bank:15000/demobanks/default/"
is_serving ${SANDBOX_URL}
SURVEY_USERNAME=`taler-config -c /config/deployment.conf -s taler-deployment -o survey-sandbox-username`
export LIBEUFIN_SANDBOX_USERNAME=${SURVEY_USERNAME}
export LIBEUFIN_SANDBOX_PASSWORD=`taler-config -c /config/deployment.conf -s taler-deployment -o survey-sandbox-password`
# Check/wait that the Survey site got its bank account.
is_serving "${SANDBOX_URL}${SURVEY_USERNAME}"
libeufin-cli sandbox \
  --sandbox-url ${SANDBOX_URL}\
  demobank new-transaction --bank-account ${LIBEUFIN_SANDBOX_USERNAME} \
  --payto-with-subject ${PAYTO_RESERVE} --amount 20
unset LIBEUFIN_SANDBOX_USERNAME
unset LIBEUFIN_SANDBOX_PASSWORD

echo DONE

wait