[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[libeufin] branch master updated: adjust dbconfig scripts to better supp
From: |
gnunet |
Subject: |
[libeufin] branch master updated: adjust dbconfig scripts to better support database sharing |
Date: |
Thu, 30 Nov 2023 06:57:26 +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 99b5c6c4 adjust dbconfig scripts to better support database sharing
99b5c6c4 is described below
commit 99b5c6c428026af8ac8c5fbf17e3cbc10d677a6f
Author: Christian Grothoff <grothoff@gnunet.org>
AuthorDate: Thu Nov 30 14:57:17 2023 +0900
adjust dbconfig scripts to better support database sharing
---
contrib/libeufin-bank-dbconfig | 42 ++++++++++++++++++++++++-----------------
contrib/libeufin-bank-dbinit | 3 ++-
contrib/libeufin-nexus-dbconfig | 41 +++++++++++++++++++++++-----------------
contrib/libeufin-nexus-dbinit | 3 ++-
4 files changed, 53 insertions(+), 36 deletions(-)
diff --git a/contrib/libeufin-bank-dbconfig b/contrib/libeufin-bank-dbconfig
index 5f0a09f4..8a685bd8 100755
--- a/contrib/libeufin-bank-dbconfig
+++ b/contrib/libeufin-bank-dbconfig
@@ -72,7 +72,9 @@ then
if ! libeufin-bank-dbinit --help 1> /dev/null # -v not provided
then
echo "Required 'libeufin-bank-dbinit' not found. Please fix your
installation."
+ exit 1
fi
+ BANK_DBINIT=$(which libeufin-bank-dbinit)
fi
if ! id "$DBUSER" > /dev/null
@@ -81,6 +83,14 @@ then
exit 1
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
+
+
if sudo -i -u postgres psql "$DBNAME" < /dev/null 2> /dev/null
then
if [ 1 = "$RESET_DB" ]
@@ -88,26 +98,24 @@ 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
+ echo "Database '$DBNAME' already exists."
+ if ! echo "GRANT ALL PRIVILEGES ON $DBNAME TO '$DBUSER'" \
+ | sudo -i -u postgres psql "$DBNAME"
+ then
+ echo "Failed to grant access to database '$DBNAME' to '$DBUSER'."
1>&2
+ exit 1
+ fi
fi
-fi
-
-echo "Setting up database user $DBUSER." 1>&2
+else
+ echo "Creating database $DBNAME." 1>&2
-if ! sudo -i -u postgres createuser "$DBUSER" 2> /dev/null
-then
- echo "Database user '$DBUSER' already existed. Continuing anyway." 1>&2
+ if ! sudo -i -u postgres createdb -O "$DBUSER" "$DBNAME"
+ then
+ echo "Failed to create database '$DBNAME'." 1>&2
+ exit 1
+ fi
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
@@ -124,7 +132,7 @@ fi
if [ 0 = "$SKIP_DBINIT" ]
then
echo "Initializing database $DBNAME." 1>&2
- sudo -u "$DBUSER" libeufin-bank-dbinit
+ sudo -u "$DBUSER" "$BANK_DBINIT" -c "$CFGFILE"
fi
echo "Database configuration finished." 1>&2
diff --git a/contrib/libeufin-bank-dbinit b/contrib/libeufin-bank-dbinit
index a0f155bf..f60ac340 100755
--- a/contrib/libeufin-bank-dbinit
+++ b/contrib/libeufin-bank-dbinit
@@ -1,3 +1,4 @@
#!/bin/sh
-exec libeufin-bank dbinit "$@"
+DIR=$(dirname $0)
+exec ${DIR}/libeufin-bank dbinit "$@"
diff --git a/contrib/libeufin-nexus-dbconfig b/contrib/libeufin-nexus-dbconfig
index 8a0ecc8d..aa7ad4ee 100755
--- a/contrib/libeufin-nexus-dbconfig
+++ b/contrib/libeufin-nexus-dbconfig
@@ -72,7 +72,9 @@ then
if ! libeufin-nexus-dbinit --help 1> /dev/null # -v not provided
then
echo "Required 'libeufin-nexus-dbinit' not found. Please fix your
installation."
+ exit 1
fi
+ NEXUS_DBINIT=$(which libeufin-nexus-dbinit)
fi
if ! id "$DBUSER" > /dev/null
@@ -81,6 +83,13 @@ then
exit 1
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
+
if sudo -i -u postgres psql "$DBNAME" < /dev/null 2> /dev/null
then
if [ 1 = "$RESET_DB" ]
@@ -88,26 +97,24 @@ 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
+ echo "Database '$DBNAME' already exists."
+ if ! echo "GRANT ALL PRIVILEGES ON DATABASE $DBNAME TO \"$DBUSER\"" \
+ | sudo -i -u postgres psql "$DBNAME"
+ then
+ echo "Failed to grant access to database '$DBNAME' to '$DBUSER'."
1>&2
+ exit 1
+ fi
fi
-fi
-
-echo "Setting up database user $DBUSER." 1>&2
+else
+ echo "Creating database $DBNAME." 1>&2
-if ! sudo -i -u postgres createuser "$DBUSER" 2> /dev/null
-then
- echo "Database user '$DBUSER' already existed. Continuing anyway." 1>&2
+ if ! sudo -i -u postgres createdb -O "$DBUSER" "$DBNAME"
+ then
+ echo "Failed to create database '$DBNAME'." 1>&2
+ exit 1
+ fi
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
@@ -124,7 +131,7 @@ fi
if [ 0 = "$SKIP_DBINIT" ]
then
echo "Initializing database $DBNAME." 1>&2
- sudo -u "$DBUSER" libeufin-nexus-dbinit
+ sudo -u "$DBUSER" "$NEXUS_DBINIT" -c "$CFGFILE"
fi
echo "Database configuration finished." 1>&2
diff --git a/contrib/libeufin-nexus-dbinit b/contrib/libeufin-nexus-dbinit
index 9fc0cc46..6bb82b65 100755
--- a/contrib/libeufin-nexus-dbinit
+++ b/contrib/libeufin-nexus-dbinit
@@ -1,2 +1,3 @@
#!/bin/sh
-exec libeufin-nexus dbinit "$@"
+DIR=$(dirname $0)
+exec ${DIR}/libeufin-nexus dbinit "$@"
--
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [libeufin] branch master updated: adjust dbconfig scripts to better support database sharing,
gnunet <=