Bug 15092: item type descriptions not showing in OPAC advsearch
[koha.git] / debian / scripts / koha-create
bloba36f7e3167310ee8450298e1bd9f756e65348986
1 #!/bin/bash
3 # koha-create -- Create a new Koha instance.
4 # Copyright 2010 Catalyst IT, Ltd
5 #
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Read configuration variable file if it is present
20 [ -r /etc/default/koha-common ] && . /etc/default/koha-common
22 set -e
24 # include helper functions
25 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
26 . "/usr/share/koha/bin/koha-functions.sh"
27 else
28 echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
29 exit 1
32 usage()
34 local scriptname=$0
35 cat <<EOF
37 Creates new Koha instances.
39 Usage:
41 $scriptname [DB usage mode] [options] instancename
43 DB usage mode:
44 --create-db Create a new database on localhost. (default).
45 --request-db Creates a instancename-db-request.txt file where
46 you adjust your DB settings and re-run with --populate-db.
47 --populate-db Finish the installation you started with --request-db after
48 you adjusted the instancename-db-request.txt file.
49 --use-db Use this option if you already created and populated your DB.
51 Options:
52 --marcflavor flavor Set the MARC flavor. Valid values are marc21 (default),
53 normarc and unimarc.
54 --zebralang lang Choose the primary language for Zebra indexing. Valid
55 values are en (default), es, fr, gr, nb, ru and uk.
56 --auth-idx idx_mode Set the indexing mode for authority records. Valid
57 values are dom (default) and grs1.
58 --biblio-idx idx_mode Set the indexing mode for bibliographic records.
59 Valid values are dom (default) and grs1.
60 --use-memcached Set the instance to make use of memcache.
61 --memcached-servers str Set a comma-separated list of host:port memcached servers.
62 --memcached-prefix str Set the desired prefix for the instance memcached namespace.
63 --enable-sru Enable the Z39.50/SRU server (default: disabled).
64 --sru-port Specifiy a TCP port number for the Z39.50/SRU server
65 to listen on. (default: 7090).
66 --defaultsql some.sql Specify a default SQL file to be loaded on the DB.
67 --configfile cfg_file Specify an alternate config file for reading default values.
68 --passwdfile passwd Specify an alternate passwd file.
69 --database dbname Enforce the use of the specified DB name (64 char limit)
70 --adminuser n Explicit the admin user ID in the DB. Relevant in
71 conjunction with --defaultsql and --populate-db.
72 --upload-path dir Set a user defined upload_path. It defaults to
73 /var/lib/koha/<instance>/uploads
74 --help,-h Show this help.
76 Note: the instance name cannot be longer that 11 chars.
78 EOF
81 # UPPER CASE VARIABLES - from configfile or default value
82 # lower case variables - generated within this script
83 generate_config_file() {
84 touch "$2"
85 chown "root:$username" "$2"
86 chmod 0640 "$2"
87 sed -e "s/__KOHASITE__/$name/g" \
88 -e "s/__OPACPORT__/$OPACPORT/g" \
89 -e "s/__INTRAPORT__/$INTRAPORT/g" \
90 -e "s/__OPACSERVER__/$opacdomain/g" \
91 -e "s/__INTRASERVER__/$intradomain/g" \
92 -e "s/__ZEBRA_PASS__/$zebrapwd/g" \
93 -e "s/__ZEBRA_MARC_FORMAT__/$ZEBRA_MARC_FORMAT/g" \
94 -e "s/__ZEBRA_LANGUAGE__/$ZEBRA_LANGUAGE/g" \
95 -e "s/__SRU_BIBLIOS_PORT__/$SRU_SERVER_PORT/g" \
96 -e "s/__START_SRU_PUBLICSERVER__/$START_SRU_PUBLICSERVER/g" \
97 -e "s/__END_SRU_PUBLICSERVER__/$END_SRU_PUBLICSERVER/g" \
98 -e "s/__BIBLIOS_INDEXING_MODE__/$BIBLIOS_INDEXING_MODE/g" \
99 -e "s/__AUTHORITIES_INDEXING_MODE__/$AUTHORITIES_INDEXING_MODE/g" \
100 -e "s/__ZEBRA_BIBLIOS_CFG__/$ZEBRA_BIBLIOS_CFG/g" \
101 -e "s/__ZEBRA_AUTHORITIES_CFG__/$ZEBRA_AUTHORITIES_CFG/g" \
102 -e "s/__START_BIBLIOS_RETRIEVAL_INFO__/`echo $START_BIBLIOS_RETRIEVAL_INFO`/g" \
103 -e "s/__END_BIBLIOS_RETRIEVAL_INFO__/`echo $END_BIBLIOS_RETRIEVAL_INFO`/g" \
104 -e "s/__START_AUTHORITIES_RETRIEVAL_INFO__/`echo $START_AUTHORITIES_RETRIEVAL_INFO`/g" \
105 -e "s/__END_AUTHORITIES_RETRIEVAL_INFO__/`echo $END_AUTHORITIES_RETRIEVAL_INFO`/g" \
106 -e "s/__DB_NAME__/$mysqldb/g" \
107 -e "s/__DB_HOST__/$mysqlhost/g" \
108 -e "s/__DB_USER__/$mysqluser/g" \
109 -e "s/__DB_PASS__/$mysqlpwd/g" \
110 -e "s/__UNIXUSER__/$username/g" \
111 -e "s/__UNIXGROUP__/$username/g" \
112 -e "s#__UPLOAD_PATH__#$UPLOAD_PATH#g" \
113 -e "s/__PLUGINS_DIR__/\/var\/lib\/koha\/$name\/plugins/g" \
114 -e "s/__MEMCACHED_NAMESPACE__/$MEMCACHED_NAMESPACE/g" \
115 -e "s/__MEMCACHED_SERVERS__/$MEMCACHED_SERVERS/g" \
116 "/etc/koha/$1" > "$2"
120 getmysqlhost() {
121 awk '
122 /^\[/ { inclient = 0 }
123 /^\[client\]/ { inclient = 1 }
124 inclient && /^ *host *=/ { print $3 }' \
125 /etc/mysql/koha-common.cnf
128 getinstancemysqlpassword() {
129 xmlstarlet sel -t -v 'yazgfs/config/pass' "/etc/koha/sites/$1/koha-conf.xml"
132 getinstancemysqluser() {
133 xmlstarlet sel -t -v 'yazgfs/config/user' "/etc/koha/sites/$1/koha-conf.xml"
136 getinstancemysqldatabase() {
137 xmlstarlet sel -t -v 'yazgfs/config/database' "/etc/koha/sites/$1/koha-conf.xml"
140 check_apache_config()
143 # Check that mpm_itk is installed and enabled
144 if ! /usr/sbin/apachectl -M 2> /dev/null | grep -q 'mpm_itk'; then
145 # Check Apache version
146 APACHE_DISABLE_MPM_MSG=""
147 if /usr/sbin/apache2ctl -v | grep -q "Server version: Apache/2.4"; then
148 # mpm_event or mpm_worker need to be disabled first. mpm_itk depends
149 # on mpm_prefork, which is enabled if needed. See
150 # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=734865
151 if /usr/sbin/apachectl -M 2> /dev/null | grep -q 'mpm_event'; then
152 APACHE_DISABLE_MPM_MSG=" sudo a2dismod mpm_event ;"
153 elif /usr/sbin/apachectl -M 2> /dev/null | grep -q 'mpm_worker'; then
154 APACHE_DISABLE_MPM_MSG=" sudo a2dismod mpm_worker ;"
155 # else mpm_prefork: a2enmod mpm_itk works
157 # else Apache 2.2: a2enmod mpm_itk works
160 cat 1>&2 <<EOM
162 Koha requires mpm_itk to be enabled within Apache in order to run.
163 Typically this can be enabled with:
165 $APACHE_DISABLE_MPM_MSG sudo a2enmod mpm_itk
171 # Check that mod_rewrite is installed and enabled.
172 if ! /usr/sbin/apachectl -M 2> /dev/null | grep -q 'rewrite_module'; then
173 cat 1>&2 <<EOM
175 Koha requires mod_rewrite to be enabled within Apache in order to run.
176 Typically this can be enabled with:
178 sudo a2enmod rewrite
183 # Check that the CGI module is installed and enabled
184 # (Apache 2.4 may not have it by default.)
185 if ! /usr/sbin/apachectl -M 2> /dev/null | grep -q 'cgi_module'; then
186 cat 1>&2 << EOM
187 Koha requires mod_cgi to be enabled within Apache in order to run.
188 Typically this can be enabled with:
190 sudo a2enmod cgi
197 set_biblios_indexing_mode()
199 local indexing_mode=$1
200 local marc_format=$2
202 case $indexing_mode in
203 "dom")
204 START_BIBLIOS_RETRIEVAL_INFO=`cat <<EOF
205 <xi:include href="\/etc\/koha\/$marc_format-retrieval-info-bib-dom.xml"\n
206 xmlns:xi="http:\/\/www.w3.org\/2001\/XInclude">\n
207 <xi:fallback>\n
208 <retrievalinfo>
209 EOF`
211 END_BIBLIOS_RETRIEVAL_INFO=`cat <<EOF
212 <\/retrievalinfo>\n
213 <\/xi:fallback>\n
214 <\/xi:include>
215 EOF`
216 BIBLIOS_INDEXING_MODE="dom"
217 ZEBRA_BIBLIOS_CFG="zebra-biblios-dom.cfg"
219 "grs1")
220 START_BIBLIOS_RETRIEVAL_INFO=" <retrievalinfo>"
221 END_BIBLIOS_RETRIEVAL_INFO=" <\/retrievalinfo>"
222 BIBLIOS_INDEXING_MODE="grs1"
223 ZEBRA_BIBLIOS_CFG="zebra-biblios.cfg"
226 die "Error: '$indexing_mode' is not a valid indexing mode for bibliographic records."
228 esac
232 set_authorities_indexing_mode()
234 local indexing_mode=$1
235 local marc_format=$2
237 case $indexing_mode in
238 "dom")
239 START_AUTHORITIES_RETRIEVAL_INFO=`cat <<EOF
240 <xi:include href="\/etc\/koha\/$marc_format-retrieval-info-auth-dom.xml"\n
241 xmlns:xi="http:\/\/www.w3.org\/2001\/XInclude">\n
242 <xi:fallback>\n
243 <retrievalinfo>
244 EOF`
246 END_AUTHORITIES_RETRIEVAL_INFO=`cat <<EOF
247 <\/retrievalinfo>\n
248 <\/xi:fallback>\n
249 <\/xi:include>\n
250 EOF`
251 AUTHORITIES_INDEXING_MODE="dom"
252 ZEBRA_AUTHORITIES_CFG="zebra-authorities-dom.cfg"
254 "grs1")
255 START_AUTHORITIES_RETRIEVAL_INFO=" <retrievalinfo>"
256 END_AUTHORITIES_RETRIEVAL_INFO=" <\/retrievalinfo>"
257 AUTHORITIES_INDEXING_MODE="grs1"
258 ZEBRA_AUTHORITIES_CFG="zebra-authorities.cfg"
261 die "Error: '$indexing_mode' is not a valid indexing mode for authority records."
263 esac
267 set_memcached()
269 local instance="$1"
271 if [ "$CLO_MEMCACHED_SERVERS" != "" ]; then
272 MEMCACHED_SERVERS=$CLO_MEMCACHED_SERVERS
273 else
274 if [ "$MEMCACHED_SERVERS" = "" ]; then
275 MEMCACHED_SERVERS=$DEFAULT_MEMCACHED_SERVERS
276 # else: was set by the koha-sites.conf file
280 if [ "$CLO_MEMCACHED_PREFIX" != "" ]; then
281 MEMCACHED_NAMESPACE="$CLO_MEMCACHED_PREFIX$instance"
282 else
283 if [ "$MEMCACHED_PREFIX" != "" ]; then
284 MEMCACHED_NAMESPACE="$MEMCACHED_PREFIX$instance"
285 else
286 MEMCACHED_NAMESPACE="$DEFAULT_MEMCACHED_PREFIX$instance"
292 set_upload_path()
294 local instance="$1"
296 if [ "$CLO_UPLOAD_PATH" != "" ]; then
297 UPLOAD_PATH=$CLO_UPLOAD_PATH
298 else
299 UPLOAD_PATH="$UPLOAD_PATH_BASE/$instance/$UPLOAD_DIR"
303 enable_sru_server()
305 # remove the commenting symbols
306 START_SRU_PUBLICSERVER=""
307 END_SRU_PUBLICSERVER=""
308 if [ "$SRU_SERVER_PORT" = "" ]; then
309 # --sru-port not passed, use the default
310 SRU_SERVER_PORT=$DEFAULT_SRU_SERVER_PORT
314 # Set defaults and read config file, if it exists.
315 DOMAIN=""
316 OPACPORT="80"
317 OPACPREFIX=""
318 OPACSUFFIX=""
319 INTRAPORT="8080"
320 INTRAPREFIX=""
321 INTRASUFFIX=""
322 DEFAULTSQL=""
323 ZEBRA_MARC_FORMAT="marc21"
324 ZEBRA_LANGUAGE="en"
325 ADMINUSER="1"
326 PASSWDFILE="/etc/koha/passwd"
328 # memcached variables
329 USE_MEMCACHED="no"
330 MEMCACHED_SERVERS=""
331 MEMCACHED_PREFIX=""
332 # hardcoded memcached defaults
333 DEFAULT_MEMCACHED_SERVERS="127.0.0.1:11211"
334 DEFAULT_MEMCACHED_PREFIX="koha_"
335 # hardcoded upload_path
336 UPLOAD_PATH_BASE="/var/lib/koha"
337 UPLOAD_DIR="uploads"
338 UPLOAD_PATH=""
340 # SRU server variables
341 ENABLE_SRU="no"
342 SRU_SERVER_PORT=""
343 # hardcoded default SRU server port
344 DEFAULT_SRU_SERVER_PORT="7090"
345 START_SRU_PUBLICSERVER="<!--"
346 END_SRU_PUBLICSERVER="-->"
348 # Indexing mode variables (default is DOM)
349 BIBLIOS_INDEXING_MODE="dom"
350 AUTHORITIES_INDEXING_MODE="dom"
352 START_BIBLIOS_RETRIEVAL_INFO=""
353 END_BIBLIOS_RETRIEVAL_INFO=""
354 START_AUTHORITIES_RETRIEVAL_INFO=""
355 END_AUTHORITIES_RETRIEVAL_INFO=""
357 if [ -e /etc/koha/koha-sites.conf ]
358 then
359 . /etc/koha/koha-sites.conf
362 [ $# -ge 1 ] && [ $# -le 16 ] || ( usage ; die "Error: wrong parameters" )
364 TEMP=`getopt -o chrpm:l:d:f:b:a: -l create-db,request-db,populate-db,use-db,use-memcached,enable-sru,sru-port:,help,marcflavor:,auth-idx:,biblio-idx:,zebralang:,defaultsql:,configfile:,passwdfile:,database:,adminuser:,memcached-servers:,memcached-prefix:,upload-path:, \
365 -n "$0" -- "$@"`
367 # Note the quotes around `$TEMP': they are essential!
368 eval set -- "$TEMP"
370 # Temporary variables for the command line options
371 CLO_ZEBRA_MARC_FORMAT=""
372 CLO_ZEBRA_LANGUAGE=""
373 CLO_DEFAULTSQL=""
374 CLO_ADMINUSER=""
375 CLO_BIBLIOS_INDEXING_MODE=""
376 CLO_AUTHORITIES_INDEXING_MODE=""
377 CLO_MEMCACHED_SERVERS=""
378 CLO_MEMCACHED_PREFIX=""
379 CLO_UPLOAD_PATH=""
382 while true ; do
383 case "$1" in
384 -c|--create-db)
385 op=create ; shift ;;
386 -r|--request-db)
387 op=request ; shift ;;
388 -p|--populate-db)
389 op=populate ; shift ;;
390 -u|--use-db)
391 op=use ; shift ;;
392 --use-memcached)
393 USE_MEMCACHED="yes" ; shift ;;
394 --memcached-servers)
395 CLO_MEMCACHED_SERVERS="$2" ; shift 2 ;;
396 --memcached-prefix)
397 CLO_MEMCACHED_PREFIX="$2" ; shift 2;;
398 -m|--marcflavor)
399 CLO_ZEBRA_MARC_FORMAT="$2" ; shift 2 ;;
400 -l|--zebralang)
401 CLO_ZEBRA_LANGUAGE="$2" ; shift 2 ;;
402 --auth-idx)
403 CLO_AUTHORITIES_INDEXING_MODE="$2" ; shift 2 ;;
404 --biblio-idx)
405 CLO_BIBLIOS_INDEXING_MODE="$2" ; shift 2 ;;
406 -d|--defaultsql)
407 CLO_DEFAULTSQL="$2" ; shift 2 ;;
408 -f|--configfile)
409 configfile="$2" ; shift 2 ;;
410 -s|--passwdfile)
411 CLO_PASSWDFILE="$2" ; shift 2 ;;
412 -b|--database)
413 CLO_DATABASE="$2" ; shift 2 ;;
414 -a|--adminuser)
415 CLO_ADMINUSER="$2" ; shift 2 ;;
416 --enable-sru)
417 ENABLE_SRU="yes" ; shift ;;
418 --sru-port)
419 SRU_SERVER_PORT="$2" ; shift 2 ;;
420 --upload-path)
421 CLO_UPLOAD_PATH="$2" ; shift 2 ;;
422 -h|--help)
423 usage ; exit 0 ;;
425 shift ; break ;;
427 die "Internal error processing command line arguments" ;;
428 esac
429 done
431 # Load the configfile given on the command line
432 if [ "$configfile" != "" ]
433 then
434 if [ -e "$configfile" ]
435 then
436 . "$configfile"
437 else
438 die "$configfile does not exist.";
442 # Make sure options from the command line get the highest precedence
443 if [ "$CLO_ZEBRA_MARC_FORMAT" != "" ]
444 then
445 ZEBRA_MARC_FORMAT="$CLO_ZEBRA_MARC_FORMAT"
447 if [ "$CLO_ZEBRA_LANGUAGE" != "" ]
448 then
449 ZEBRA_LANGUAGE="$CLO_ZEBRA_LANGUAGE"
451 if [ "$CLO_DEFAULTSQL" != "" ]
452 then
453 DEFAULTSQL="$CLO_DEFAULTSQL"
455 if [ "$CLO_ADMINUSER" != "" ]
456 then
457 ADMINUSER="$CLO_ADMINUSER"
459 if [ "$CLO_PASSWDFILE" != "" ]
460 then
461 PASSWDFILE="$CLO_PASSWDFILE"
464 if [ "$CLO_BIBLIOS_INDEXING_MODE" != "" ]; then
465 BIBLIOS_INDEXING_MODE=$CLO_BIBLIOS_INDEXING_MODE
468 set_biblios_indexing_mode $BIBLIOS_INDEXING_MODE $ZEBRA_MARC_FORMAT
470 if [ "$ENABLE_SRU" != "no" ]; then
471 enable_sru_server
474 if [ "$CLO_AUTHORITIES_INDEXING_MODE" != "" ]; then
475 AUTHORITIES_INDEXING_MODE=$CLO_AUTHORITIES_INDEXING_MODE
478 set_authorities_indexing_mode $AUTHORITIES_INDEXING_MODE $ZEBRA_MARC_FORMAT
480 name="$1"
482 set_upload_path $name
484 if [ "$USE_MEMCACHED" = "yes" ]; then
485 set_memcached $name
486 elif [ "$CLO_MEMCACHED_SERVERS" != "" ] || \
487 [ "$CLO_MEMCACHED_PREFIX" != "" ]; then
489 MSG=`cat <<EOF
491 Error: you provided memcached configuration switches but memcached is not enabled.
492 Please set USE_MEMCACHED="yes" on /etc/koha/koha-sites.conf or use the
493 --use-memcached option switch to enable it.
495 EOF`
497 usage ; die $MSG
498 else
499 # Unset memcached-related variables
500 MEMCACHED_SERVERS=""
501 MEMCACHED_PREFIX=""
504 # Are we root? If not, the mod_rewrite check will fail and be confusing, so
505 # we look into this first.
506 if [[ $UID -ne 0 ]]
507 then
508 die "This script must be run with root privileges."
511 # Check everything is ok with Apache, die otherwise
512 check_apache_config
514 opacdomain="$OPACPREFIX$name$OPACSUFFIX$DOMAIN"
515 intradomain="$INTRAPREFIX$name$INTRASUFFIX$DOMAIN"
518 if [ -f $PASSWDFILE ] && [ `cat $PASSWDFILE | grep "^$name:"` ]
519 then
520 passwdline=`cat $PASSWDFILE | grep "^$name:"`
521 mysqluser=`echo $passwdline | cut -d ":" -f 2`
522 mysqlpwd=`echo $passwdline | cut -d ":" -f 3`
523 mysqldb=`echo $passwdline | cut -d ":" -f 4`
526 # The order of precedence for MySQL database name is:
527 # default < passwd file < command line
528 if [ "$mysqldb" = "" ]
529 then
530 mysqldb="koha_$name"
532 if [ "$CLO_DATABASE" != "" ]
533 then
534 mysqldb="$CLO_DATABASE"
537 if [ "$mysqluser" = "" ]
538 then
539 mysqluser="koha_$name"
541 mysqlhost="$(getmysqlhost)"
543 if [ "$op" = create ] || [ "$op" = request ] || [ "$op" = use ]
544 then
545 if [ "$mysqlpwd" = "" ]
546 then
547 mysqlpwd="$(pwgen -s 16 1)"
549 else
550 mysqlpwd="$(getinstancemysqlpassword $name)"
554 if [ "$op" = create ] || [ "$op" = request ] || [ "$op" = use ]
555 then
556 # Create new user and group.
557 username="$name-koha"
558 if getent passwd "$username" > /dev/null
559 then
560 die "User $username already exists."
562 if getent group "$username" > /dev/null
563 then
564 die "Group $username already exists."
566 adduser --no-create-home --disabled-login \
567 --gecos "Koha instance $username" \
568 --home "/var/lib/koha/$name" \
569 --quiet "$username"
571 # Create the site-specific directories.
572 koha-create-dirs "$name"
574 # Generate Zebra database password.
575 zebrapwd="$(pwgen -s 16 1)"
576 # Future enhancement: make this configurable for when your db is on
577 # another server.
578 mysql_hostname="localhost"
579 # Set up MySQL database for this instance.
580 if [ "$op" = create ]
581 then
582 mysql --defaults-extra-file=/etc/mysql/koha-common.cnf <<eof
583 CREATE DATABASE \`$mysqldb\`;
584 CREATE USER \`$mysqluser\`@'$mysql_hostname' IDENTIFIED BY '$mysqlpwd';
585 CREATE USER \`$mysqluser\`@'%' IDENTIFIED BY '$mysqlpwd';
586 GRANT ALL PRIVILEGES ON \`$mysqldb\`.* TO \`$mysqluser\`;
587 FLUSH PRIVILEGES;
589 fi #`
591 if [ "$op" = use ]
592 then
593 mysql --defaults-extra-file=/etc/mysql/koha-common.cnf --force <<eof
594 CREATE USER \`$mysqluser\`@'$mysql_hostname' IDENTIFIED BY '$mysqlpwd';
595 CREATE USER \`$mysqluser\`@'%' IDENTIFIED BY '$mysqlpwd';
596 GRANT ALL PRIVILEGES ON \`$mysqldb\`.* TO \`$mysqluser\`;
597 FLUSH PRIVILEGES;
599 fi #`
601 # Generate and install Apache site-available file and log dir.
602 generate_config_file apache-site.conf.in \
603 "/etc/apache2/sites-available/$name.conf"
604 mkdir "/var/log/koha/$name"
605 chown "$username:$username" "/var/log/koha/$name"
608 # Generate and install main Koha config file.
609 generate_config_file koha-conf-site.xml.in \
610 "/etc/koha/sites/$name/koha-conf.xml"
612 # Generate and install the log4perl config file.
613 generate_config_file log4perl-site.conf.in \
614 "/etc/koha/sites/$name/log4perl.conf"
616 # Generate and install Zebra config files.
617 generate_config_file zebra-biblios-site.cfg.in \
618 "/etc/koha/sites/$name/zebra-biblios.cfg"
619 generate_config_file zebra-biblios-dom-site.cfg.in \
620 "/etc/koha/sites/$name/zebra-biblios-dom.cfg"
621 generate_config_file zebra-authorities-site.cfg.in \
622 "/etc/koha/sites/$name/zebra-authorities.cfg"
623 generate_config_file zebra-authorities-dom-site.cfg.in \
624 "/etc/koha/sites/$name/zebra-authorities-dom.cfg"
625 generate_config_file zebra.passwd.in \
626 "/etc/koha/sites/$name/zebra.passwd"
629 # Create a GPG-encrypted file for requesting a DB to be set up.
630 if [ "$op" = request ]
631 then
632 touch "$name-db-request.txt"
633 chmod 0600 "$name-db-request.txt"
634 cat > "$name-db-request.txt" << eof
635 Please create a MySQL database and user on $mysqlhost as follows:
637 database name: $mysqldb
638 database user: $mysqluser
639 password: $mysqlpwd
641 Thank you.
644 echo "See $name-db-request.txt for database creation request."
645 echo "Please forward it to the right person, and then run"
646 echo "$0 --populate-db $name"
647 echo "Thanks."
652 if [ "$op" = create ] || [ "$op" = populate ]
653 then
654 # Re-fetch the passwords from the config we've generated, allows it
655 # to be different from what we set, in case the user had to change
656 # something.
657 mysqluser=$(getinstancemysqluser $name)
658 mysqldb=$(getinstancemysqldatabase $name)
659 # Use the default database content if that exists.
660 if [ -e "$DEFAULTSQL" ]
661 then
662 # Populate the database with default content.
663 zcat "$DEFAULTSQL" |
664 sed "s/__KOHASITE__/$name/g" |
665 mysql --host="$mysqlhost" --user="$mysqluser" --password="$mysqlpwd" "$mysqldb"
668 # Change the default user's password.
669 staffpass="$(pwgen 12 1)"
670 staffdigest=$(echo -n "$staffpass" |
671 perl -e '
672 use Digest::MD5 qw(md5_base64);
673 while (<>) { print md5_base64($_), "\n"; }')
674 mysql --host="$mysqlhost" --user="$mysqluser" \
675 --password="$mysqlpwd" <<eof
676 USE \`$mysqldb\`;
677 UPDATE borrowers
678 SET password = '$staffdigest'
679 WHERE borrowernumber = $ADMINUSER;
682 echo "staff user password is '$staffpass' but keep that secret"
684 # Upgrade the database schema, just in case the dump was from an
685 # old version.
686 koha-upgrade-schema "$name"
687 else
688 echo "Koha instance is empty, no staff user created."
693 if [ "$op" = create ] || [ "$op" = populate ] || [ "$op" = use ]
694 then
695 # Reconfigure Apache.
696 if ! {
697 a2ensite "$name" > /dev/null 2>&1 ||
698 a2ensite "${name}.conf" > /dev/null 2>&1
699 }; then
700 echo "Warning: problem enabling $name in Apache" >&2
702 service apache2 restart
704 # Start Zebra.
705 koha-start-zebra "$name"
707 if [ "$USE_INDEXER_DAEMON" = "yes" ]; then
708 # Start Indexer daemon
709 koha-indexer --start "$name"
714 if [ "$op" = request ]
715 then
716 koha-disable "$name"
719 echo <<eoh
721 Email for this instance is disabled. When you're ready to enable it, use:
722 koha-email-enable $name