From fcea70fad29416440fb8f5839e8b1d7e0e7d2a54 Mon Sep 17 00:00:00 2001 From: Andreas Jonsson Date: Thu, 4 Jul 2019 18:49:18 +0200 Subject: [PATCH] Bug 23141: Add option to select db credentials source when populating db. --- debian/scripts/koha-create | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/debian/scripts/koha-create b/debian/scripts/koha-create index fb8fb73366..04d9fb4a53 100755 --- a/debian/scripts/koha-create +++ b/debian/scripts/koha-create @@ -69,6 +69,8 @@ Options: --database dbname Enforce the use of the specified DB name (64 char limit) --adminuser n Explicit the admin user ID in the DB. Relevant in conjunction with --defaultsql and --populate-db. + --defaultsql-creds src Which source should be used for database credentials to use + when populating the database with --defaultsql. (default|instance) --template-cache-dir Set a user defined template_cache_dir. It defaults to /var/cache/koha//templates --timezone time/zone Specify a timezone. e.g. America/Argentina @@ -452,7 +454,7 @@ fi [ $# -ge 1 ] && [ $# -le 16 ] || ( usage ; die "Error: wrong parameters" ) -TEMP=`getopt -o chrpm:l:d:f:b:a: -l create-db,request-db,populate-db,use-db,enable-sru,sru-port:,help,marcflavor:,auth-idx:,biblio-idx:,zebralang:,defaultsql:,configfile:,passwdfile:,dbhost:,dbport:database:,elasticsearch-server:,adminuser:,memcached-servers:,memcached-prefix:,template-cache-dir:,timezone:,upload-path:,tmp-path:,smtp-host:,smtp-port,smtp-timeout:,smtp-ssl-mode:smtp-user-name:,smtp-password:,smtp-debug,letsencrypt, \ +TEMP=`getopt -o chrpm:l:d:f:b:a: -l create-db,request-db,populate-db,use-db,enable-sru,sru-port:,help,marcflavor:,auth-idx:,biblio-idx:,zebralang:,defaultsql:,defaultsql-creds:,configfile:,passwdfile:,dbhost:,dbport:database:,elasticsearch-server:,adminuser:,memcached-servers:,memcached-prefix:,template-cache-dir:,timezone:,upload-path:,tmp-path:,smtp-host:,smtp-port,smtp-timeout:,smtp-ssl-mode:smtp-user-name:,smtp-password:,smtp-debug,letsencrypt, \ -n "$0" -- "$@"` # Note the quotes around `$TEMP': they are essential! @@ -478,6 +480,7 @@ CLO_SMTP_SSL_MODE="" CLO_SMTP_USER_NAME="" CLO_SMTP_PASSWORD="" CLO_SMTP_DEBUG="" +CLO_DEFAULTSQL_CREDS="" while true ; do case "$1" in @@ -501,6 +504,8 @@ while true ; do CLO_ZEBRA_LANGUAGE="$2" ; shift 2 ;; -d|--defaultsql) CLO_DEFAULTSQL="$2" ; shift 2 ;; + --defaultsql-creds) + CLO_DEFAULTSQL_CREDS="$2" ; shift 2 ;; -f|--configfile) configfile="$2" ; shift 2 ;; -s|--passwdfile) @@ -574,6 +579,12 @@ if [ "$CLO_DEFAULTSQL" != "" ] then DEFAULTSQL="$CLO_DEFAULTSQL" fi +if [ "$CLO_DEFAULTSQL_CREDS" != "" ] +then + DEFAULTSQL_CREDS="$CLO_DEFAULTSQL_CREDS" +else + DEFAULTSQL_CREDS="default" +fi if [ "$CLO_ADMINUSER" != "" ] then ADMINUSER="$CLO_ADMINUSER" @@ -659,6 +670,7 @@ then mysqlpwd=`echo $passwdline | cut -d ":" -f 3` mysqldb=`echo $passwdline | cut -d ":" -f 4` mysqlhost=`echo $passwdline | cut -d ":" -f 5` + mysqlport=`echo $passwdline | cut -d ":" -f 6` fi # The order of precedence for MySQL database name is: @@ -805,18 +817,18 @@ fi if [ "$op" = create ] || [ "$op" = populate ] then - # Re-fetch the passwords from the config we've generated, allows it - # to be different from what we set, in case the user had to change - # something. - mysqluser=$(getinstancemysqluser $name) - mysqldb=$(getinstancemysqldatabase $name) # Use the default database content if that exists. if [ -e "$DEFAULTSQL" ] then + if [ "$DEFAULTSQL_CREDS" = "instance" ] ; then + mysqlcmd="koha-mysql $(printf %q $name)" + else + mysqlcmd="mysql --host=$(printf %q $mysqlhost) --user=$(printf %q $mysqluser) --port=$(printf %q $mysqlport) --password=$(printf %q $mysqlpwd) $(printf %q $mysqldb)" + fi # Populate the database with default content. zcat -f "$DEFAULTSQL" | sed "s/__KOHASITE__/koha_$name/g" | - mysql --host="$mysqlhost" --user="$mysqluser" --password="$mysqlpwd" "$mysqldb" + $mysqlcmd # Change the default user's password. @@ -825,8 +837,7 @@ then perl -e ' use Digest::MD5 qw(md5_base64); while (<>) { print md5_base64($_), "\n"; }') - mysql --host="$mysqlhost" --user="$mysqluser" \ ---password="$mysqlpwd" <