taler-deployment

Deployment scripts and configuration files
Log | Files | Refs | README

setup-libeufin.sh (4210B)


      1 #!/bin/bash
      2 # This file is in the public domain.
      3 #
      4 # This script configure libeufin-bank and libeufin-nexus.
      5 
      6 
      7 set -eu
      8 
      9 source functions.sh
     10 source config/internal.conf
     11 load_config
     12 
     13 say "Beginning LibEuFin setup"
     14 
     15 expect_vars BANK_NAME DOMAIN_NAME BANK_ADMIN_PASSWORD BANK_EXCHANGE_PASSWORD
     16 
     17 if test ${DO_CONVERSION} == y; then
     18   say "Configuring libeufin-nexus with ${FIAT_CURRENCY}..."
     19 
     20   taler-harness config -c /etc/libeufin/libeufin-nexus.conf set \
     21     nexus-ebics CURRENCY "$FIAT_CURRENCY"
     22   taler-harness config -c /etc/libeufin/libeufin-nexus.conf set \
     23     nexus-ebics IBAN  "$FIAT_ACCOUNT_IBAN"
     24   taler-harness config -c /etc/libeufin/libeufin-nexus.conf set \
     25     nexus-ebics BIC "$FIAT_ACCOUNT_BIC"
     26   taler-harness config -c /etc/libeufin/libeufin-nexus.conf set \
     27     nexus-ebics NAME "$FIAT_ACCOUNT_NAME"
     28 fi
     29 
     30 
     31 say "Configuring libeufin-bank with ${CURRENCY}..."
     32 
     33 cat >/etc/libeufin/libeufin-bank.conf <<EOF
     34 [libeufin-bank]
     35 CURRENCY=${CURRENCY}
     36 NAME="${BANK_NAME}"
     37 BASE_URL=${PROTO}://bank.${DOMAIN_NAME}/
     38 WIRE_TYPE=x-taler-bank
     39 X_TALER_BANK_PAYTO_HOSTNAME=bank.${DOMAIN_NAME}
     40 SUGGESTED_WITHDRAWAL_EXCHANGE=${PROTO}://exchange.${DOMAIN_NAME}/
     41 SERVE=tcp
     42 PORT=${BANK_PORT}
     43 PWD_AUTH_COMPAT = yes
     44 EOF
     45 
     46 if test ${DO_CONVERSION} == y; then
     47   cat >>/etc/libeufin/libeufin-bank.conf <<EOF
     48 ALLOW_CONVERSION=yes
     49 FIAT_CURRENCY=${FIAT_CURRENCY}
     50 ALLOW_EDIT_CASHOUT_PAYTO_URI=yes
     51 EOF
     52 fi
     53 
     54 if test ${DO_TEST} == y; then
     55  cat >>/etc/libeufin/libeufin-bank.conf <<EOF
     56 ALLOW_REGISTRATION = yes
     57 ALLOW_ACCOUNT_DELETION = yes
     58 ALLOW_EDIT_NAME = yes
     59 DEFAULT_DEBT_LIMIT = ${CURRENCY}:100
     60 EOF
     61 fi
     62 
     63 if test -n "${TELESIGN_AUTH_TOKEN:-}"; then
     64   cat >>/etc/libeufin/libeufin-bank.conf <<EOF
     65 TAN_SMS=libeufin-tan-sms.sh
     66 TAN_SMS_ENV={"TELESIGN_AUTH_TOKEN":"$TELESIGN_AUTH_TOKEN"}
     67 EOF
     68 fi
     69 
     70 say "Setting up libeufin database..."
     71 
     72 ( p=$PWD; cd /; libeufin-dbconfig &>> $p/setup.log; )
     73 
     74 say "Setting up libeufin-bank..."
     75 
     76 
     77 say "Setting up libeufin-bank admin account..."
     78 ( p=$PWD; cd /; sudo -u libeufin-bank \
     79      libeufin-bank passwd \
     80      admin "${BANK_ADMIN_PASSWORD}" &>> $p/setup.log; )
     81 
     82 say "Setting up admin's debt limit..."
     83 ( p=$PWD; cd /; sudo -u libeufin-bank \
     84     libeufin-bank edit-account \
     85     admin --debit_threshold=${CURRENCY}:200000000 &>> $p/setup.log; )
     86 
     87 say "Setting up SPA configuration..."
     88 echo "settings = { bankName: \"${BANK_NAME}\" }" >/etc/libeufin/settings.js
     89 
     90 say "Create exchange account..."
     91 if test -z "${EXCHANGE_PAYTO:-}"; then
     92   # FIXME create-account should have a way to update the password if the account already exists
     93   EXCHANGE_PAYTO_NEW="$(sudo -u libeufin-bank libeufin-bank create-account --username exchange --password "${BANK_EXCHANGE_PASSWORD}" --name Exchange --exchange 2>> setup.log)"
     94   echo "EXCHANGE_PAYTO=\"${EXCHANGE_PAYTO_NEW}\"" >> config/user.conf
     95 fi
     96 if test -z "${BANK_EXCHANGE_TOKEN:-}"; then
     97   BANK_EXCHANGE_TOKEN=$(sudo -u libeufin-bank libeufin-bank create-token -u exchange -s wiregateway -d forever)
     98   echo "BANK_EXCHANGE_TOKEN=\"${BANK_EXCHANGE_TOKEN}\"" >>config/internal.conf
     99 fi
    100 
    101 
    102 say "Start the bank..."
    103 systemctl enable libeufin-bank &>> setup.log
    104 systemctl restart libeufin-bank &>> setup.log
    105 
    106 say "Waiting for the bank (/config)..."
    107 curl -sS --max-time 2 \
    108   --retry-all-errors \
    109   --retry-delay 2 \
    110   --retry 10 \
    111   --fail \
    112   ${PROTO}://bank.${DOMAIN_NAME}/config &>> setup.log
    113 
    114 if test ${DO_CONVERSION} == y; then
    115 say "Setting conversion rates to 1:1 ..."
    116 # TODO only set conversion rates if known have been set
    117 BANK_ADMIN_TOKEN=`sudo -u libeufin-bank libeufin-bank create-token -u admin -s readwrite`
    118 curl -sS --fail-with-body \
    119   -H "Authorization: Bearer $BANK_ADMIN_TOKEN" \
    120   -H 'Content-Type: application/json; charset=utf-8' \
    121   ${PROTO}://bank.${DOMAIN_NAME}/conversion-info/conversion-rate \
    122 --data-binary @- &>> setup.log << EOF
    123 {
    124   "cashin_ratio": "1",
    125   "cashin_fee": "${CURRENCY}:0",
    126   "cashin_tiny_amount": "${CURRENCY}:0.01",
    127   "cashin_rounding_mode": "nearest",
    128   "cashin_min_amount": "${FIAT_CURRENCY}:0",
    129   "cashout_ratio": "1",
    130   "cashout_fee": "${FIAT_CURRENCY}:0",
    131   "cashout_tiny_amount": "${FIAT_CURRENCY}:0.01",
    132   "cashout_rounding_mode": "nearest",
    133   "cashout_min_amount": "${CURRENCY}:0"
    134 }
    135 EOF
    136 fi
    137 
    138 say "LibEuFin setup finished"