diff options
author | Antoine A <> | 2024-02-20 11:47:01 +0100 |
---|---|---|
committer | Antoine A <> | 2024-02-20 11:47:01 +0100 |
commit | 79a9586d41f2bfc67b6093a79e9cc7db08fa4147 (patch) | |
tree | 0a4faf38d41ee51992606dacb07e3097a58cd6a6 | |
parent | 251cbd19e24a0278f3a8fd2b26620c73b8c4123d (diff) | |
download | deployment-79a9586d41f2bfc67b6093a79e9cc7db08fa4147.tar.gz deployment-79a9586d41f2bfc67b6093a79e9cc7db08fa4147.tar.bz2 deployment-79a9586d41f2bfc67b6093a79e9cc7db08fa4147.zip |
Generate missing currency specification
-rwxr-xr-x | regional-currency/functions.sh | 51 | ||||
-rwxr-xr-x | regional-currency/main.sh | 13 | ||||
-rwxr-xr-x | regional-currency/setup-exchange.sh | 17 | ||||
-rwxr-xr-x | regional-currency/setup-libeufin.sh | 17 | ||||
-rwxr-xr-x | regional-currency/setup-merchant.sh | 3 |
5 files changed, 57 insertions, 44 deletions
diff --git a/regional-currency/functions.sh b/regional-currency/functions.sh index 961d7c5..abd2582 100755 --- a/regional-currency/functions.sh +++ b/regional-currency/functions.sh @@ -25,24 +25,12 @@ function check_user() { function ask_questions() { if test -z "${CURRENCY:-}"; then read -r -p "Enter the name of the regional currency (e.g. 'NETZBON'): " CURRENCY - # convert to all-caps - CURRENCY=$(echo "${CURRENCY}" | tr a-z A-Z) - # libeufin currenly doesn't like currency names less than 3 letters. - if [[ ${#CURRENCY} -lt 3 || ${#CURRENCY} -gt 11 ]]; then - say "Currency name must be between 3 and 10 letters" - exit 1 - fi + CURRENCY=$(normalize_currency "${CURRENCY}") echo "CURRENCY=${CURRENCY}" >>config/user.conf fi if test -z "${FIAT_CURRENCY:-}"; then read -r -p "Enter the name of the fiat currency (e.g. 'CHF'): " FIAT_CURRENCY - # convert to all-caps - FIAT_CURRENCY=$(echo "${FIAT_CURRENCY}" | tr a-z A-Z) - # libeufin currenly doesn't like currency names less than 3 letters. - if [[ ${#FIAT_CURRENCY} -lt 3 || ${#FIAT_CURRENCY} -gt 11 ]]; then - say "Currency name must be between 3 and 10 letters" - exit 1 - fi + FIAT_CURRENCY=$(normalize_currency "${FIAT_CURRENCY}") echo "FIAT_CURRENCY=${FIAT_CURRENCY}" >>config/user.conf fi if test -z "${BANK_NAME:-}"; then @@ -114,6 +102,41 @@ function ask_questions() { fi } +function normalize_currency() { + # convert to all-caps + local CURRENCY=$(echo "$1" | tr a-z A-Z) + # libeufin currenly doesn't like currency names less than 3 letters. + if [[ ${#CURRENCY} -lt 3 || ${#CURRENCY} -gt 11 ]]; then + say "Currency name must be between 3 and 10 letters" + exit 1 + fi + echo "${CURRENCY}" +} + +function check_currency_spec() { + # Convert to lowercase + local CURRENCY=$(echo "$1" | tr A-Z a-z) + local HAS_SPEC=$(taler-config -S 2>/dev/null | grep --count "^currency-$CURRENCY$") + if test "${HAS_SPEC}" != "1"; then + say "Missing currency specification for $1, creating one" + read -r -p "Enter the currency name (e.g. 'US Dollar' for USD): " CURRENCY_SPEC_NAME + read -r -p "Enter the currency unit name (e.g. '$' for USD): " CURRENCY_SPEC_UNIT_NAME + cat << EOF > /usr/share/taler/config.d/$CURRENCY.conf +[currency-$CURRENCY] +ENABLED=YES +name=$CURRENCY_SPEC_NAME +code=$1 +fractional_input_digits=2 +fractional_normal_digits=2 +fractional_trailing_zero_digits=2 +alt_unit_names = {"0":"$CURRENCY_SPEC_UNIT_NAME"} +EOF + chmod a+r /usr/share/taler/config.d/$CURRENCY.conf + ln -s /usr/share/taler/config.d/$CURRENCY.conf /usr/share/libeufin/config.d/$CURRENCY.conf + say "Currency specification for $1 have been created at /usr/share/taler/config.d/$CURRENCY.conf" + fi +} + function check_dns() { for prefix in "exchange" "bank" "backend"; do if ! ping -c1 "${prefix}.${DOMAIN_NAME}" &>>setup.log; then diff --git a/regional-currency/main.sh b/regional-currency/main.sh index bca1d72..1d3eb6a 100755 --- a/regional-currency/main.sh +++ b/regional-currency/main.sh @@ -45,6 +45,19 @@ say "Installing packages (step 1 of 5)" . install_packages.sh check_dns +# Remove when libeufin currencies.conf is in sync with exchange +cat >>/usr/share/libeufin/config.d/netzbon.conf <<EOF +[CURRENCY-NETZBON] +enabled=yes +name=NetzBon +code=NETZBON +fractional_input_digits=2 +fractional_normal_digits=2 +fractional_trailing_zero_digits=2 +alt_unit_names={"0":"NETZBON"} +EOF +check_currency_spec $CURRENCY +check_currency_spec $FIAT_CURRENCY if test -z "${BANK_EXCHANGE_PASSWORD:-}"; then BANK_EXCHANGE_PASSWORD=$(uuidgen) diff --git a/regional-currency/setup-exchange.sh b/regional-currency/setup-exchange.sh index bf1f22d..01792b7 100755 --- a/regional-currency/setup-exchange.sh +++ b/regional-currency/setup-exchange.sh @@ -130,20 +130,6 @@ ENABLE_CREDIT=YES @inline-secret@ exchange-accountcredentials-default ../secrets/exchange-accountcredentials-default.secret.conf EOF -# FIXME-CG: def already in the Git, remove this -# after the next .deb release -cat << EOF > /etc/taler/conf.d/netzbon.conf -[currency-netzbon] -ENABLED=YES -name=NetzBon -code=NETZBON -fractional_input_digits=2 -fractional_normal_digits=2 -fractional_trailing_zero_digits=2 -alt_unit_names = {"0":"NETZBON"} -EOF -chmod a+r /etc/taler/conf.d/netzbon.conf - cat << EOF > /etc/taler/secrets/exchange-db.secret.conf [exchangedb-postgres] CONFIG=postgres:///exchange @@ -181,7 +167,8 @@ say "Initializing exchange database" taler-exchange-dbconfig -c /etc/taler/taler.conf &>> setup.log say "Launching exchange" -systemctl enable --now taler-exchange.target &>> setup.log +systemctl enable taler-exchange.target &>> setup.log +systemctl restart taler-exchange.target &>> setup.log say "Waiting for exchange HTTP service (/config)..." curl -sS --max-time 2 \ diff --git a/regional-currency/setup-libeufin.sh b/regional-currency/setup-libeufin.sh index 04ca162..b62cc58 100755 --- a/regional-currency/setup-libeufin.sh +++ b/regional-currency/setup-libeufin.sh @@ -49,25 +49,13 @@ FIAT_CURRENCY=${FIAT_CURRENCY} ALLOW_EDIT_CASHOUT_PAYTO_URI=yes EOF -if test -n "$TELESIGN_AUTH_TOKEN"; then +if test -n "${TELESIGN_AUTH_TOKEN:-}"; then cat >>/etc/libeufin/libeufin-bank.conf <<EOF TAN_SMS=libeufin-tan-sms.sh TAN_SMS_ENV="AUTH_TOKEN=$TELESIGN_AUTH_TOKEN" EOF fi -cat >>/etc/libeufin/libeufin-bank.conf <<EOF - -[CURRENCY-NETZBON] -enabled=yes -name=NetzBon -code=NETZBON -fractional_input_digits=2 -fractional_normal_digits=2 -fractional_trailing_zero_digits=2 -alt_unit_names={"0":"NETZBON"} -EOF - say "Setting up libeufin database..." libeufin-dbconfig &>> setup.log @@ -102,7 +90,8 @@ if test -z "${EXCHANGE_WIRE_GATEWAY_URL:-}"; then fi say "Start the bank..." -systemctl enable --now libeufin-bank &>> setup.log +systemctl enable libeufin-bank &>> setup.log +systemctl restart libeufin-bank &>> setup.log say "Waiting for the bank (/config)..." curl -sS --max-time 2 \ diff --git a/regional-currency/setup-merchant.sh b/regional-currency/setup-merchant.sh index 7c857b2..a594060 100755 --- a/regional-currency/setup-merchant.sh +++ b/regional-currency/setup-merchant.sh @@ -10,4 +10,5 @@ say "Setting up merchant database" taler-merchant-dbconfig &>> setup.log say "Launching taler-merchant-httpd" -systemctl enable --now taler-merchant-httpd &>> setup.log +systemctl enable taler-merchant-httpd &>> setup.log +systemctl restart taler-merchant-httpd &>> setup.log |