gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[libeufin] 01/02: update Debian package of libeufin to include more DB s


From: gnunet
Subject: [libeufin] 01/02: update Debian package of libeufin to include more DB setup logic
Date: Thu, 02 Mar 2023 14:41:50 +0100

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository libeufin.

commit b5c14d235d63aacf5fa00ddf05a36dde20860106
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Thu Mar 2 14:40:51 2023 +0100

    update Debian package of libeufin to include more DB setup logic
---
 debian/db/install/pgsql  | 34 ++++++++++++++++++++++++++++++++++
 debian/libeufin.config   | 22 ++++++++++++++++++++++
 debian/libeufin.install  |  3 +++
 debian/libeufin.postinst | 32 ++++++++++++++++++++++++++++++++
 debian/libeufin.postrm   | 30 ++++++++++++++++++++++++++++++
 debian/libeufin.prerm    | 22 ++++++++++++++++++++++
 6 files changed, 143 insertions(+)

diff --git a/debian/db/install/pgsql b/debian/db/install/pgsql
new file mode 100755
index 00000000..5336037a
--- /dev/null
+++ b/debian/db/install/pgsql
@@ -0,0 +1,34 @@
+#!/bin/bash
+
+set -eu
+
+libeufindb_secretconf=/etc/libeufin-db.secret.conf
+
+# Get database settings from dbconfig-common and write Taler configuration 
files.
+if [ -f /etc/dbconfig-common/taler-libeufin.conf ]; then
+  . /etc/dbconfig-common/taler-libeufin.conf
+  case "$dbc_dbtype" in
+  pgsql)
+    # We assume ident auth here.  We might support password auth later.
+    echo -e "[libeufin-postgres]\nCONFIG=postgres:///${dbc_dbname}\n\n" > \
+      $libeufindb_secretconf
+
+    # Allow the libeufin-sandbox/nexus user to create schemas, needed by dbinit
+    echo "GRANT CREATE ON DATABASE \"${dbc_dbtype}\" TO \"libeufin-nexus\";" | 
sudo -u postgres psql -f -
+    echo "GRANT CREATE ON DATABASE \"${dbc_dbtype}\" TO \"libeufin-sandbox\";" 
| sudo -u postgres psql -f -
+    ;;
+  sqlite3)
+    # Later: use something like:
+    # sqlite:///$DATA_DIR/libeufin.db
+    # But for now, sqlite is unsupported:
+    echo "Unsupported database type $dbc_type."
+    exit 1
+    ;;
+  "") ;;
+
+  *)
+    echo "Unsupported database type $dbc_type."
+    exit 1
+    ;;
+  esac
+fi
diff --git a/debian/libeufin.config b/debian/libeufin.config
new file mode 100644
index 00000000..1e256c61
--- /dev/null
+++ b/debian/libeufin.config
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+set -e
+
+. /usr/share/debconf/confmodule
+
+_USERNAME=libeufin
+_GROUPNAME=libeufin
+
+# For now, we only support postgres
+dbc_dbtypes=pgsql
+dbc_dbuser=${_USERNAME}
+
+dbc_authmethod_user=ident
+dbc_authmethod_admin=ident
+
+if [ -f /usr/share/dbconfig-common/dpkg/config.pgsql ]; then
+    . /usr/share/dbconfig-common/dpkg/config.pgsql
+    dbc_go libeufin "$@"
+fi
+
+db_stop
diff --git a/debian/libeufin.install b/debian/libeufin.install
index 708dd6d4..38a82ded 100644
--- a/debian/libeufin.install
+++ b/debian/libeufin.install
@@ -1 +1,4 @@
 debian/etc/* etc/
+
+# Files needed by dbconf
+debian/db/install/* usr/share/dbconfig-common/scripts/libeufin/install/
diff --git a/debian/libeufin.postinst b/debian/libeufin.postinst
index 494eb031..b3586787 100644
--- a/debian/libeufin.postinst
+++ b/debian/libeufin.postinst
@@ -2,12 +2,37 @@
 
 set -e
 
+if [ -d /run/systemd/system ]; then
+        systemctl --system daemon-reload >/dev/null || true
+fi
+if [ "$1" = "remove" ]; then
+        if [ -x "/usr/bin/deb-systemd-helper" ]; then
+                deb-systemd-helper mask 'libeufin-nexus.service' >/dev/null || 
true
+                deb-systemd-helper mask 'libeufin-sandbox.service' >/dev/null 
|| true
+        fi
+fi
+
+if [ "$1" = "purge" ]; then
+        if [ -x "/usr/bin/deb-systemd-helper" ]; then
+                deb-systemd-helper purge 'libeufin-nexus.service' >/dev/null 
|| true
+                deb-systemd-helper purge 'libeufin-sandbox.service' >/dev/null 
|| true
+                deb-systemd-helper unmask 'libeufin-nexus.service' >/dev/null 
|| true
+                deb-systemd-helper unmask 'libeufin-sandbox.service' 
>/dev/null || true
+        fi
+fi
 nexus_user=libeufin-nexus
 sandbox_user=libeufin-sandbox
 nexus_group=libeufin-nexus
 sandbox_group=libeufin-sandbox
 libeufin_home=/var/lib/libeufin
 
+# Set permissions for sqlite3 file
+# (for when we support sqlite3 in the future)
+dbc_dbfile_owner="${_USERNAME}:${_GROUPNAME}"
+dbc_dbfile_perms="0600"
+
+. /usr/share/debconf/confmodule
+
 case "${1}" in
   configure)
 
@@ -29,6 +54,13 @@ case "${1}" in
       adduser --quiet --system --no-create-home --ingroup $sandbox_group 
--home $libeufin_home $sandbox_user
     fi
 
+    # Set up postgres database (needs dbconfig-pgsql package)
+    if [ -f /usr/share/dbconfig-common/dpkg/postinst.pgsql ]; then
+      . /usr/share/dbconfig-common/dpkg/postinst.pgsql
+      dbc_pgsql_createdb_encoding="UTF8"
+      dbc_go libeufin "$@"
+    fi
+
     ;;
 
   abort-upgrade|abort-remove|abort-deconfigure)
diff --git a/debian/libeufin.postrm b/debian/libeufin.postrm
new file mode 100644
index 00000000..56acce50
--- /dev/null
+++ b/debian/libeufin.postrm
@@ -0,0 +1,30 @@
+#!/bin/sh
+
+set -e
+
+if [ -f /usr/share/debconf/confmodule ]; then
+    . /usr/share/debconf/confmodule
+fi
+
+if [ -f /usr/share/dbconfig-common/dpkg/postrm.pgsql ]; then
+    . /usr/share/dbconfig-common/dpkg/postrm.pgsql
+    dbc_go libeufin "$@"
+fi
+
+case "${1}" in
+purge)
+# TODO: anything to clean up? Like:
+#  rm -f /etc/libeufin-db.conf
+  ;;
+remove | upgrade | failed-upgrade | abort-install | abort-upgrade | disappear)
+  ;;
+
+  *)
+  echo "postrm called with unknown argument \`${1}'" >&2
+  exit 1
+  ;;
+esac
+
+#DEBHELPER#
+
+exit 0
diff --git a/debian/libeufin.prerm b/debian/libeufin.prerm
new file mode 100644
index 00000000..5363996a
--- /dev/null
+++ b/debian/libeufin.prerm
@@ -0,0 +1,22 @@
+#!/bin/sh
+
+set -e
+
+if [ -d /run/systemd/system ] && [ "$1" = remove ]; then
+        deb-systemd-invoke stop 'libeufin-nexus.service' >/dev/null || true
+        deb-systemd-invoke stop 'libeufin-sandbox.service' >/dev/null || true
+fi
+
+if [ -f /usr/share/debconf/confmodule ]; then
+    . /usr/share/debconf/confmodule
+fi
+. /usr/share/dbconfig-common/dpkg/prerm
+
+if [ -f /usr/share/dbconfig-common/dpkg/prerm.pgsql ]; then
+    . /usr/share/dbconfig-common/dpkg/prerm.pgsql
+    dbc_go libeufin "$@"
+fi
+
+
+db_stop
+exit 0

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]