summaryrefslogtreecommitdiff
path: root/regional-currency/functions.sh
diff options
context:
space:
mode:
Diffstat (limited to 'regional-currency/functions.sh')
-rwxr-xr-xregional-currency/functions.sh51
1 files changed, 37 insertions, 14 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