challenger

OAuth 2.0-based authentication service that validates user can receive messages at a certain address
Log | Files | Refs | Submodules | README | LICENSE

commit 836da1b8cc42ef9d076200686da0aa0be9a8ba67
parent e3516be513762e5d3bb44b1a1a8e868dcc1d061a
Author: Christian Grothoff <grothoff@gnunet.org>
Date:   Wed, 22 Jul 2026 17:42:27 +0200

-fix error message

Diffstat:
Mcontrib/challenger-dbconfig | 96+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
1 file changed, 55 insertions(+), 41 deletions(-)

diff --git a/contrib/challenger-dbconfig b/contrib/challenger-dbconfig @@ -51,39 +51,45 @@ while getopts 'c:hrsu:' OPTION; do DBUSER="$OPTARG" ;; ?) - echo "Unrecognized command line option '$OPTARG'" 1>&2 + echo "Unrecognized command line option '$OPTION'" 1>&2 exit 1 ;; esac done -if ! id postgres >/dev/null; then +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 +if [ "$(id -u)" -ne 0 ]; +then echo "This script must be run as root" exit 1 fi -if [ 0 = "$SKIP_DBINIT" ]; then - if ! challenger-dbinit -v 2>/dev/null; then - echo "Required 'challenger-dbinit' not found. Please fix your installation." - exit 1 - fi - DBINIT=$(which challenger-dbinit) +if [ 0 = "$SKIP_DBINIT" ]; +then + if ! challenger-dbinit -v 2>/dev/null; + then + echo "Required 'challenger-dbinit' not found. Please fix your installation." + exit 1 + fi + DBINIT=$(which challenger-dbinit) fi -if ! id "$DBUSER" >/dev/null; then - echo "Could not find '$DBUSER' user. Please create it up first" - exit 1 +if ! id "$DBUSER" >/dev/null; +then + echo "Could not find '$DBUSER' user. Please create 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=$(challenger-config \ @@ -91,9 +97,10 @@ DBPATH=$(challenger-config \ -s challengerdb-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" | @@ -101,37 +108,44 @@ DBNAME=$(echo "$DBPATH" | -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 +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 - DO_CREATE=1 - else - echo "Database '$DBNAME' already exists, continuing anyway." - DO_CREATE=0 - fi else - DO_CREATE=1 + 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 echo "Database configuration finished." 1>&2