gnunet-svn
[Top][All Lists]
Advanced

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

[libeufin] branch master updated: add libeufin-bank-dbconfig script


From: gnunet
Subject: [libeufin] branch master updated: add libeufin-bank-dbconfig script
Date: Sun, 26 Nov 2023 23:22:41 +0100

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

grothoff pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 981e2fc1 add libeufin-bank-dbconfig script
981e2fc1 is described below

commit 981e2fc15fdb5d0bdf2d5d0711c402ef656d60fb
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Mon Nov 27 07:22:34 2023 +0900

    add libeufin-bank-dbconfig script
---
 .../{libeufin-bank => libeufin}/libeufin-bank.conf |   0
 debian/libeufin-bank.libeufin-bank.service         |   2 +-
 debian/usr/bin/libeufin-bank-dbconfig              | 132 +++++++++++++++++++++
 debian/usr/bin/libeufin-bank-dbinit                |   3 +
 4 files changed, 136 insertions(+), 1 deletion(-)

diff --git a/debian/etc/libeufin-bank/libeufin-bank.conf 
b/debian/etc/libeufin/libeufin-bank.conf
similarity index 100%
rename from debian/etc/libeufin-bank/libeufin-bank.conf
rename to debian/etc/libeufin/libeufin-bank.conf
diff --git a/debian/libeufin-bank.libeufin-bank.service 
b/debian/libeufin-bank.libeufin-bank.service
index 4594fe48..c364758c 100644
--- a/debian/libeufin-bank.libeufin-bank.service
+++ b/debian/libeufin-bank.libeufin-bank.service
@@ -3,7 +3,7 @@ Description=LibEuFin Bank service.
 
 [Service]
 User=libeufin-bank
-ExecStart=/usr/bin/libeufin-bank serve -c /etc/libeufin-bank/libeufin-bank.conf
+ExecStart=/usr/bin/libeufin-bank serve -c /etc/libeufin/libeufin-bank.conf
 Restart=on-failure
 RestartSec=1s
 
diff --git a/debian/usr/bin/libeufin-bank-dbconfig 
b/debian/usr/bin/libeufin-bank-dbconfig
new file mode 100755
index 00000000..888bf09b
--- /dev/null
+++ b/debian/usr/bin/libeufin-bank-dbconfig
@@ -0,0 +1,132 @@
+#!/bin/bash
+# This file is part of GNU TALER.
+# Copyright (C) 2023 Taler Systems SA
+#
+# TALER is free software; you can redistribute it and/or modify it under the
+# terms of the GNU Lesser General Public License as published by the Free 
Software
+# Foundation; either version 2.1, or (at your option) any later version.
+#
+# TALER is distributed in the hope that it will be useful, but WITHOUT ANY
+# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+# A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more 
details.
+#
+# You should have received a copy of the GNU Lesser General Public License 
along with
+# TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
+#
+# @author Christian Grothoff
+#
+#
+# Error checking on
+set -eu
+
+RESET_DB=0
+SKIP_DBINIT=0
+DBUSER="libeufin-bank"
+DBNAME="libeufinbank"
+CFGFILE="/etc/libeufin/libeufin-bank.conf"
+
+# Parse command-line options
+while getopts ':hn:rsu:' OPTION; do
+    case "$OPTION" in
+        h)
+            echo 'Supported options:'
+            echo "  -c FILENAME  -- write configuration to FILENAME (default: 
$CFGFILE)"
+            echo "  -n NAME      -- user NAME for database name (default: 
$DBNAME)"
+            echo "  -r           -- reset database (dangerous)"
+            echo "  -s           -- skip database initialization"
+            echo "  -u USER      -- taler-merchant to be run by USER (default: 
$DBUSER)"
+            exit 0
+            ;;
+        n)
+            DBNAME="$OPTARG"
+            ;;
+        r)
+            RESET_DB="1"
+            ;;
+        s)
+            SKIP_DBINIT="1"
+            ;;
+        u)
+            DBUSER="$OPTARG"
+            ;;
+        ?)
+        exit_fail "Unrecognized command line option"
+        ;;
+    esac
+done
+
+if ! id postgres > /dev/null
+then
+    echo "Could not find 'postgres' user. Please install Postgresql first"
+    exit 1
+fi
+
+if [ "$(id -u)" -ne 0 ]
+then
+    echo "This script must be run as root"
+    exit 1
+fi
+
+if [ 0 = "$SKIP_DBINIT" ]
+then
+    if ! libeufin-bank-dbinit -v 2> /dev/null
+    then
+        echo "Required 'libeufin-bank-dbinit' not found. Please fix your 
installation."
+    fi
+fi
+
+if ! id "$DBUSER" > /dev/null
+then
+    echo "Could not find '$DBUSER' user. Please set it up first"
+    exit 1
+fi
+
+if sudo -i -u postgres psql "$DBNAME" < /dev/null 2> /dev/null
+then
+    if [ 1 = "$RESET_DB" ]
+    then
+        echo "Deleting existing database $DBNAME." 1>&2
+        sudo -i -u postgres dropdb "$DBNAME"
+    else
+        echo "Database '$DBNAME' already exists, refusing to setup again."
+        echo "Use -r to delete the existing database first (dangerous!)."
+        exit 77
+    fi
+fi
+
+echo "Setting up database user $DBUSER." 1>&2
+
+if ! sudo -i -u postgres createuser "$DBUSER" 2> /dev/null
+then
+    echo "Database user '$DBUSER' already existed. Continuing anyway." 1>&2
+fi
+
+echo "Creating database $DBNAME." 1>&2
+
+if ! sudo -i -u postgres createdb -O "$DBUSER" "$DBNAME"
+then
+    echo "Failed to create database '$DBNAME'"
+    exit 1
+fi
+
+if [ -f "$CFGFILE" ]
+then
+    echo "Adding database configuration to $CFGFILE." 1>&2
+    echo -e "[libeufin-bankdb-postgres]\nCONFIG=postgres:///$DBNAME\n" >> 
"$CFGFILE"
+else
+    echo "Configuration $CFGFILE does not yet exist, creating it." 1>&2
+    mkdir -p "$(dirname "$CFGFILE")"
+    echo -e "[libeufin-bankdb-postgres]\nCONFIG=postgres:///$DBNAME\n" >> 
"$CFGFILE"
+    chown "$DBUSER":root "$CFGFILE"
+    chmod 460 "$CFGFILE"
+fi
+
+if [ 0 = "$SKIP_DBINIT" ]
+then
+    echo "Initializing database $DBNAME." 1>&2
+    sudo -u "$DBUSER" libeufin-bank-dbinit
+fi
+
+echo "Database configuration finished." 1>&2
+
+exit 0
diff --git a/debian/usr/bin/libeufin-bank-dbinit 
b/debian/usr/bin/libeufin-bank-dbinit
new file mode 100755
index 00000000..a0f155bf
--- /dev/null
+++ b/debian/usr/bin/libeufin-bank-dbinit
@@ -0,0 +1,3 @@
+#!/bin/sh
+exec libeufin-bank dbinit "$@"
+

-- 
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]