gnunet-svn
[Top][All Lists]
Advanced

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

[taler-sync] branch master updated: add taler-sync-dbconfig


From: gnunet
Subject: [taler-sync] branch master updated: add taler-sync-dbconfig
Date: Fri, 11 Aug 2023 01:03:36 +0200

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

grothoff pushed a commit to branch master
in repository sync.

The following commit(s) were added to refs/heads/master by this push:
     new 8e61b9f  add taler-sync-dbconfig
8e61b9f is described below

commit 8e61b9ff9ea223e8c92317a46ef77013401b3ffe
Author: Christian Grothoff <christian@grothoff.org>
AuthorDate: Fri Aug 11 01:03:34 2023 +0200

    add taler-sync-dbconfig
---
 Makefile.am                 |   7 +--
 configure.ac                |   1 +
 contrib/Makefile.am         |  11 ++++
 contrib/taler-sync-dbconfig | 132 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 146 insertions(+), 5 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 3227908..d7a53ea 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -8,9 +8,9 @@ else
 endif
 else
 if ENABLE_DOC
-  SUBDIRS = . src doc
+  SUBDIRS = . src doc contrib
 else
-  SUBDIRS = . src doc
+  SUBDIRS = . src doc contrib
 endif
 endif
 
@@ -20,7 +20,4 @@ ACLOCAL_AMFLAGS = -I m4
 EXTRA_DIST = \
  AUTHORS \
  COPYING.AGPL \
- contrib/gnunet.tag \
- contrib/uncrustify.cfg \
- contrib/uncrustify_precommit \
  Doxyfile
diff --git a/configure.ac b/configure.ac
index 2d9b750..40a19d5 100644
--- a/configure.ac
+++ b/configure.ac
@@ -329,6 +329,7 @@ AM_CONDITIONAL([HAVE_EXPERIMENTAL], [test 
"x$enable_experimental" = "xyes"])
 
 
 AC_CONFIG_FILES([Makefile
+contrib/Makefile
 doc/Makefile
 src/Makefile
 src/include/Makefile
diff --git a/contrib/Makefile.am b/contrib/Makefile.am
new file mode 100644
index 0000000..f187d1c
--- /dev/null
+++ b/contrib/Makefile.am
@@ -0,0 +1,11 @@
+# This file is in the public domain.
+
+SUBDIRS = .
+
+bin_SCRIPTS = \
+  sync-dbconfig
+
+EXTRA_DIST = \
+  gnunet.tag \
+  uncrustify.cfg \
+  uncrustify_precomit
diff --git a/contrib/taler-sync-dbconfig b/contrib/taler-sync-dbconfig
new file mode 100755
index 0000000..8562fd9
--- /dev/null
+++ b/contrib/taler-sync-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
+
+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
+
+RESET_DB=0
+SKIP_DBINIT=0
+DBUSER="sync-httpd"
+DBNAME="sync"
+CFGFILE="/etc/taler/secrets/sync-db.secret.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      -- sync-httpd 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 [ 0 = "$SKIP_DBINIT" ]
+then
+    if ! sync-dbinit -v 2> /dev/null
+    then
+        echo "Required 'sync-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 "[syncdb-postgres]\nCONFIG=postgres:///$DBNAME\n" >> "$CFGFILE"
+else
+    echo "Configuration $CFGFILE does not yet exist, creating it." 1>&2
+    mkdir -p "$(dirname "$CFGFILE")"
+    echo -e "[syncdb-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 -i -u "$DBUSER" sync-dbinit
+fi
+
+echo "Database configuration finished." 1>&2
+
+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]