taldir

Directory service to resolve wallet mailboxes by messenger addresses
Log | Files | Refs | Submodules | README | LICENSE

commit c901ef5be91bfe9e00bf3fc8000ad4defca13e69
parent 3a34e98312f472e994f00b1fdcf09e9269ea6384
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date:   Sat, 14 Feb 2026 21:16:25 +0100

add dbconfig tool

Diffstat:
MMakefile.in | 2++
Mconfigure | 2+-
Acontrib/taler-directory-dbconfig | 131+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 134 insertions(+), 1 deletion(-)

diff --git a/Makefile.in b/Makefile.in @@ -21,6 +21,8 @@ install: server tools install ./taler-directory-cli ${DESTDIR}${bindir} install ./taler-directory-config ${DESTDIR}${bindir} install ./taler-directory-dbinit ${DESTDIR}${bindir} + chmod +x ./contrib/taler-directory-dbconfig + install ./contrib/taler-directory-dbconfig ${DESTDIR}${bindir} cp -r ./web ${DESTDIR}${TALER_DIRECTORY_HOME}/ cp -r ./static ${DESTDIR}${TALER_DIRECTORY_HOME}/ cp -r ./sql ${DESTDIR}${TALER_DIRECTORY_HOME}/ diff --git a/configure b/configure @@ -1,7 +1,7 @@ #!/bin/sh pkg_name="taldir" -pkg_version="1.1.0" +pkg_version="2.0.1" pkg_default_features="" pkg_optional_features="" pkg_optional_dependencies="" diff --git a/contrib/taler-directory-dbconfig b/contrib/taler-directory-dbconfig @@ -0,0 +1,131 @@ +#!/bin/bash +# This file is part of GNU TALER. +# Copyright (C) 2026 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 +# @author Martin Schanzenbach +# +# +# Error checking on +set -eu + +RESET_DB=0 +SKIP_DBINIT=0 +DBUSER="taler-directory" +CFGFILE="/etc/taler-directory/taler-directory.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-directory 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 +fi + +if [ "$(id -u)" -ne 0 ]; then + echo "This script must be run as root" + exit 1 +fi + +if [ 0 = "$SKIP_DBINIT" ]; then + if ! taler-directory-dbinit -h 1>/dev/null 2>/dev/null; then + echo "Required 'taler-directory-dbinit' not found. Please fix your installation." + exit 1 + fi + DBINIT=$(which taler-directory-dbinit) +fi + +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 +fi + +DBNAME_CFG_ENTRY=$(taler-directory-config \ + -c "$CFGFILE" \ + -s taldir-pq \ + -o db_name) + +DBNAME=$(echo $DBNAME_CFG_ENTRY | cut -d'=' -f2 | xargs) + +echo $DBNAME + +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 + 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 +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 + +exit 0