diff options
-rwxr-xr-x | contrib/sync-dbconfig | 81 | ||||
-rw-r--r-- | debian/control | 4 | ||||
-rw-r--r-- | src/util/sync-config.in | 4 |
3 files changed, 53 insertions, 36 deletions
diff --git a/contrib/sync-dbconfig b/contrib/sync-dbconfig index dc7339a..d0d3a4b 100755 --- a/contrib/sync-dbconfig +++ b/contrib/sync-dbconfig @@ -22,24 +22,22 @@ set -eu RESET_DB=0 SKIP_DBINIT=0 DBUSER="sync-httpd" -DBNAME="sync" -CFGFILE="/etc/taler/secrets/sync-db.secret.conf" +CFGFILE="/etc/sync/sync.conf" # Parse command-line options -while getopts ':hn:rsu:' OPTION; do +while getopts 'c:hrsu:' OPTION; do case "$OPTION" in + c) + CFGFILE="$OPTARG" + ;; 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 -- sync-httpd to be run by USER (default: $DBUSER)" exit 0 ;; - n) - DBNAME="$OPTARG" - ;; r) RESET_DB="1" ;; @@ -72,7 +70,9 @@ then if ! sync-dbinit -v 2> /dev/null then echo "Required 'sync-dbinit' not found. Please fix your installation." + exit 1 fi + DBINIT=$(which sync-dbinit) fi if ! id "$DBUSER" > /dev/null @@ -81,19 +81,6 @@ then 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 -fi - echo "Setting up database user $DBUSER." 1>&2 if ! sudo -i -u postgres createuser "$DBUSER" 2> /dev/null @@ -101,30 +88,60 @@ then echo "Database user '$DBUSER' already existed. Continuing anyway." 1>&2 fi -echo "Creating database $DBNAME." 1>&2 +DBPATH=$(sync-config \ + -c "$CFGFILE" \ + -s syncdb-postgres \ + -o CONFIG) -if ! sudo -i -u postgres createdb -O "$DBUSER" "$DBNAME" +if ! echo "$DBPATH" | grep "postgres://" > /dev/null then - echo "Failed to create database '$DBNAME'" + echo "Invalid database configuration value '$DBPATH'." 1>&2 exit 1 fi -if [ -f "$CFGFILE" ] +DBNAME=$(echo "$DBPATH" \ + | sed \ + -e "s/postgres:\/\/.*\///" \ + -e "s/?.*//") + +if sudo -i -u postgres psql "$DBNAME" < /dev/null 2> /dev/null then - echo "Adding database configuration to $CFGFILE." 1>&2 - echo -e "[syncdb-postgres]\nCONFIG=postgres:///$DBNAME\n" >> "$CFGFILE" + 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 - echo "Configuration $CFGFILE does not yet exist, creating it." 1>&2 - mkdir -p "$(dirname "$CFGFILE")" - echo -e "[syncdb-postgres]\nCONFIG=postgres:///$DBNAME\n" >> "$CFGFILE" - chown "$DBUSER":root "$CFGFILE" - chmod 460 "$CFGFILE" + 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 - sudo -u "$DBUSER" sync-dbinit -c "$CFGFILE" + if ! sudo -u "$DBUSER" "$DBINIT" -c "$CFGFILE" + then + echo "Failed to initialize database schema" + exit 1 + fi fi echo "Database configuration finished." 1>&2 diff --git a/debian/control b/debian/control index 4eb3db0..8a2c2c0 100644 --- a/debian/control +++ b/debian/control @@ -8,7 +8,7 @@ Build-Depends: autopoint, debhelper-compat (= 12), gettext, - libgnunet-dev (>=0.20), + libgnunet-dev (>=0.21), libtalerexchange-dev (>= 0.9.3), libtalermerchant-dev (>= 0.9.3), libpq-dev (>=14.0), @@ -66,7 +66,7 @@ Architecture: any Depends: libtalermerchant-dev (>= 0.9.3), libtalerexchange-dev (>= 0.9.3), - libgnunet-dev (>=0.20), + libgnunet-dev (>=0.21), ${misc:Depends}, ${shlibs:Depends} Description: libraries to talk to a Sync provider (development). diff --git a/src/util/sync-config.in b/src/util/sync-config.in index b1c4971..6a74245 100644 --- a/src/util/sync-config.in +++ b/src/util/sync-config.in @@ -7,7 +7,7 @@ if ! type gnunet-config >/dev/null; then exit 1 fi -GC=`which gnunet-config` -SO=`ls %libdir%/libsyncutil.so.* | sort -n | tail -n1` +GC=$(which gnunet-config) +SO=$(ls %libdir%/libsyncutil.so.* | sort -n | tail -n1) export LD_PRELOAD=${LD_PRELOAD:-}:${SO} exec gnunet-config "$@" |