summaryrefslogtreecommitdiff
path: root/netzbon/functions.sh
blob: 9820ca6dba5cb7c83c490479bc27c6f4c294738f (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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#!/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
}

# Asks several questions to the user
# -----------------------------------
function ask()
{

# DOMAIN_NAME

if [ $1 == "DOMAIN_NAME" ]; then
    read -p "Enter the domain name: " DOMAIN_NAME
fi

# ENABLE_TLS

if [ $1 == "ENABLE_TLS" ]; then
    read -p "Use TLS? (y/n): " ENABLE_TLS
fi

# CURRENCY

if [ $1 == "CURRENCY" ]; then
    read -p "Enter the name of the currency (e.g. 'EUR'):" CURRENCY
fi

# BANK_NAME

if [ $1 == "BANK_NAME" ]; then
    read -p "Enter the human-readable name of the bank (e.g. 'Taler Bank'): " BANK_NAME

fi

# DO_OFFLINE

if [ $1 == "DO_OFFLINE" ]; then
    read -p "Run taler-exchange offline? (y/n): " DO_OFFLINE
fi

# MASTER_PUBLIC_KEY

if [ $1 == "MASTER_PUBLIC_KEY" ]; then
    if [ $2 == "DO_OFFLINE" ]  && [ $DO_OFFLINE == 'n' ]; then
        read -p "Enter the exchange-offline master public key: " MASTER_PUBLIC_KEY
    fi
fi

# SANDBOX_ADMIN_PASSWORD

if [ $1 == "SANDBOX_ADMIN_PASSWORD" ]; then
    read -s -p "Enter the admin password for the bank: " SANDBOX_ADMIN_PASSWORD
    echo "" # force new line
fi

# SANDBOX_EXCHANGE_PASSWORD

if [ $1 == "SANDBOX_EXCHANGE_PASSWORD" ]; then
    SANDBOX_EXCHANGE_PASSWORD=`uuidgen`

fi


# NEXUS_EXCHANGE_PASSWORD

if [ $1 == "NEXUS_EXCHANGE_PASSWORD" ]; then
    NEXUS_EXCHANGE_PASSWORD=`uuidgen`
fi

}



function check_nexus_exchange ()
{

if test -z ${LIBEUFIN_NEXUS_USERNAME:-}
then
    say "Failure: LIBEUFIN_NEXUS_USERNAME not set"
    exit 1
fi

if test -z ${NEXUS_EXCHANGE_PASSWORD:-}
then
    say "Failure: NEXUS_EXCHANGE_PASSWORD not set"
    exit 1
fi

if test -z ${EXCHANGE_IBAN:-}
then
    say "Failure: EXCHANGE_IBAN not set"
    exit 1
fi
if test -z ${EXCHANGE_PAYTO:-}
then
    say "Failure: EXCHANGE_PAYTO not set"
    exit 1
fi

}


# Ask about whether use TLS or not
# -----------------------------------

function ask_tls()
{

read -p "Use TLS? (y/n): " ENABLE_TLS

if test ${ENABLE_TLS} == "y"
then
    PROTO="https"
else
    PROTO="http"
fi
}

# Check network
# -----------------------------------

check_dns()
{

ping -c1 exchange.${DOMAIN_NAME} # &> /dev/null


if test 0 != $?
then
    say "Could not ping TO exchange.${DOMAIN_NAME}."
    say "Please make sure your DNS/network are working."
    exit 1
fi

}