gnunet-svn
[Top][All Lists]
Advanced

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

[taler-exchange] branch master updated: format with shfmt


From: gnunet
Subject: [taler-exchange] branch master updated: format with shfmt
Date: Mon, 26 Aug 2024 20:09:57 +0200

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

dold pushed a commit to branch master
in repository exchange.

The following commit(s) were added to refs/heads/master by this push:
     new bb098bb4c format with shfmt
bb098bb4c is described below

commit bb098bb4cf22d1f1f24c383baf4ae988a8510907
Author: Florian Dold <florian@dold.me>
AuthorDate: Mon Aug 26 20:09:53 2024 +0200

    format with shfmt
---
 contrib/taler-auditor-dbconfig  | 139 +++++++++++-------------
 contrib/taler-exchange-dbconfig | 229 ++++++++++++++++++----------------------
 2 files changed, 169 insertions(+), 199 deletions(-)

diff --git a/contrib/taler-auditor-dbconfig b/contrib/taler-auditor-dbconfig
index 245d6970d..448c17c63 100755
--- a/contrib/taler-auditor-dbconfig
+++ b/contrib/taler-auditor-dbconfig
@@ -27,104 +27,93 @@ CFGFILE="/etc/taler/secrets/auditor-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      -- taler-auditor 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
+  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-auditor 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
+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-auditor-dbinit -v 2> /dev/null
-    then
-        echo "Required 'taler-auditor-dbinit' not found. Please fix your 
installation."
-    fi
+if [ 0 = "$SKIP_DBINIT" ]; then
+  if ! taler-auditor-dbinit -v 2>/dev/null; then
+    echo "Required 'taler-auditor-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
+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
+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
+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
+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 "[auditordb-postgres]\nCONFIG=postgres:///$DBNAME\n" >> "$CFGFILE"
+if [ -f "$CFGFILE" ]; then
+  echo "Adding database configuration to '$CFGFILE'." 1>&2
+  echo -e "[auditordb-postgres]\nCONFIG=postgres:///$DBNAME\n" >>"$CFGFILE"
 else
-    echo "Configuration '$CFGFILE' does not yet exist, creating it." 1>&2
-    mkdir -p "$(dirname "$CFGFILE")"
-    echo -e "[auditordb-postgres]\nCONFIG=postgres:///$DBNAME\n" >> "$CFGFILE"
-    chown "$DBUSER":root "$CFGFILE"
-    chmod 460 "$CFGFILE"
+  echo "Configuration '$CFGFILE' does not yet exist, creating it." 1>&2
+  mkdir -p "$(dirname "$CFGFILE")"
+  echo -e "[auditordb-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" taler-auditor-dbinit
+if [ 0 = "$SKIP_DBINIT" ]; then
+  echo "Initializing database '$DBNAME'." 1>&2
+  sudo -u "$DBUSER" taler-auditor-dbinit
 fi
 
 echo "Database configuration finished." 1>&2
diff --git a/contrib/taler-exchange-dbconfig b/contrib/taler-exchange-dbconfig
index eb90ee721..c3a608103 100755
--- a/contrib/taler-exchange-dbconfig
+++ b/contrib/taler-exchange-dbconfig
@@ -28,157 +28,138 @@ CFGFILE="/etc/taler/taler.conf"
 
 # Parse command-line options
 while getopts 'c:g:hprsu:' OPTION; do
-    case "$OPTION" in
-        c)
-            CFGFILE="$OPTARG"
-            ;;
-        h)
-            echo 'Supported options:'
-            echo "  -c FILENAME  -- use configuration FILENAME (default: 
$CFGFILE)"
-            echo "  -g GROUP     -- taler-exchange to be run by GROUP 
(default: $DBGROUP)"
-            echo "  -h           -- print this help text"
-            echo "  -r           -- reset database (dangerous)"
-            echo "  -p           -- force permission setup even without 
database initialization"
-            echo "  -s           -- skip database initialization"
-            echo "  -u USER      -- taler-exchange to be run by USER (default: 
$DBUSER)"
-            exit 0
-            ;;
-        p)
-            FORCE_PERMS="1"
-            ;;
-        r)
-            RESET_DB="1"
-            ;;
-        s)
-            SKIP_DBINIT="1"
-            ;;
-        u)
-            DBUSER="$OPTARG"
-            ;;
-        ?)
-            echo "Unrecognized command line 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 "  -g GROUP     -- taler-exchange to be run by GROUP (default: 
$DBGROUP)"
+    echo "  -h           -- print this help text"
+    echo "  -r           -- reset database (dangerous)"
+    echo "  -p           -- force permission setup even without database 
initialization"
+    echo "  -s           -- skip database initialization"
+    echo "  -u USER      -- taler-exchange to be run by USER (default: 
$DBUSER)"
+    exit 0
+    ;;
+  p)
+    FORCE_PERMS="1"
+    ;;
+  r)
+    RESET_DB="1"
+    ;;
+  s)
+    SKIP_DBINIT="1"
+    ;;
+  u)
+    DBUSER="$OPTARG"
+    ;;
+  ?)
+    echo "Unrecognized command line 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-exchange-dbinit -v 2> /dev/null
-    then
-        echo "Required 'taler-exchange-dbinit' not found. Please fix your 
installation."
-        exit 1
-    fi
-    DBINIT=$(which taler-exchange-dbinit)
+if [ 0 = "$SKIP_DBINIT" ]; then
+  if ! taler-exchange-dbinit -v 2>/dev/null; then
+    echo "Required 'taler-exchange-dbinit' not found. Please fix your 
installation."
+    exit 1
+  fi
+  DBINIT=$(which taler-exchange-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-config \
-             -c "$CFGFILE" \
-             -s exchangedb-postgres \
-             -o CONFIG)
+  -c "$CFGFILE" \
+  -s exchangedb-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 [ 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 ! 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
 
-if [ 0 = "$SKIP_DBINIT" ] || [ 1 = "$FORCE_PERMS" ]
-then
-    DB_GRP="$(getent group "$DBGROUP" | sed -e "s/.*://g" -e "s/,/ /g")"
-    echo "Initializing permissions for '$DB_GRP'." 1>&2
-    for GROUPIE in $DB_GRP
-    do
-        if [ "$GROUPIE" != "$DBUSER" ]
-        then
-            if ! sudo -i -u postgres createuser "$GROUPIE" 2> /dev/null
-            then
-                echo "Database user '$GROUPIE' already existed. Continuing 
anyway." 1>&2
-            fi
-            echo -e 'GRANT SELECT,INSERT,UPDATE,DELETE ON ALL TABLES IN SCHEMA 
exchange TO "'"$GROUPIE"'";\n' \
-                    'GRANT USAGE ON ALL SEQUENCES IN SCHEMA exchange TO 
"'"$GROUPIE"'";\n' \
-                | sudo -u "$DBUSER" psql "$DBNAME"
-            echo -e 'GRANT USAGE ON SCHEMA exchange TO "'"$GROUPIE"'"' \
-                | sudo -u "$DBUSER" psql "$DBNAME"
-           # FIXME: double-check the following GRANTs
-            echo -e 'GRANT USAGE ON SCHEMA _v TO "'"$GROUPIE"'"' \
-                | sudo -u "$DBUSER" psql "$DBNAME"
-            echo -e 'GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA _v TO 
"'"$GROUPIE"'"' \
-                | sudo -u "$DBUSER" psql "$DBNAME"
-
-
-        fi
-    done
+if [ 0 = "$SKIP_DBINIT" ] || [ 1 = "$FORCE_PERMS" ]; then
+  DB_GRP="$(getent group "$DBGROUP" | sed -e "s/.*://g" -e "s/,/ /g")"
+  echo "Initializing permissions for '$DB_GRP'." 1>&2
+  for GROUPIE in $DB_GRP; do
+    if [ "$GROUPIE" != "$DBUSER" ]; then
+      if ! sudo -i -u postgres createuser "$GROUPIE" 2>/dev/null; then
+        echo "Database user '$GROUPIE' already existed. Continuing anyway." 
1>&2
+      fi
+      echo -e 'GRANT SELECT,INSERT,UPDATE,DELETE ON ALL TABLES IN SCHEMA 
exchange TO "'"$GROUPIE"'";\n' \
+        'GRANT USAGE ON ALL SEQUENCES IN SCHEMA exchange TO "'"$GROUPIE"'";\n' 
|
+        sudo -u "$DBUSER" psql "$DBNAME"
+      echo -e 'GRANT USAGE ON SCHEMA exchange TO "'"$GROUPIE"'"' |
+        sudo -u "$DBUSER" psql "$DBNAME"
+      # FIXME: double-check the following GRANTs
+      echo -e 'GRANT USAGE ON SCHEMA _v TO "'"$GROUPIE"'"' |
+        sudo -u "$DBUSER" psql "$DBNAME"
+      echo -e 'GRANT ALL PRIVILEGES ON ALL TABLES IN SCHEMA _v TO 
"'"$GROUPIE"'"' |
+        sudo -u "$DBUSER" psql "$DBNAME"
+
+    fi
+  done
 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]