From 2039e2c332fb87df3a331bd76b8b2270e5f2ec9b 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 c1cb4eea64..02e699cedd 100755 --- a/debian/scripts/koha-create +++ b/debian/scripts/koha-create @@ -66,6 +66,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 @@ -391,7 +393,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:,adminuser:,memcached-servers:,memcached-prefix:,template-cache-dir:,timezone:,upload-path:,tmp-path:,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:,adminuser:,memcached-servers:,memcached-prefix:,template-cache-dir:,timezone:,upload-path:,tmp-path:,letsencrypt, \ -n "$0" -- "$@"` # Note the quotes around `$TEMP': they are essential! @@ -409,6 +411,7 @@ CLO_TMP_PATH="" CLO_LETSENCRYPT="" CLO_TEMPLATE_CACHE_DIR="" CLO_TIMEZONE="" +CLO_DEFAULTSQL_CREDS="" while true ; do case "$1" in @@ -430,6 +433,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) @@ -489,6 +494,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" @@ -566,6 +577,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: @@ -711,18 +723,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. @@ -731,8 +743,7 @@ then perl -e ' use Digest::MD5 qw(md5_base64); while (<>) { print md5_base64($_), "\n"; }') - mysql --host="$mysqlhost" --user="$mysqluser" \ ---password="$mysqlpwd" <