#!/bin/bash # This file is in the public domain. # # This script configure libeufin-bank and libeufin-nexus. set -eu source functions.sh source config/user.conf source config/internal.conf say "Beginning LibEuFin setup" 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 if test ${DO_CONVERSION} == y; then say "Configuring libeufin-nexus with ${FIAT_CURRENCY}..." taler-config -s nexus-ebics -o CURRENCY \ -V "$FIAT_CURRENCY" -c /etc/libeufin/libeufin-nexus.conf taler-config -s nexus-ebics -o IBAN \ -V "$FIAT_ACCOUNT_IBAN" -c /etc/libeufin/libeufin-nexus.conf taler-config -s nexus-ebics -o BIC \ -V "$FIAT_ACCOUNT_BIC" -c /etc/libeufin/libeufin-nexus.conf taler-config -s nexus-ebics -o NAME \ -V "$FIAT_ACCOUNT_NAME" -c /etc/libeufin/libeufin-nexus.conf fi say "Configuring libeufin-bank with ${CURRENCY}..." cat >/etc/libeufin/libeufin-bank.conf <>/etc/libeufin/libeufin-bank.conf <>/etc/libeufin/libeufin-bank.conf <> setup.log say "Setting up libeufin-bank..." say "Setting up libeufin-bank admin account..." sudo -u libeufin-bank \ libeufin-bank passwd \ -c /etc/libeufin/libeufin-bank.conf \ admin "${BANK_ADMIN_PASSWORD}" &>> setup.log say "Setting up admin's debt limit..." sudo -u libeufin-bank \ libeufin-bank edit-account \ -c /etc/libeufin/libeufin-bank.conf \ admin --debit_threshold=${CURRENCY}:200000000 &>> setup.log say "Setting up SPA configuration..." echo "settings = { bankName: \"${BANK_NAME}\" }" >/etc/libeufin/settings.js say "Create exchange account..." if test -z "${EXCHANGE_PAYTO:-}"; then EXCHANGE_PAYTO_NEW="$(sudo -u libeufin-bank libeufin-bank create-account -c /etc/libeufin/libeufin-bank.conf --username exchange --password "${BANK_EXCHANGE_PASSWORD}" --name Exchange --exchange 2>> setup.log)?receiver-name=Exchange" echo "EXCHANGE_PAYTO=\"${EXCHANGE_PAYTO_NEW}\"" >> config/internal.conf fi if test -z "${EXCHANGE_WIRE_GATEWAY_URL:-}"; then EXCHANGE_WIRE_GATEWAY_URL_NEW="${PROTO}://bank.$DOMAIN_NAME/accounts/exchange/taler-wire-gateway/" echo "EXCHANGE_WIRE_GATEWAY_URL=\"${EXCHANGE_WIRE_GATEWAY_URL_NEW}\"" >> config/internal.conf fi say "Start the bank..." systemctl enable libeufin-bank &>> setup.log systemctl restart libeufin-bank &>> setup.log say "Waiting for the bank (/config)..." curl -sS --max-time 2 \ --retry-all-errors \ --retry-delay 2 \ --retry 10 \ ${PROTO}://bank.${DOMAIN_NAME}/config &>> setup.log if test ${DO_CONVERSION} == y; then say "Setting conversion rates to 1:1 ..." # TODO only set conversion rates if known have been set curl -sS -u "admin:${BANK_ADMIN_PASSWORD}" \ -H 'Content-Type: application/json; charset=utf-8' \ ${PROTO}://bank.${DOMAIN_NAME}/conversion-info/conversion-rate \ --data-binary @- &>> setup.log << EOF { "cashin_ratio": "1", "cashin_fee": "${CURRENCY}:0", "cashin_tiny_amount": "${CURRENCY}:0.01", "cashin_rounding_mode": "nearest", "cashin_min_amount": "${FIAT_CURRENCY}:1", "cashout_ratio": "1", "cashout_fee": "${FIAT_CURRENCY}:0", "cashout_tiny_amount": "${FIAT_CURRENCY}:0.01", "cashout_rounding_mode": "nearest", "cashout_min_amount": "${CURRENCY}:1" } EOF fi say "LibEuFin setup finished"