exchange/debian/taler-exchange.postinst

260 lines
7.4 KiB
Plaintext
Raw Normal View History

#!/bin/bash
set -e
apache_install() {
mkdir -p /etc/apache2/conf-available
if [ ! -f /etc/apache2/conf-available/taler-exchange.conf ];
then
cp /etc/taler-exchange/apache.conf /etc/apache2/conf-available/taler-exchange.conf
fi
a2enmod proxy
a2enmod proxy_http
a2enmod headers
}
nginx_install() {
mkdir -p /etc/nginx/conf-available
if [ ! -f /etc/apache2/conf-available/taler-exchange.conf ];
then
cp /etc/taler-exchange/nginx.conf /etc/nginx/conf-available/taler-exchange.conf
fi
}
. /usr/share/debconf/confmodule
case "${1}" in
configure)
db_version 2.0
2020-12-28 13:14:11 +01:00
db_get taler-exchange/eusername
_EUSERNAME="${RET:-taler-exchange-httpd}"
2020-12-28 13:14:11 +01:00
db_get taler-exchange/rsecusername
2020-12-31 22:04:14 +01:00
_RSECUSERNAME="${RET:-taler-exchange-helper-rsa}"
2020-12-28 13:14:11 +01:00
db_get taler-exchange/esecusername
2020-12-31 22:04:14 +01:00
_ESECUSERNAME="${RET:-taler-exchange-helper-eddsa}"
2020-12-28 13:14:11 +01:00
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"
TALER_HOME="/var/lib/taler-exchange"
# 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
2020-12-28 13:14:11 +01:00
# Creating taler users if needed
if ! getent passwd ${_EUSERNAME} > /dev/null
then
2020-12-28 13:14:11 +01:00
echo -n "Creating new Taler user ${_EUSERNAME}:"
adduser --quiet --system --ingroup ${_GROUPNAME} --home ${TALER_HOME}/httpd ${_EUSERNAME}
adduser ${_EUSERNAME} ${_DBGROUPNAME}
echo " done."
fi
2020-12-28 13:14:11 +01:00
if ! getent passwd ${_RSECUSERNAME} > /dev/null
then
2020-12-28 13:14:11 +01:00
echo -n "Creating new Taler user ${_RSECUSERNAME}:"
2020-12-31 20:46:08 +01:00
adduser --quiet --system --ingroup ${_GROUPNAME} --home ${TALER_HOME}/helper-rsa ${_RSECUSERNAME}
2020-12-28 13:14:11 +01:00
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}/helper-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 ${_WIREUSERNAME} ${_DBGROUPNAME}
2020-12-28 13:14:11 +01:00
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 ${_AGGRUSERNAME} ${_DBGROUPNAME}
echo " done."
fi
2020-12-28 13:14:11 +01:00
# 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.
2020-12-28 13:14:11 +01:00
# please do not edit by hand, use 'dpkg-reconfigure taler-exchange'.
2020-12-28 13:14:11 +01:00
TALER_EUSER=${_EUSERNAME}
TALER_RSECUSER=${_RESCUSERNAME}
TALER_ESECUSER=${_ESECUSERNAME}
TALER_WIREUSER=${_WIREUSERNAME}
TALER_AGGRUSER=${_AGGRUSERNAME}
TALER_GROUP=${_GROUPNAME}
EOF
2020-12-28 13:14:11 +01:00
cat > "/etc/systemd/system/taler-exchange-httpd.service" <<EOF
[Unit]
2020-12-28 13:14:11 +01:00
Description=GNU Taler payment system exchange REST API
Requires=taler-exchange-helper-rsa.service taler-exchange-helper-eddsa.service
Wants=taler-exchange-wirewatch taler-exchange-aggregator taler-exchange-transfer
After=postgres.service network.target
[Service]
EnvironmentFile=/etc/default/taler-exchange
2020-12-28 13:14:11 +01:00
User=${_EUSERNAME}
Type=simple
Restart=on-failure
ExecStart=/usr/bin/taler-exchange-httpd -c /etc/taler-exchange.conf
[Install]
WantedBy=multi-user.target
2020-12-28 13:14:11 +01:00
EOF
cat > "/etc/systemd/system/taler-exchange-helper-rsa.service" <<EOF
[Unit]
Description=GNU Taler payment system exchange RSA security module
[Service]
EnvironmentFile=/etc/default/taler-exchange
2020-12-28 13:14:11 +01:00
User=${_RSECUSERNAME}
Type=simple
Restart=on-failure
ExecStart=/usr/bin/taler-helper-crypto-rsa -c /etc/taler-exchange.conf
2020-12-28 13:14:11 +01:00
[Install]
WantedBy=multi-user.target
EOF
cat > "/etc/systemd/system/taler-exchange-helper-eddsa.service" <<EOF
[Unit]
Description=GNU Taler payment system exchange EdDSA security module
[Service]
EnvironmentFile=/etc/default/taler-exchange
2020-12-28 13:14:11 +01:00
User=${_ESECUSERNAME}
Type=simple
Restart=on-failure
ExecStart=/usr/bin/taler-helper-crypto-eddsa -c /etc/taler-exchange.conf
2020-12-28 13:14:11 +01:00
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
2020-12-28 13:14:11 +01:00
User=${_WIREUSERNAME}
Type=simple
Restart=on-failure
ExecStart=/usr/bin/taler-exchange-wirewatch -c /etc/taler-wire.conf
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
2020-12-28 13:14:11 +01:00
User=${_WIREUSERNAME}
Type=simple
Restart=on-failure
ExecStart=/usr/bin/taler-exchange-wirewatch -c /etc/taler-wire.conf
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
2020-12-28 13:14:11 +01:00
User=${_AGGRUSERNAME}
Type=simple
Restart=on-failure
ExecStart=/usr/bin/taler-exchange-aggregator -c /etc/taler.conf
EOF
systemctl daemon-reload
cp -f "${CONFIG_NEW}" "${CONFIG_FILE}"
echo " done."
mkdir -p /var/lib/taler-exchange/tmp
chown root:taler /var/lib/taler-exchange/tmp
chmod 770 /var/lib/taler-exchange/tmp
chmod +s /var/lib/taler-exchange/tmp
# Setup postgres database (needs dbconfig-pgsql package)
if [ -f /usr/share/dbconfig-common/dpkg/postinst.pgsql ]; then
. /usr/share/dbconfig-common/dpkg/postinst.pgsql
# dbc_dbfile_* should not apply for Postgres, but better be safe...
dbc_dbfile_owner="${_EUSERNAME}:${_DBGROUPNAME}"
dbc_dbfile_perms="0660"
dbc_pgsql_createdb_encoding="UTF8"
dbc_go taler-exchange "$@"
fi
# get database settings from dbconfig-common
if [ -f /etc/dbconfig-common/taler-exchange.conf ]; then
. /etc/dbconfig-common/taler-exchange.conf
case "$dbc_dbtype" in
pgsql)
taler-config -c /etc/taler-exchange-db.conf \
-s "exchangedb-postgres" \
-o "CONFIG" \
-V "postgres://$dbc_dbuser:$dbc_dbpass@$dbc_dbserver/$dbc_dbname"
taler-config -c /etc/taler-exchange-db.conf \
-s "exchange" \
-o "DB" \
-V "postgres"
chown ${_EUSERNAME}:${_DBGROUPNAME} /etc/taler-exchange-db.conf
chmod 440 /etc/taler-exchange-db.conf
;;
"")
;;
*)
echo "Unsupported database type $dbc_type."
exit 1
;;
esac
fi
# 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