aboutsummaryrefslogtreecommitdiff
path: root/debian/taler-exchange.postinst
blob: 67fe7eefdd85450b88e85b9dd83a9cc756bde9e9 (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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!/bin/bash

set -e

. /usr/share/debconf/confmodule

TALER_HOME="/var/lib/taler-exchange"

# usage: fixperm user:group perms file
function fixperm() {
  chown "$1" "$3"
  chmod "$2" "$3"
}

# usage: lncfg user home target
function lncfg() {
  local cf=$TALER_HOME/$2/.config
  if [ ! -e $cf ]; then
    mkdir $cf
    chown $(stat -L -c %u $TALER_HOME/$2):$(stat -L -c %g $TALER_HOME/$2) $cf
  fi
  ln -sf $3 $cf/taler.conf
}

case "${1}" in
configure)
  db_version 2.0

  db_get taler-exchange/eusername
  _EUSERNAME="${RET:-taler-exchange-httpd}"

  db_get taler-exchange/rsecusername
  _RSECUSERNAME="${RET:-taler-exchange-secmod-rsa}"

  db_get taler-exchange/esecusername
  _ESECUSERNAME="${RET:-taler-exchange-secmod-eddsa}"

  db_get taler-exchange/wireusername
  _WIREUSERNAME="${RET:-taler-exchange-wire}"

  db_get taler-exchange/aggrusername
  _AGGRUSERNAME="${RET:-taler-exchange-aggregator}"

  db_get taler-exchange/groupname
  _GROUPNAME="${RET:-taler-private}"

  db_get taler-exchange/dbgroupname
  _DBGROUPNAME="${RET:-taler-exchange-db}"

  db_stop

  CONFIG_FILE="/etc/default/taler-exchange"

  # Creating taler groups as needed
  if ! getent group ${_GROUPNAME} >/dev/null; then
    echo -n "Creating new Taler group ${_GROUPNAME}:"
    addgroup --quiet --system ${_GROUPNAME}
    echo " done."
  fi
  if ! getent group ${_DBGROUPNAME} >/dev/null; then
    echo -n "Creating new Taler group ${_DBGROUPNAME}:"
    addgroup --quiet --system ${_DBGROUPNAME}
    echo " done."
  fi

  # Creating taler users if needed
  if ! getent passwd ${_EUSERNAME} >/dev/null; then
    echo -n "Creating new Taler user ${_EUSERNAME}:"
    adduser --quiet --system --ingroup ${_GROUPNAME} --home ${TALER_HOME}/httpd ${_EUSERNAME}
    adduser ${_EUSERNAME} ${_DBGROUPNAME}
    echo " done."
  fi
  if ! getent passwd ${_RSECUSERNAME} >/dev/null; then
    echo -n "Creating new Taler user ${_RSECUSERNAME}:"
    adduser --quiet --system --ingroup ${_GROUPNAME} --home ${TALER_HOME}/secmod-rsa ${_RSECUSERNAME}
    echo " done."
  fi
  if ! getent passwd ${_ESECUSERNAME} >/dev/null; then
    echo -n "Creating new Taler user ${_ESECUSERNAME}:"
    adduser --quiet --system --ingroup ${_GROUPNAME} --home ${TALER_HOME}/secmod-eddsa ${_ESECUSERNAME}
    echo " done."
  fi
  if ! getent passwd ${_WIREUSERNAME} >/dev/null; then
    echo -n "Creating new Taler user ${_WIREUSERNAME}:"
    adduser --quiet --system --home ${TALER_HOME}/wire ${_WIREUSERNAME}
    adduser --quiet ${_WIREUSERNAME} ${_DBGROUPNAME}
    echo " done."
  fi
  if ! getent passwd ${_AGGRUSERNAME} >/dev/null; then
    echo -n "Creating new Taler user ${_AGGRUSERNAME}:"
    adduser --quiet --system --home ${TALER_HOME}/aggregator ${_AGGRUSERNAME}
    adduser --quiet ${_AGGRUSERNAME} ${_DBGROUPNAME}
    echo " done."
  fi

  # Writing new values to configuration file
  echo -n "Writing new configuration file:"
  CONFIG_NEW=$(tempfile)

  cat >"${CONFIG_NEW}" <<EOF
# This file controls the behaviour of the Taler init script.
# It will be parsed as a shell script.
# please do not edit by hand, use 'dpkg-reconfigure taler-exchange'.

TALER_EUSER=${_EUSERNAME}
TALER_RSECUSER=${_RSECUSERNAME}
TALER_ESECUSER=${_ESECUSERNAME}
TALER_WIREUSER=${_WIREUSERNAME}
TALER_AGGRUSER=${_AGGRUSERNAME}
TALER_GROUP=${_GROUPNAME}
EOF

  cat >"/etc/systemd/system/taler-exchange-httpd.socket" <<EOF
[Unit]
Description=Taler Exchange Socket
PartOf=taler-exchange-httpd.service

[Socket]
ListenStream=/var/lib/taler-exchange/exchange.sock
Accept=no
Service=taler-exchange-httpd.service
SocketUser=${_EUSERNAME}
SocketGroup=www-data
SocketMode=0660

[Install]
WantedBy=sockets.target
EOF

  cat >"/etc/systemd/system/taler-exchange-httpd.service" <<EOF
[Unit]
Description=GNU Taler payment system exchange REST API
AssertPathExists=/var/lib/taler-exchange/
Requires=taler-exchange-httpd.socket taler-exchange-secmod-rsa.service taler-exchange-secmod-eddsa.service
Wants=taler-exchange-wirewatch.service taler-exchange-aggregator.service taler-exchange-transfer.service
After=postgres.service network.target

[Service]
EnvironmentFile=/etc/default/taler-exchange
User=${_EUSERNAME}
Type=simple
Restart=on-failure
ExecStart=/usr/bin/taler-exchange-httpd -c /etc/taler/exchange-service-default.conf
StandardOutput=journal
StandardError=journal
PrivateTmp=no
PrivateDevices=yes
ProtectSystem=full

[Install]
WantedBy=multi-user.target
EOF

  cat >"/etc/systemd/system/taler-exchange-secmod-rsa.service" <<EOF
[Unit]
Description=GNU Taler payment system exchange RSA security module

[Service]
EnvironmentFile=/etc/default/taler-exchange
User=${_RSECUSERNAME}
Type=simple
Restart=on-failure
ExecStart=/usr/bin/taler-exchange-secmod-rsa -c /etc/taler/exchange-service-default.conf
StandardOutput=journal
StandardError=journal
PrivateTmp=no
PrivateDevices=yes
ProtectSystem=full

EOF
  cat >"/etc/systemd/system/taler-exchange-secmod-eddsa.service" <<EOF
[Unit]
Description=GNU Taler payment system exchange EdDSA security module

[Service]
EnvironmentFile=/etc/default/taler-exchange
User=${_ESECUSERNAME}
Type=simple
Restart=on-failure
ExecStart=/usr/bin/taler-exchange-secmod-eddsa -c /etc/taler/exchange-service-default.conf
StandardOutput=journal
StandardError=journal
PrivateTmp=no
PrivateDevices=yes
ProtectSystem=full

EOF
  cat >"/etc/systemd/system/taler-exchange-wirewatch.service" <<EOF
[Unit]
Description=GNU Taler payment system exchange wirewatch service
After=network.target

[Service]
EnvironmentFile=/etc/default/taler-exchange
User=${_WIREUSERNAME}
Type=simple
Restart=on-failure
ExecStart=/usr/bin/taler-exchange-wirewatch -c /etc/taler/exchange-service-wire.conf
StandardOutput=journal
StandardError=journal
PrivateTmp=yes
PrivateDevices=yes
ProtectSystem=full


EOF
  cat >"/etc/systemd/system/taler-exchange-transfer.service" <<EOF
[Unit]
Description=GNU Taler payment system exchange transfer service
After=network.target

[Service]
EnvironmentFile=/etc/default/taler-exchange
User=${_WIREUSERNAME}
Type=simple
Restart=on-failure
ExecStart=/usr/bin/taler-exchange-wirewatch -c /etc/taler/exchange-service-wire.conf
StandardOutput=journal
StandardError=journal
PrivateTmp=yes
PrivateDevices=yes
ProtectSystem=full

EOF
  cat >"/etc/systemd/system/taler-exchange-aggregator.service" <<EOF
[Unit]
Description=GNU Taler payment system exchange aggregator service

[Service]
EnvironmentFile=/etc/default/taler-exchange
User=${_AGGRUSERNAME}
Type=simple
Restart=on-failure
ExecStart=/usr/bin/taler-exchange-aggregator -c /etc/taler/exchange-service-default.conf
StandardOutput=journal
StandardError=journal
PrivateTmp=yes
PrivateDevices=yes
ProtectSystem=full


EOF

  cp -f "${CONFIG_NEW}" "${CONFIG_FILE}"
  rm -f "${CONFIG_NEW}"
  echo " done."

  echo -n "Setting up system services "

  mkdir -p /var/lib/taler-exchange/tmp
  chown root:${_GROUPNAME} /var/lib/taler-exchange/tmp
  chmod 770 /var/lib/taler-exchange/tmp
  chmod +s /var/lib/taler-exchange/tmp

  fixperm ${_WIREUSERNAME}:root 460 /etc/taler/exchange-wire-gateway.conf
  fixperm root:${_DBGROUPNAME} 640 /etc/taler/exchange-db.conf

  systemctl daemon-reload >/dev/null 2>&1 || true

  echo "done."

  echo -n "Linking config files"
  lncfg ${_EUSERNAME} httpd /etc/taler/exchange-service-default.conf
  lncfg ${_RSECUSERNAME} secmod-rsa /etc/taler/exchange-service-default.conf
  lncfg ${_ESECUSERNAME} secmod-eddsa /etc/taler/exchange-service-default.conf
  lncfg ${_AGGRUSERNAME} aggregator /etc/taler/exchange-service-default.conf
  lncfg ${_WIREUSERNAME} wire /etc/taler/exchange-service-wire.conf
  echo " done"

  # Cleaning
  echo "All done."
  ;;

abort-upgrade | abort-remove | abort-deconfigure) ;;

*)
  echo "postinst called with unknown argument \`${1}'" >&2
  exit 1
  ;;
esac

#DEBHELPER#

exit 0