#!/usr/bin/env bash # Helper to enable a bank account for the exchange via taler-exchange-offline. # Run this inside the exchange container (where the master private key lives). # Requires taler-exchange-offline and a valid master key in the secrets path. set -euo pipefail EXCHANGE_CONFIG="${EXCHANGE_CONFIG:-/etc/taler/taler-exchange.conf}" PAYTO_URI="${PAYTO_URI:-payto://x-taler-bank/ob.antifa.ltd/demogeld?receiver-name=demogeld}" OUT="${ENABLE_ACCOUNT_JSON:-/tmp/enable-account.json}" EXCHANGE_KEYS_URL="${EXCHANGE_KEYS_URL:-http://exchange:8081/keys}" EXCHANGE_WAIT_RETRIES="${EXCHANGE_WAIT_RETRIES:-60}" EXCHANGE_WAIT_INTERVAL="${EXCHANGE_WAIT_INTERVAL:-2}" EXCHANGE_CURL_OPTS="${EXCHANGE_CURL_OPTS:-}" render_template() { local src="$1" local dst="$2" if [[ -f "${src}" ]]; then echo "Rendering template ${src} -> ${dst}" envsubst < "${src}" > "${dst}" fi } render_template /etc/taler/taler-exchange.conf.tmpl /etc/taler/taler-exchange.conf render_template /etc/taler/conf.d/99-exchange.conf.tmpl /etc/taler/conf.d/99-exchange.conf enabled_flag="${ENABLE_EXCHANGE_ACCOUNT:-0}" case "${enabled_flag,,}" in 1|true|yes|on) ;; *) echo "ENABLE_EXCHANGE_ACCOUNT not set to true; skipping enable-account." exit 0 ;; esac echo "Using config: ${EXCHANGE_CONFIG}" echo "Payto URI: ${PAYTO_URI}" echo "Output JSON: ${OUT}" echo "Waiting for exchange at: ${EXCHANGE_KEYS_URL}" wait_for_exchange() { local i for ((i=1; i<=EXCHANGE_WAIT_RETRIES; i++)); do if curl -fsS ${EXCHANGE_CURL_OPTS} "${EXCHANGE_KEYS_URL}" >/dev/null 2>&1; then echo "Exchange reachable (attempt ${i})." return 0 fi sleep "${EXCHANGE_WAIT_INTERVAL}" done echo "Exchange not reachable after ${EXCHANGE_WAIT_RETRIES} attempts." >&2 return 1 } wait_for_exchange taler-exchange-offline -c "${EXCHANGE_CONFIG}" enable-account "${PAYTO_URI}" > "${OUT}" echo "enable-account JSON written to ${OUT}" taler-exchange-offline -c "${EXCHANGE_CONFIG}" upload < "${OUT}" echo "Upload complete."