gnunet-svn
[Top][All Lists]
Advanced

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

[taler-merchant] 02/02: shfmt


From: gnunet
Subject: [taler-merchant] 02/02: shfmt
Date: Mon, 02 Dec 2024 23:38:03 +0100

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

dold pushed a commit to branch master
in repository merchant.

commit 603d5ba49bbbddf705dcb0f43bb68941180d5933
Author: Florian Dold <florian@dold.me>
AuthorDate: Mon Dec 2 23:37:57 2024 +0100

    shfmt
---
 contrib/taler-merchant-dbconfig | 172 ++++++++++++++++++----------------------
 1 file changed, 79 insertions(+), 93 deletions(-)

diff --git a/contrib/taler-merchant-dbconfig b/contrib/taler-merchant-dbconfig
index e698dc99..976f0ffa 100755
--- a/contrib/taler-merchant-dbconfig
+++ b/contrib/taler-merchant-dbconfig
@@ -26,123 +26,109 @@ CFGFILE="/etc/taler-merchant/taler-merchant.conf"
 
 # Parse command-line options
 while getopts 'c:hrsu:' OPTION; do
-    case "$OPTION" in
-        c)
-            CFGFILE="$OPTARG"
-            ;;
-        h)
-            echo 'Supported options:'
-            echo "  -c FILENAME  -- use configuration FILENAME (default: 
$CFGFILE)"
-            echo "  -h           -- print this help text"
-            echo "  -r           -- reset database (dangerous)"
-            echo "  -s           -- skip database initialization"
-            echo "  -u USER      -- taler-merchant to be run by USER (default: 
$DBUSER)"
-            exit 0
-            ;;
-        r)
-            RESET_DB="1"
-            ;;
-        s)
-            SKIP_DBINIT="1"
-            ;;
-        u)
-            DBUSER="$OPTARG"
-            ;;
-        ?)
-        echo "Unrecognized command line option '$OPTION'" 1&>2
-        exit 1
-        ;;
-    esac
+  case "$OPTION" in
+  c)
+    CFGFILE="$OPTARG"
+    ;;
+  h)
+    echo 'Supported options:'
+    echo "  -c FILENAME  -- use configuration FILENAME (default: $CFGFILE)"
+    echo "  -h           -- print this help text"
+    echo "  -r           -- reset database (dangerous)"
+    echo "  -s           -- skip database initialization"
+    echo "  -u USER      -- taler-merchant to be run by USER (default: 
$DBUSER)"
+    exit 0
+    ;;
+  r)
+    RESET_DB="1"
+    ;;
+  s)
+    SKIP_DBINIT="1"
+    ;;
+  u)
+    DBUSER="$OPTARG"
+    ;;
+  ?)
+    echo "Unrecognized command line option '$OPTION'" 1 &>2
+    exit 1
+    ;;
+  esac
 done
 
-if ! id postgres > /dev/null
-then
-    echo "Could not find 'postgres' user. Please install Postgresql first"
-    exit 1
+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
+if [ "$(id -u)" -ne 0 ]; then
+  echo "This script must be run as root"
+  exit 1
 fi
 
-if [ 0 = "$SKIP_DBINIT" ]
-then
-    if ! taler-merchant-dbinit -v 2> /dev/null
-    then
-        echo "Required 'taler-merchant-dbinit' not found. Please fix your 
installation."
-        exit 1
-    fi
-    DBINIT=$(which taler-merchant-dbinit)
+if [ 0 = "$SKIP_DBINIT" ]; then
+  if ! taler-merchant-dbinit -v 2>/dev/null; then
+    echo "Required 'taler-merchant-dbinit' not found. Please fix your 
installation."
+    exit 1
+  fi
+  DBINIT=$(which taler-merchant-dbinit)
 fi
 
-if ! id "$DBUSER" > /dev/null
-then
-    echo "Could not find '$DBUSER' user. Please set it up first"
-    exit 1
+if ! id "$DBUSER" >/dev/null; then
+  echo "Could not find '$DBUSER' user. Please set it up first"
+  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
+if ! sudo -i -u postgres createuser "$DBUSER" 2>/dev/null; then
+  echo "Database user '$DBUSER' already existed. Continuing anyway." 1>&2
 fi
 
 DBPATH=$(taler-merchant-config \
-             -c "$CFGFILE" \
-             -s merchantdb-postgres \
-             -o CONFIG)
+  -c "$CFGFILE" \
+  -s merchantdb-postgres \
+  -o CONFIG)
 
-if ! echo "$DBPATH" | grep "postgres://" > /dev/null
-then
-    echo "Invalid database configuration value '$DBPATH'." 1>&2
-    exit 1
+if ! echo "$DBPATH" | grep "postgres://" >/dev/null; then
+  echo "Invalid database configuration value '$DBPATH'." 1>&2
+  exit 1
 fi
 
-DBNAME=$(echo "$DBPATH" \
-         | sed \
-             -e "s/postgres:\/\/.*\///" \
-             -e "s/?.*//")
-
-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
-        if ! sudo -i -u postgres dropdb "$DBNAME"
-        then
-            echo "Failed to delete existing database '$DBNAME'"
-            exit 1
-        fi
-        DO_CREATE=1
-    else
-        echo "Database '$DBNAME' already exists, continuing anyway."
-        DO_CREATE=0
+DBNAME=$(echo "$DBPATH" |
+  sed \
+    -e "s/postgres:\/\/.*\///" \
+    -e "s/?.*//")
+
+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
+    if ! sudo -i -u postgres dropdb "$DBNAME"; then
+      echo "Failed to delete existing database '$DBNAME'"
+      exit 1
     fi
-else
     DO_CREATE=1
+  else
+    echo "Database '$DBNAME' already exists, continuing anyway."
+    DO_CREATE=0
+  fi
+else
+  DO_CREATE=1
 fi
 
-if [ 1 = "$DO_CREATE" ]
-then
-    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 [ 1 = "$DO_CREATE" ]; then
+  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
 fi
 
-if [ 0 = "$SKIP_DBINIT" ]
-then
-    echo "Initializing database $DBNAME." 1>&2
-    if ! sudo -u "$DBUSER" "$DBINIT" -c "$CFGFILE"
-    then
-        echo "Failed to initialize database schema"
-        exit 1
-    fi
+if [ 0 = "$SKIP_DBINIT" ]; then
+  echo "Initializing database $DBNAME." 1>&2
+  if ! sudo -u "$DBUSER" "$DBINIT" -c "$CFGFILE"; then
+    echo "Failed to initialize database schema"
+    exit 1
+  fi
 fi
 
 echo "Database configuration finished." 1>&2

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