From e34668a32d043e7b555f3db91ecf1a204b4a6b66 Mon Sep 17 00:00:00 2001 From: Jared Camins-Esakov Date: Sat, 8 Oct 2011 15:34:24 -0400 Subject: [PATCH] Bug 6913: More options for koha-create and koha-remove This commit makes koha-create more flexible by adding a number of command-line and configuration options. The biggest change is to add support for pre-determined MySQL credentials using a file in /etc/koha/passwd (for security reasons, if you use this feature, make sure the file is not world-readable). The configuration file has the following format: instance:user:password:database The database is optional, but the other two are both required if you want to specify MySQL credentials. If no credentials are specified for a given instance, the standard koha_instance username and an auto-generated password are used. The following additional command line options are now available: * --use-db - use a pre-existing database, see also --database * --database - specify the name of the mysql database (still defaults to koha_instance) * --passwdfile - specify a custom (Koha) passwd file for MySQL credentials The following additional variables are now available (for use in koha-sites.conf or a custom config file): * OPACPORT (previously added but not documented) - port on which the OPAC should be served * OPACPREFIX - prefix for the OPAC's virtual host * OPACSUFFIX - suffix for the OPAC's virtual host This commit also adds the --keep-mysql option to koha-remove, which, if specified, will prevent koha-remove from deleting the database or MySQL user when removing an instance. Signed-off-by: Chris Cormack --- debian/docs/koha-create.xml | 57 +++++++++++++++++++++++++++++++++++-- debian/docs/koha-remove.xml | 19 ++++++++++-- debian/scripts/koha-create | 66 +++++++++++++++++++++++++++++++++++------- debian/scripts/koha-remove | 16 ++++++++++- 4 files changed, 140 insertions(+), 18 deletions(-) diff --git a/debian/docs/koha-create.xml b/debian/docs/koha-create.xml index a3e1520..ec1e426 100644 --- a/debian/docs/koha-create.xml +++ b/debian/docs/koha-create.xml @@ -24,11 +24,13 @@ koha-create - || + ||| marc21|normarc|unimarc en|nb|fr /path/to/some.sql /path/to/config + /path/to/passwd + database n instancename @@ -40,7 +42,7 @@ - Create a new datbase on localhost. If the database you want to use does not reside on localhost, you can use and , see below. + Create a new database on localhost. If the database you want to use does not reside on localhost, you can use and , see below. If the database already exists, you can use , see below. @@ -54,7 +56,14 @@ - When you have run koha-create with the option, and a database has been set up, you can finnish your installation by running koha-create with this option. + When you have run koha-create with the option, and a database has been set up, you can finish your installation by running koha-create with this option. + + + + + + + When the database you want to use has already been populated, you can run koha-create with this option to take care of all the other set-up configuration. @@ -66,6 +75,13 @@ + + + MySQL database to use. + + + + Path to an SQL-file other than the one pointed to in the default or alternative config file. Corresponds to the DEFAULTSQL config file variable. @@ -80,6 +96,13 @@ + + + Path to an alternative passwd file. This file is in the same format as the default (Koha) passwd file, see below for details. + + + + Primary language for Zebra indexing. Corresponds to the ZEBRA_LANGUAGE config file variable. @@ -107,6 +130,27 @@ + + + The port for the OPAC. + + + + + + + This is inserted before the instance name when forming Apache ServerName. For subdomains, make sure it ends with a period. + + + + + + + This is inserted after the instance name, but before the domain name, when forming Apache ServerName. + + + + The port for the intranet. If you set this to empty or 80, then you must also define INTRAPREFIX or INTRASUFFIX. @@ -169,6 +213,13 @@ Configuration variables are read from this file, if it exists. + + + + + Pre-selected database credentials are read from this file, if it exists. The format for this file is instancename:username:passwd:database. Database is optional, but the other three are required if you want to use pre-determined database user credentials. + + diff --git a/debian/docs/koha-remove.xml b/debian/docs/koha-remove.xml index ee2b266..4e272f8 100644 --- a/debian/docs/koha-remove.xml +++ b/debian/docs/koha-remove.xml @@ -23,14 +23,27 @@ - koha-remove instancename + koha-remove + + instancename + Options + + + + + Leave the MySQL database and user when removing the Koha instance. + + + + + Description Remove a Koha instance. - + See also koha-disable(8) @@ -39,7 +52,7 @@ koha-restore(8) - + diff --git a/debian/scripts/koha-create b/debian/scripts/koha-create index b52cf90..bb2b642 100755 --- a/debian/scripts/koha-create +++ b/debian/scripts/koha-create @@ -19,11 +19,12 @@ set -e -usage="Usage: $0 [--create-db|--request-db|--populate-db] \ +usage="Usage: $0 [--create-db|--request-db|--populate-db|--use-db] \ [--marcflavor marc21|normarc|unimarc] \ [--zebralang en|nb|fr] \ [--defaultsql /path/to/some.sql] \ - [--configfile /path/to/config] [--adminuser n] instancename" + [--configfile /path/to/config] [--passwdfile /path/to/passwd] \ + [--database database] [--adminuser n] instancename" die() { echo "$@" 1>&2 @@ -76,6 +77,8 @@ getinstancemysqldatabase() { # Set defaults and read config file, if it exists. DOMAIN="" OPACPORT="80" +OPACPREFIX="" +OPACSUFFIX="" INTRAPORT="8080" INTRAPREFIX="" INTRASUFFIX="" @@ -83,14 +86,15 @@ DEFAULTSQL="" ZEBRA_MARC_FORMAT="marc21" ZEBRA_LANGUAGE="en" ADMINUSER="1" +PASSWDFILE="/etc/koha/passwd" if [ -e /etc/koha/koha-sites.conf ] then . /etc/koha/koha-sites.conf fi -[ $# -ge 2 ] && [ $# -le 12 ] || die $usage +[ $# -ge 2 ] && [ $# -le 16 ] || die $usage -TEMP=`getopt -o crpm:l:d:f:a: -l create-db,request-db,populate-db,marcflavor:,zebralang:,defaultsql:,configfile:,adminuser: \ +TEMP=`getopt -o crpm:l:d:f:a: -l create-db,request-db,populate-db,use-db,marcflavor:,zebralang:,defaultsql:,configfile:,passwdfile:,adminuser: \ -n "$0" -- "$@"` # Note the quotes around `$TEMP': they are essential! @@ -107,10 +111,13 @@ while true ; do -c|--create-db) op=create ; shift ;; -r|--request-db) op=request ; shift ;; -p|--populate-db) op=populate ; shift ;; + -u|--use-db) op=use ; shift ;; -m|--marcflavor) CLO_ZEBRA_MARC_FORMAT="$2" ; shift 2 ;; -l|--zebralang) CLO_ZEBRA_LANGUAGE="$2" ; shift 2 ;; -d|--defaultsql) CLO_DEFAULTSQL="$2" ; shift 2 ;; -f|--configfile) configfile="$2" ; shift 2 ;; + -s|--passwdfile) CLO_PASSWDFILE="$2" ; shift 2 ;; + -b|--database) CLO_DATABASE="$2" ; shift 2 ;; -a|--adminuser) CLO_ADMINUSER="$2" ; shift 2 ;; --) shift ; break ;; *) die "Internal error processing command line arguments" ;; @@ -145,26 +152,54 @@ if [ "$CLO_ADMINUSER" != "" ] then ADMINUSER="$CLO_ADMINUSER" fi +if [ "$CLO_PASSWDFILE" != "" ] +then + PASSWDFILE="$CLO_PASSWDFILE" +fi name="$1" -opacdomain="$name$DOMAIN" +opacdomain="$OPACPREFIX$name$OPACSUFFIX$DOMAIN" intradomain="$INTRAPREFIX$name$INTRASUFFIX$DOMAIN" -mysqldb="koha_$name" +if [ `cat $PASSWDFILE | grep "^$name:"` ] +then + passwdline=`cat $PASSWDFILE | grep "^$name:"` + mysqluser=`echo $passwdline | cut -d ":" -f 2` + mysqlpwd=`echo $passwdline | cut -d ":" -f 3` + mysqldb=`echo $passwdline | cut -d ":" -f 4` +fi + +# The order of precedence for MySQL database name is: +# default < passwd file < command line +if [ "$mysqldb" = "" ] +then + mysqldb="koha_$name" +fi +if [ "$CLO_DATABASE" != "" ] +then + mysqldb="$CLO_DATABASE" +fi + +if [ "$mysqluser" = "" ] +then + mysqluser="koha_$name" +fi mysqlhost="$(getmysqlhost)" -mysqluser="koha_$name" -if [ "$op" = create ] || [ "$op" = request ] +if [ "$op" = create ] || [ "$op" = request ] || [ "$op" = use ] then - mysqlpwd="$(pwgen -1)" + if [ "$mysqlpwd" = "" ] + then + mysqlpwd="$(pwgen -1)" + fi else mysqlpwd="$(getinstancemysqlpassword $name)" fi -if [ "$op" = create ] || [ "$op" = request ] +if [ "$op" = create ] || [ "$op" = request ] || [ "$op" = use ] then # Create new user and group. username="$name-koha" @@ -197,6 +232,15 @@ FLUSH PRIVILEGES; eof fi #` + if [ "$op" = use ] + then + mysql --defaults-extra-file=/etc/mysql/koha-common.cnf --force <