summaryrefslogtreecommitdiff
path: root/netzbon/functions.sh
blob: a596f729999be812804521d406bde4c63006b7e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#!/bin/bash

# Message
function say() {
  echo "TALER: " "$@"
}

# Check user if the user is root
function check_user() {
  if [ "$(whoami)" != "root" ]; then
    say "Please run this script as root"
    exit 1
  fi
}

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
    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
    echo "FIAT_CURRENCY=${FIAT_CURRENCY}" >>config/user.conf
  fi
  if test -z "${BANK_NAME:-}"; then
    read -r -p "Enter the human-readable name of the bank (e.g. 'Taler Bank'): " BANK_NAME
    echo "BANK_NAME=\"${BANK_NAME}\"" >>config/user.conf
  fi
  if test -z "${ENABLE_TLS:-}"; then
    read -r -p "Use TLS? (y/n): " ENABLE_TLS
    echo "ENABLE_TLS=${ENABLE_TLS}" >>config/user.conf
  fi
  if test -z "${DO_OFFLINE:-}"; then
    read -r -p "Run taler-exchange-offline? (y/n): " DO_OFFLINE
    echo "DO_OFFLINE=${DO_OFFLINE}" >>config/user.conf
  fi
  if test -z "${MASTER_PUBLIC_KEY:-}"; then
    if test "${DO_OFFLINE:-y}" == n; then
      read -r -p "Enter the exchange-offline master public key: " MASTER_PUBLIC_KEY
      echo "MASTER_PUBLIC_KEY=${MASTER_PUBLIC_KEY}" >>config/user.conf
    fi
  fi
  if test -z "${BANK_ADMIN_PASSWORD:-}"; then
    read -r -s -p "Enter the admin password for the bank: " BANK_ADMIN_PASSWORD
    echo "BANK_ADMIN_PASSWORD=$(printf '%q' "${BANK_ADMIN_PASSWORD}")" >>config/user.conf
    echo "" # force new line
  fi
  if test -z "${DOMAIN_NAME:-}"; then
    read -r -p "Enter the domain name: " DOMAIN_NAME
    # convert to lower-case
    DOMAIN_NAME=$(echo "${DOMAIN_NAME}" | tr A-Z a-z)
    echo "DOMAIN_NAME=${DOMAIN_NAME}" >>config/user.conf
  fi
}

# Set DISTRO to the detected distro or return non-zero
# status if distro not supported.
function detect_distro() {
  unset DISTRO
  # shellcheck disable=SC2034
  uname -a | grep Ubuntu >/dev/null && DISTRO=ubuntu && return 0
  # shellcheck disable=SC2034
  uname -a | grep Debian >/dev/null && DISTRO=debian && return 0
  echo "Unsupported distro, should be either ubuntu or debian" >&2
  return 1
}

function config_services() {
  ./config_nginx.sh
  ./config_libeufin.sh
  ./setup-exchange.sh
  ./setup-merchant.sh
}