summaryrefslogtreecommitdiff
path: root/netzbon/config_libeufin_bank.sh
blob: 0c5a4b4687c79a3c09b44523db26569a85478b06 (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
#!/bin/bash
# This file is in the public domain.
#
# This script configure and launches libeufin-bank.
# The setup provides the admin account at the bank, and
# another account for the exchange at the bank.
#
# The environment must provide the following variables:
# - BANK_ADMIN_PASSWORD: password of the Netzbon administrator.
# - BANK_EXCHANGE_PASSWORD: password of the exchange
#     bank account hosted at Sandbox.  The related
#     username is: exchange-at-sandbox
# - BANK_NAME: human-readable name for the bank
# - DOMAIN_NAME: DNS domain name to use for the setup
# - ENABLE_TLS (http or https?)
#
# OUTPUTS:
#
# EXCHANGE_PAYTO -- payto-URI of the exchange
# EXCHANGE_WIRE_GATEWAY_URL -- URL of the wire gateway for the exchange

set -eu

source functions.sh
source config/user.conf
source config/internal.conf

if test -z "${BANK_NAME:-}"; then
  say "Error: config/user.conf does not specify BANK_NAME"
  exit 1
fi
if test -z "${DOMAIN_NAME:-}"; then
  say "Error: config/user.conf does not specify DOMAIN_NAME"
  exit 1
fi
if test -z "${BANK_ADMIN_PASSWORD:-}"; then
  say "Error: config/user.conf does not specify BANK_ADMIN_PASSWORD"
  exit 1
fi
if test -z "${BANK_EXCHANGE_PASSWORD:-}"; then
  say "Error: config/user.conf does not specify BANK_EXCHANGE_PASSWORD"
  exit 1
fi

# TODO: add sanity-checks for presence of other required env-vars

say "Configure the bank with ${CURRENCY}..."

# TODO is 20000000 big enough for admin dbt limit

bank_cfg () {
  taler-config -c /etc/libeufin/libeufin-bank.conf -s libeufin-bank -o $1 -V $2
}

bank_cfg -o CURRENCY ${CURRENCY}
bank_cfg -o DEFAULT_EXCHANGE ${PROTO}://exchange.${DOMAIN_NAME}
bank_cfg -o DEFAULT_ADMIN_DEBT_LIMIT ${CURRENCY}:20000000
bank_cfg -o DEFAULT_CUSTOMER_DEBT_LIMIT ${CURRENCY}:0
bank_cfg -o SERVE tcp
bank_cfg -o PORT ${BANK_PORT}
bank_cfg -o ALLOW_CONVERSION yes
bank_cfg -o FIAT_CURRENCY ${FIAT_CURRENCY} 
bank_cfg -o TAN_SMS libeufin-tan-sms.sh
bank_cfg -o TAN_EMAIL libeufin-tan-email.sh

say "Setting up libeufin-bank admin account"
sudo -u "libeufin-bank" libeufin-bank passwd admin "${BANK_ADMIN_PASSWORD}"

say "Setting up SPA configuration..."
echo "settings = { bankName: \"${BANK_NAME}\" }" >/etc/libeufin/settings.js

say "DONE"
say "Create exchange account..."
EXCHANGE_PAYTO_NEW="$(sudo -u libeufin-bank libeufin-bank create-account '{"username":"exchange","password":"'${BANK_EXCHANGE_PASSWORD}'","name":"Exchange","is_taler_exchange":true}')?receiver-name=Exchange"
EXCHANGE_WIRE_GATEWAY_URL_NEW="${PROTO}://bank.$DOMAIN_NAME/accounts/exchange/taler-wire-gateway/"

# Communicating this to the exchange script, as the exchange
# needs these for the /keys response.

if test -z "${EXCHANGE_PAYTO:-}"; then
  echo "EXCHANGE_PAYTO=\"${EXCHANGE_PAYTO_NEW}\"" >> config/internal.conf
fi

if test -z "${EXCHANGE_WIRE_GATEWAY_URL:-}"; then
  echo "EXCHANGE_WIRE_GATEWAY_URL=\"${EXCHANGE_WIRE_GATEWAY_URL_NEW}\"" >> config/internal.conf
fi

say "Start the bank..."
systemctl enable --now libeufin-bank