summaryrefslogtreecommitdiff
path: root/debian/taler-exchange.postinst
blob: d943647b266ae6fb4ffe23cd569a9327c2898139 (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
#!/bin/bash

set -e

. /usr/share/debconf/confmodule

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

		db_get taler-systempeer/username
		_USERNAME="${RET:-taler}"

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

		db_get taler-systempeer/autostart
		_AUTOSTART="${RET}" # boolean

		db_stop

		CONFIG_FILE="/etc/default/taler"

		# Read default values
		TALER_HOME="/var/lib/taler-exchange"
		eval $(grep TALER_HOME /etc/taler.conf | tr -d '[:blank:]')

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

		# Creating taler user if needed
		if ! getent passwd ${_USERNAME} > /dev/null
		then
			echo -n "Creating new Taler user ${_USERNAME}:"
			adduser --quiet --system --ingroup ${_GROUPNAME} --home ${TALER_HOME} ${_USERNAME}
			echo " done."
		fi

		# Add a special secured group
		TALERDNS_GROUP="talerdns"

		# Creating talerdns group if needed
		if ! getent group ${TALERDNS_GROUP} > /dev/null
		then
			echo -n "Creating new secured Taler group ${TALERDNS_GROUP}:"
			addgroup --quiet --system ${TALERDNS_GROUP}
			echo " done."
		fi

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-systempeer'.

TALER_USER=${_USERNAME}
TALER_GROUP=${_GROUPNAME}
TALER_AUTOSTART="${_AUTOSTART}"
EOF

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

[Service]
EnvironmentFile=/etc/default/taler
User=${_USERNAME}
Type=forking
ExecStart=/usr/bin/taler-arm -s -c /etc/taler.conf
ExecStop=/usr/bin/taler-arm -e -c /etc/taler.conf

[Install]
WantedBy=multi-user.target
EOF

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

		# Cleaning
		rm -f "${CONFIG_NEW}"
		echo "All done."

		;;

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

		;;

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

#DEBHELPER#

exit 0