commit 2f35fcfa0dae5b65ecc8e4fa20d23b5d5f137c13
parent 590248aa69ef5b3a6600e542e912a0201250898c
Author: Florian Dold <florian@dold.me>
Date: Thu, 13 Nov 2025 22:57:50 +0100
shfmt
Diffstat:
1 file changed, 57 insertions(+), 22 deletions(-)
diff --git a/contrib/libeufin-dbconfig b/contrib/libeufin-dbconfig
@@ -35,16 +35,15 @@ function exit_fail() {
exit 1
}
-VALID_ARGS=`getopt -o b:hrn:psu:v: -l bank-config:,help,nexus-config:,reset,skip,permissions,nexus-user:,bank-user:,only-nexus,only-bank -n 'libeufin-dbconfig' -- "$@"`
+VALID_ARGS=$(getopt -o b:hrn:psu:v: -l bank-config:,help,nexus-config:,reset,skip,permissions,nexus-user:,bank-user:,only-nexus,only-bank -n 'libeufin-dbconfig' -- "$@")
-if [ $? != 0 ] ;
-then
- exit 1 ;
+if [ $? != 0 ]; then
+ exit 1
fi
eval set -- "$VALID_ARGS"
function usage {
- cat - <<EOF
+ cat - <<EOF
libeufin-dbconfig
Setup databases for libeufin components.
Arguments mandatory for long options are also mandatory for short options.
@@ -64,18 +63,54 @@ EOF
# Parse command-line options
while true; do
case "$1" in
- -b | --bank-config) BANK_CFGFILE="$1"; shift 2 ;;
- -h | --help) usage; exit 0 ;;
- -r | --reset) RESET_DB="1"; shift ;;
- -s | --skip) SKIP_INIT="1"; shift ;;
- -n | --nexus-config) NEXUS_CFGFILE="$1"; shift 2 ;;
- -p | --permissions) FORCE_PERMS="1"; shift ;;
- --only-nexus) SKIP_BANK="1"; shift ;;
- --only-bank) SKIP_NEXUS="1"; shift ;;
- -u | --nexus-user) NEXUS_DBUSER="$1"; shift 2 ;;
- -v | --bank-user) BANK_DBUSER="$1"; shift 2 ;;
- --) shift; break ;;
- *) usage; exit 1 ;;
+ -b | --bank-config)
+ BANK_CFGFILE="$1"
+ shift 2
+ ;;
+ -h | --help)
+ usage
+ exit 0
+ ;;
+ -r | --reset)
+ RESET_DB="1"
+ shift
+ ;;
+ -s | --skip)
+ SKIP_INIT="1"
+ shift
+ ;;
+ -n | --nexus-config)
+ NEXUS_CFGFILE="$1"
+ shift 2
+ ;;
+ -p | --permissions)
+ FORCE_PERMS="1"
+ shift
+ ;;
+ --only-nexus)
+ SKIP_BANK="1"
+ shift
+ ;;
+ --only-bank)
+ SKIP_NEXUS="1"
+ shift
+ ;;
+ -u | --nexus-user)
+ NEXUS_DBUSER="$1"
+ shift 2
+ ;;
+ -v | --bank-user)
+ BANK_DBUSER="$1"
+ shift 2
+ ;;
+ --)
+ shift
+ break
+ ;;
+ *)
+ usage
+ exit 1
+ ;;
esac
done
@@ -135,11 +170,11 @@ if [ 0 = "$SKIP_BANK" ]; then
BANK_DBNAME=$(get_db_name "$(libeufin-bank config get libeufin-bankdb-postgres CONFIG)" "bank")
fi
if [ 0 = "$SKIP_NEXUS" ]; then
- NEXUS_DBNAME=$(get_db_name "$(libeufin-nexus config get nexus-postgres CONFIG 2> /dev/null || libeufin-nexus config get libeufin-nexusdb-postgres CONFIG)" "nexus")
+ NEXUS_DBNAME=$(get_db_name "$(libeufin-nexus config get nexus-postgres CONFIG 2>/dev/null || libeufin-nexus config get libeufin-nexusdb-postgres CONFIG)" "nexus")
fi
# If using both components they must use the same database
-if [[ 0 = "$SKIP_BANK" && 0 = "$SKIP_NEXUS" && "$NEXUS_DBNAME" != "$BANK_DBNAME" ]]; then
+if [[ 0 == "$SKIP_BANK" && 0 == "$SKIP_NEXUS" && $NEXUS_DBNAME != "$BANK_DBNAME" ]]; then
exit_fail "Database names for libeufin-bank and libeufin-nexus must match ($NEXUS_DBNAME vs $BANK_DBNAME)"
fi
@@ -204,7 +239,7 @@ if [ 0 = "$SKIP_INIT" ]; then
fi
# nexus permission to access db and _v schema if bank init the database
-if [[ 0 = "$SKIP_INIT" || 1 = "$FORCE_PERMS" ]] && [[ 0 = "$SKIP_BANK" && 0 = "$SKIP_NEXUS" ]]; then
+if [[ 0 == "$SKIP_INIT" || 1 == "$FORCE_PERMS" ]] && [[ 0 == "$SKIP_BANK" && 0 == "$SKIP_NEXUS" ]]; then
echo "Setting postgres permissions for '$NEXUS_DBUSER'" 1>&2
grant_db_access "$NEXUS_DBUSER"
grant_schema_access "$NEXUS_DBUSER" "_v"
@@ -212,13 +247,13 @@ if [[ 0 = "$SKIP_INIT" || 1 = "$FORCE_PERMS" ]] && [[ 0 = "$SKIP_BANK" && 0 =
fi
# DB initialization for nexus if both component are setup
-if [[ 0 = "$SKIP_INIT" && 0 = "$SKIP_BANK" && 0 = "$SKIP_NEXUS" ]]; then
+if [[ 0 == "$SKIP_INIT" && 0 == "$SKIP_BANK" && 0 == "$SKIP_NEXUS" ]]; then
echo "Initializing database '$DBNAME' for libeufin-nexus." 1>&2
sudo -u "$NEXUS_DBUSER" "$NEXUS_DBINIT" -c "$NEXUS_CFGFILE"
fi
# bank permission to access nexus schema if both component are setup
-if [[ 0 = "$SKIP_INIT" || 1 = "$FORCE_PERMS" ]] && [[ 0 = "$SKIP_BANK" && 0 = "$SKIP_NEXUS" ]]; then
+if [[ 0 == "$SKIP_INIT" || 1 == "$FORCE_PERMS" ]] && [[ 0 == "$SKIP_BANK" && 0 == "$SKIP_NEXUS" ]]; then
echo "Setting postgres permissions for '$BANK_DBUSER'" 1>&2
grant_schema_access "$BANK_DBUSER" "libeufin_nexus"
fi