Bug 11404: add support for Apache 2.4's config file convention
[koha.git] / debian / scripts / koha-create
1 #!/bin/bash
2 #
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.
10
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.
15
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/>.
18
19
20 set -e
21
22 usage()
23 {
24     local scriptname=$0
25     cat <<EOF
26
27 Creates new Koha instances.
28
29 Usage:
30
31   $scriptname [DB usage mode] [options] instancename
32
33 DB usage mode:
34   --create-db               Create a new database on localhost. (default).
35   --request-db              Creates a instancename-db-request.txt file where
36                             you adjust your DB settings and re-run with --populate-db.
37   --populate-db             Finish the installation you started with --request-db after
38                             you adjusted the instancename-db-request.txt file.
39   --use-db                  Use this option if you already created and populated your DB.
40
41 Options:
42   --marcflavor flavor       Set the MARC flavor. Valid values are marc21 (default),
43                             normarc and unimarc.
44   --zebralang lang          Choose the primary language for Zebra indexing. Valid
45                             values are en (default), es, fr, nb, ru and uk.
46   --auth-idx idx_mode       Set the indexing mode for authority records. Valid
47                             values are dom (default) and grs1.
48   --biblio-idx idx_mode     Set the indexing mode for bibliographic records.
49                             Valid values are dom (default) and grs1.
50   --use-memcached           Set the instance to make use of memcache.
51   --memcached-servers str   Set a comma-separated list of host:port memcached servers.
52   --memcached-prefix str    Set the desired prefix for the instance memcached namespace.
53   --defaultsql some.sql     Specify a default SQL file to be loaded on the DB.
54   --configfile cfg_file     Specify an alternate config file for reading default values.
55   --passwdfile passwd       Specify an alternate passwd file.
56   --database dbname         Enforce the use of the specified DB name (64 char limit)
57   --adminuser n             Explicit the admin user ID in the DB. Relevant in
58                             conjunction with --defaultsql and --populate-db.
59   --help,-h                 Show this help.
60
61 Note: the instance name cannot be longer that 11 chars.
62
63 EOF
64 }
65
66 die() {
67     echo "$@" 1>&2
68     exit 1
69 }
70
71 # UPPER CASE VARIABLES - from configfile or default value
72 # lower case variables - generated within this script
73 generate_config_file() {
74     touch "$2"
75     chown "root:$username" "$2"
76     chmod 0640 "$2"
77     sed -e "s/__KOHASITE__/$name/g" \
78         -e "s/__OPACPORT__/$OPACPORT/g" \
79         -e "s/__INTRAPORT__/$INTRAPORT/g" \
80         -e "s/__OPACSERVER__/$opacdomain/g" \
81         -e "s/__INTRASERVER__/$intradomain/g" \
82         -e "s/__ZEBRA_PASS__/$zebrapwd/g" \
83         -e "s/__ZEBRA_MARC_FORMAT__/$ZEBRA_MARC_FORMAT/g" \
84         -e "s/__ZEBRA_LANGUAGE__/$ZEBRA_LANGUAGE/g" \
85         -e "s/__BIBLIOS_INDEXING_MODE__/$BIBLIOS_INDEXING_MODE/g" \
86         -e "s/__AUTHORITIES_INDEXING_MODE__/$AUTHORITIES_INDEXING_MODE/g" \
87         -e "s/__ZEBRA_BIBLIOS_CFG__/$ZEBRA_BIBLIOS_CFG/g" \
88         -e "s/__ZEBRA_AUTHORITIES_CFG__/$ZEBRA_AUTHORITIES_CFG/g" \
89         -e "s/__START_BIBLIOS_RETRIEVAL_INFO__/`echo $START_BIBLIOS_RETRIEVAL_INFO`/g" \
90         -e "s/__END_BIBLIOS_RETRIEVAL_INFO__/`echo $END_BIBLIOS_RETRIEVAL_INFO`/g" \
91         -e "s/__START_AUTHORITIES_RETRIEVAL_INFO__/`echo $START_AUTHORITIES_RETRIEVAL_INFO`/g" \
92         -e "s/__END_AUTHORITIES_RETRIEVAL_INFO__/`echo $END_AUTHORITIES_RETRIEVAL_INFO`/g" \
93         -e "s/__DB_NAME__/$mysqldb/g" \
94         -e "s/__DB_HOST__/$mysqlhost/g" \
95         -e "s/__DB_USER__/$mysqluser/g" \
96         -e "s/__DB_PASS__/$mysqlpwd/g" \
97         -e "s/__UNIXUSER__/$username/g" \
98         -e "s/__UNIXGROUP__/$username/g" \
99         -e "s/__PLUGINS_DIR__/\/var\/lib\/koha\/$name\/plugins/g" \
100         -e "s/__MEMCACHED_NAMESPACE__/$MEMCACHED_NAMESPACE/g" \
101         -e "s/__MEMCACHED_SERVERS__/$MEMCACHED_SERVERS/g" \
102         "/etc/koha/$1" > "$2"
103
104 }
105
106 getmysqlhost() {
107     awk '
108         /^\[/ { inclient = 0 }
109         /^\[client\]/ { inclient = 1 }
110         inclient && /^ *host *=/ { print $3 }' \
111         /etc/mysql/koha-common.cnf
112 }
113
114 getinstancemysqlpassword() {
115     xmlstarlet sel -t -v 'yazgfs/config/pass' "/etc/koha/sites/$1/koha-conf.xml"
116 }
117
118 getinstancemysqluser() {
119     xmlstarlet sel -t -v 'yazgfs/config/user' "/etc/koha/sites/$1/koha-conf.xml"
120 }
121
122 getinstancemysqldatabase() {
123     xmlstarlet sel -t -v 'yazgfs/config/database' "/etc/koha/sites/$1/koha-conf.xml"
124 }
125
126 check_apache_config()
127 {
128
129     # Check that mpm_itk is installed and enabled
130     if ! /usr/sbin/apachectl -M 2> /dev/null | grep -q 'mpm_itk'; then
131         # Check Apache version
132         APACHE_DISABLE_MPM_MSG=""
133         if /usr/sbin/apache2ctl -v | grep -q "Server version: Apache/2.4"; then
134             # mpm_event or mpm_worker need to be disabled first. mpm_itk depends
135             # on mpm_prefork, which is enabled if needed. See
136             # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=734865
137             if /usr/sbin/apachectl -M 2> /dev/null | grep -q 'mpm_event'; then
138                 APACHE_DISABLE_MPM_MSG=" sudo a2dismod mpm_event ;"
139             elif /usr/sbin/apachectl -M 2> /dev/null | grep -q 'mpm_worker'; then
140                 APACHE_DISABLE_MPM_MSG=" sudo a2dismod mpm_worker ;"
141             # else mpm_prefork: a2enmod mpm_itk works
142             fi
143         # else Apache 2.2: a2enmod mpm_itk works
144         fi
145
146         cat 1>&2  <<EOM
147
148 Koha requires mpm_itk to be enabled within Apache in order to run.
149 Typically this can be enabled with:
150
151    $APACHE_DISABLE_MPM_MSG sudo a2enmod mpm_itk
152 EOM
153
154         die
155     fi
156
157     # Check that mod_rewrite is installed and enabled.
158     if ! /usr/sbin/apachectl -M 2> /dev/null | grep -q 'rewrite_module'; then
159         cat 1>&2  <<EOM
160
161 Koha requires mod_rewrite to be enabled within Apache in order to run.
162 Typically this can be enabled with:
163
164     sudo a2enmod rewrite
165 EOM
166         die
167     fi
168 }
169
170 set_biblios_indexing_mode()
171 {
172     local indexing_mode=$1
173     local marc_format=$2
174
175     case $indexing_mode in
176         "dom")
177             START_BIBLIOS_RETRIEVAL_INFO=`cat <<EOF
178     <xi:include href="\/etc\/koha\/$marc_format-retrieval-info-bib-dom.xml"\n
179                 xmlns:xi="http:\/\/www.w3.org\/2001\/XInclude">\n
180      <xi:fallback>\n
181       <retrievalinfo>
182 EOF`
183
184             END_BIBLIOS_RETRIEVAL_INFO=`cat <<EOF
185       <\/retrievalinfo>\n
186      <\/xi:fallback>\n
187     <\/xi:include>
188 EOF`
189             BIBLIOS_INDEXING_MODE="dom"
190             ZEBRA_BIBLIOS_CFG="zebra-biblios-dom.cfg"
191             ;;
192         "grs1")
193             START_BIBLIOS_RETRIEVAL_INFO="    <retrievalinfo>"
194             END_BIBLIOS_RETRIEVAL_INFO="    <\/retrievalinfo>"
195             BIBLIOS_INDEXING_MODE="grs1"
196             ZEBRA_BIBLIOS_CFG="zebra-biblios.cfg"
197             ;;
198         *)
199             die "Error: '$indexing_mode' is not a valid indexing mode for bibliographic records."
200             ;;
201     esac
202 }
203
204
205 set_authorities_indexing_mode()
206 {
207     local indexing_mode=$1
208     local marc_format=$2
209
210     case $indexing_mode in
211         "dom")
212             START_AUTHORITIES_RETRIEVAL_INFO=`cat <<EOF
213     <xi:include href="\/etc\/koha\/$marc_format-retrieval-info-auth-dom.xml"\n
214                 xmlns:xi="http:\/\/www.w3.org\/2001\/XInclude">\n
215      <xi:fallback>\n
216       <retrievalinfo>
217 EOF`
218
219             END_AUTHORITIES_RETRIEVAL_INFO=`cat <<EOF
220       <\/retrievalinfo>\n
221      <\/xi:fallback>\n
222     <\/xi:include>\n
223 EOF`
224             AUTHORITIES_INDEXING_MODE="dom"
225             ZEBRA_AUTHORITIES_CFG="zebra-authorities-dom.cfg"
226             ;;
227         "grs1")
228             START_AUTHORITIES_RETRIEVAL_INFO="    <retrievalinfo>"
229             END_AUTHORITIES_RETRIEVAL_INFO="    <\/retrievalinfo>"
230             AUTHORITIES_INDEXING_MODE="grs1"
231             ZEBRA_AUTHORITIES_CFG="zebra-authorities.cfg"
232             ;;
233         *)
234             die "Error: '$indexing_mode' is not a valid indexing mode for authority records."
235             ;;
236     esac
237 }
238
239
240 set_memcached()
241 {
242     local instance="$1"
243
244     if [ "$CLO_MEMCACHED_SERVERS" != "" ]; then
245         MEMCACHED_SERVERS=$CLO_MEMCACHED_SERVERS
246     else
247         if [ "$MEMCACHED_SERVERS" = "" ]; then
248             MEMCACHED_SERVERS=$DEFAULT_MEMCACHED_SERVERS
249         # else: was set by the koha-sites.conf file
250         fi
251     fi
252
253     if [ "$CLO_MEMCACHED_PREFIX" != "" ]; then
254         MEMCACHED_NAMESPACE="$CLO_MEMCACHED_PREFIX$instance"
255     else
256         if [ "$MEMCACHED_PREFIX" != "" ]; then
257             MEMCACHED_NAMESPACE="$MEMCACHED_PREFIX$instance"
258         else
259             MEMCACHED_NAMESPACE="$DEFAULT_MEMCACHED_PREFIX$instance"
260         fi
261     fi
262
263 }
264
265 # Set defaults and read config file, if it exists.
266 DOMAIN=""
267 OPACPORT="80"
268 OPACPREFIX=""
269 OPACSUFFIX=""
270 INTRAPORT="8080"
271 INTRAPREFIX=""
272 INTRASUFFIX=""
273 DEFAULTSQL=""
274 ZEBRA_MARC_FORMAT="marc21"
275 ZEBRA_LANGUAGE="en"
276 ADMINUSER="1"
277 PASSWDFILE="/etc/koha/passwd"
278
279 # memcached variables
280 USE_MEMCACHED="no"
281 MEMCACHED_SERVERS=""
282 MEMCACHED_PREFIX=""
283 # hardcoded memcached defaults
284 DEFAULT_MEMCACHED_SERVERS="127.0.0.1:11211"
285 DEFAULT_MEMCACHED_PREFIX="koha_"
286
287 # Indexing mode variables (default is DOM)
288 BIBLIOS_INDEXING_MODE="dom"
289 AUTHORITIES_INDEXING_MODE="dom"
290
291 START_BIBLIOS_RETRIEVAL_INFO=""
292 END_BIBLIOS_RETRIEVAL_INFO=""
293 START_AUTHORITIES_RETRIEVAL_INFO=""
294 END_AUTHORITIES_RETRIEVAL_INFO=""
295
296 if [ -e /etc/koha/koha-sites.conf ]
297 then
298     . /etc/koha/koha-sites.conf
299 fi
300
301 [ $# -ge 1 ] && [ $# -le 16 ] || ( usage ; die "Error: wrong parameters" )
302
303 TEMP=`getopt -o chrpm:l:d:f:b:a: -l create-db,request-db,populate-db,use-db,use-memcached,help,marcflavor:,auth-idx:,biblio-idx:,zebralang:,defaultsql:,configfile:,passwdfile:,database:,adminuser:,memcached-servers:,memcached-prefix:, \
304      -n "$0" -- "$@"`
305
306 # Note the quotes around `$TEMP': they are essential!
307 eval set -- "$TEMP"
308
309 # Temporary variables for the command line options
310 CLO_ZEBRA_MARC_FORMAT=""
311 CLO_ZEBRA_LANGUAGE=""
312 CLO_DEFAULTSQL=""
313 CLO_ADMINUSER=""
314 CLO_BIBLIOS_INDEXING_MODE=""
315 CLO_AUTHORITIES_INDEXING_MODE=""
316 CLO_MEMCACHED_SERVERS=""
317 CLO_MEMCACHED_PREFIX=""
318
319
320 while true ; do
321     case "$1" in
322         -c|--create-db)
323             op=create ; shift ;;
324         -r|--request-db)
325             op=request ; shift ;;
326         -p|--populate-db)
327             op=populate ; shift ;;
328         -u|--use-db)
329             op=use ; shift ;;
330         --use-memcached)
331             USE_MEMCACHED="yes" ; shift ;;
332         --memcached-servers)
333             CLO_MEMCACHED_SERVERS="$2" ; shift 2 ;;
334         --memcached-prefix)
335             CLO_MEMCACHED_PREFIX="$2" ; shift 2;;
336         -m|--marcflavor)
337             CLO_ZEBRA_MARC_FORMAT="$2" ; shift 2 ;;
338         -l|--zebralang)
339             CLO_ZEBRA_LANGUAGE="$2" ; shift 2 ;;
340         --auth-idx)
341             CLO_AUTHORITIES_INDEXING_MODE="$2" ; shift 2 ;;
342         --biblio-idx)
343             CLO_BIBLIOS_INDEXING_MODE="$2" ; shift 2 ;;
344         -d|--defaultsql)
345             CLO_DEFAULTSQL="$2" ; shift 2 ;;
346         -f|--configfile)
347             configfile="$2" ; shift 2 ;;
348         -s|--passwdfile)
349             CLO_PASSWDFILE="$2" ; shift 2 ;;
350         -b|--database)
351             CLO_DATABASE="$2" ; shift 2 ;;
352         -a|--adminuser)
353             CLO_ADMINUSER="$2" ; shift 2 ;;
354         -h|--help)
355             usage ; exit 0 ;;
356         --)
357             shift ; break ;;
358         *)
359             die "Internal error processing command line arguments" ;;
360     esac
361 done
362
363 # Load the configfile given on the command line
364 if [ "$configfile" != "" ]
365 then
366     if [ -e "$configfile" ]
367     then
368         . "$configfile"
369     else
370         die "$configfile does not exist.";
371     fi
372 fi
373
374 # Make sure options from the command line get the highest precedence
375 if [ "$CLO_ZEBRA_MARC_FORMAT" != "" ]
376 then
377     ZEBRA_MARC_FORMAT="$CLO_ZEBRA_MARC_FORMAT"
378 fi
379 if [ "$CLO_ZEBRA_LANGUAGE" != "" ]
380 then
381     ZEBRA_LANGUAGE="$CLO_ZEBRA_LANGUAGE"
382 fi
383 if [ "$CLO_DEFAULTSQL" != "" ]
384 then
385     DEFAULTSQL="$CLO_DEFAULTSQL"
386 fi
387 if [ "$CLO_ADMINUSER" != "" ]
388 then
389     ADMINUSER="$CLO_ADMINUSER"
390 fi
391 if [ "$CLO_PASSWDFILE" != "" ]
392 then
393     PASSWDFILE="$CLO_PASSWDFILE"
394 fi
395
396 if [ "$CLO_BIBLIOS_INDEXING_MODE" !=  "" ]; then
397     BIBLIOS_INDEXING_MODE=$CLO_BIBLIOS_INDEXING_MODE
398 fi
399
400 set_biblios_indexing_mode $BIBLIOS_INDEXING_MODE $ZEBRA_MARC_FORMAT
401
402
403 if [ "$CLO_AUTHORITIES_INDEXING_MODE" !=  "" ]; then
404     AUTHORITIES_INDEXING_MODE=$CLO_AUTHORITIES_INDEXING_MODE
405 fi
406
407 set_authorities_indexing_mode $AUTHORITIES_INDEXING_MODE $ZEBRA_MARC_FORMAT
408
409 name="$1"
410
411 if [ "$USE_MEMCACHED" = "yes" ]; then
412     set_memcached $name
413 elif [ "$CLO_MEMCACHED_SERVERS" != "" ] || \
414      [ "$CLO_MEMCACHED_PREFIX" != "" ]; then
415
416     MSG=`cat <<EOF
417
418 Error: you provided memcached configuration switches but memcached is not enabled.
419 Please set USE_MEMCACHED="yes" on /etc/koha/koha-sites.conf or use the
420 --use-memcached option switch to enable it.
421
422 EOF`
423
424     usage ; die $MSG
425 else
426     # Unset memcached-related variables
427     MEMCACHED_SERVERS=""
428     MEMCACHED_PREFIX=""
429 fi
430
431 # Are we root? If not, the mod_rewrite check will fail and be confusing, so
432 # we look into this first.
433 if [[ $UID -ne 0 ]]
434 then
435     die "This script must be run with root privileges."
436 fi
437
438 # Check everything is ok with Apache, die otherwise
439 check_apache_config
440
441 opacdomain="$OPACPREFIX$name$OPACSUFFIX$DOMAIN"
442 intradomain="$INTRAPREFIX$name$INTRASUFFIX$DOMAIN"
443
444
445 if [ -f $PASSWDFILE ] && [ `cat $PASSWDFILE | grep "^$name:"` ]
446 then
447     passwdline=`cat $PASSWDFILE | grep "^$name:"`
448     mysqluser=`echo $passwdline | cut -d ":" -f 2`
449     mysqlpwd=`echo $passwdline | cut -d ":" -f 3`
450     mysqldb=`echo $passwdline | cut -d ":" -f 4`
451 fi
452
453 # The order of precedence for MySQL database name is:
454 # default < passwd file < command line
455 if [ "$mysqldb" = "" ]
456 then
457     mysqldb="koha_$name"
458 fi
459 if [ "$CLO_DATABASE" != "" ]
460 then
461     mysqldb="$CLO_DATABASE"
462 fi
463
464 if [ "$mysqluser" = "" ]
465 then
466     mysqluser="koha_$name"
467 fi
468 mysqlhost="$(getmysqlhost)"
469
470 if [ "$op" = create ] || [ "$op" = request ] || [ "$op" = use ]
471 then
472     if [ "$mysqlpwd" = "" ]
473     then
474         mysqlpwd="$(pwgen -s 16 1)"
475     fi
476 else
477     mysqlpwd="$(getinstancemysqlpassword $name)"
478 fi
479
480
481 if [ "$op" = create ] || [ "$op" = request ] || [ "$op" = use ]
482 then
483     # Create new user and group.
484     username="$name-koha"
485     if getent passwd "$username" > /dev/null
486     then
487         die "User $username already exists."
488     fi
489     if getent group "$username" > /dev/null
490     then
491         die "Group $username already exists."
492     fi
493     adduser --no-create-home --disabled-login \
494         --gecos "Koha instance $username" \
495         --home "/var/lib/koha/$name" \
496         --quiet "$username"
497
498     # Create the site-specific directories.
499     koha-create-dirs "$name"
500
501     # Generate Zebra database password.
502     zebrapwd="$(pwgen -s 16 1)"
503     # Future enhancement: make this configurable for when your db is on
504     # another server.
505     mysql_hostname="localhost"
506     # Set up MySQL database for this instance.
507     if [ "$op" = create ]
508     then
509         mysql --defaults-extra-file=/etc/mysql/koha-common.cnf <<eof
510 CREATE DATABASE \`$mysqldb\`;
511 CREATE USER \`$mysqluser\`@'$mysql_hostname' IDENTIFIED BY '$mysqlpwd';
512 CREATE USER \`$mysqluser\`@'%' IDENTIFIED BY '$mysqlpwd';
513 GRANT ALL PRIVILEGES ON \`$mysqldb\`.* TO \`$mysqluser\`;
514 FLUSH PRIVILEGES;
515 eof
516     fi #`
517
518     if [ "$op" = use ]
519     then
520         mysql --defaults-extra-file=/etc/mysql/koha-common.cnf --force <<eof
521 CREATE USER \`$mysqluser\`@'$mysql_hostname' IDENTIFIED BY '$mysqlpwd';
522 CREATE USER \`$mysqluser\`@'%' IDENTIFIED BY '$mysqlpwd';
523 GRANT ALL PRIVILEGES ON \`$mysqldb\`.* TO \`$mysqluser\`;
524 FLUSH PRIVILEGES;
525 eof
526     fi #`
527
528     # Generate and install Apache site-available file and log dir.
529     generate_config_file apache-site.conf.in \
530         "/etc/apache2/sites-available/$name.conf"
531     mkdir "/var/log/koha/$name"
532     chown "$username:$username" "/var/log/koha/$name"
533
534
535     # Generate and install main Koha config file.
536     generate_config_file koha-conf-site.xml.in \
537         "/etc/koha/sites/$name/koha-conf.xml"
538
539     # Generate and install Zebra config files.
540     generate_config_file zebra-biblios-site.cfg.in \
541         "/etc/koha/sites/$name/zebra-biblios.cfg"
542     generate_config_file zebra-biblios-dom-site.cfg.in \
543         "/etc/koha/sites/$name/zebra-biblios-dom.cfg"
544     generate_config_file zebra-authorities-site.cfg.in \
545         "/etc/koha/sites/$name/zebra-authorities.cfg"
546     generate_config_file zebra-authorities-dom-site.cfg.in \
547         "/etc/koha/sites/$name/zebra-authorities-dom.cfg"
548     generate_config_file zebra.passwd.in \
549         "/etc/koha/sites/$name/zebra.passwd"
550
551
552     # Create a GPG-encrypted file for requesting a DB to be set up.
553     if [ "$op" = request ]
554     then
555         touch "$name-db-request.txt"
556         chmod 0600 "$name-db-request.txt"
557         cat > "$name-db-request.txt" << eof
558 Please create a MySQL database and user on $mysqlhost as follows:
559
560 database name: $mysqldb
561 database user: $mysqluser
562      password: $mysqlpwd
563
564 Thank you.
565 eof
566
567         echo "See $name-db-request.txt for database creation request."
568         echo "Please forward it to the right person, and then run"
569         echo "$0 --populate-db $name"
570         echo "Thanks."
571     fi
572 fi
573
574
575 if [ "$op" = create ] || [ "$op" = populate ]
576 then
577     # Re-fetch the passwords from the config we've generated, allows it
578     # to be different from what we set, in case the user had to change
579     # something.
580     mysqluser=$(getinstancemysqluser $name)
581     mysqldb=$(getinstancemysqldatabase $name)
582     # Use the default database content if that exists.
583     if [ -e "$DEFAULTSQL" ]
584     then
585         # Populate the database with default content.
586         zcat "$DEFAULTSQL" |
587         sed "s/__KOHASITE__/$name/g" |
588         mysql --host="$mysqlhost" --user="$mysqluser" --password="$mysqlpwd" "$mysqldb"
589
590
591         # Change the default user's password.
592         staffpass="$(pwgen 12 1)"
593         staffdigest=$(echo -n "$staffpass" |
594                       perl -e '
595                             use Digest::MD5 qw(md5_base64); 
596                             while (<>) { print md5_base64($_), "\n"; }')
597         mysql --host="$mysqlhost" --user="$mysqluser" \
598 --password="$mysqlpwd" <<eof
599 USE \`$mysqldb\`;
600 UPDATE borrowers 
601 SET password = '$staffdigest' 
602 WHERE borrowernumber = $ADMINUSER;
603 eof
604         #`
605         echo "staff user password is '$staffpass' but keep that secret"
606
607         # Upgrade the database schema, just in case the dump was from an 
608         # old version.
609         koha-upgrade-schema "$name"
610     else
611         echo "Koha instance is empty, no staff user created."
612     fi
613 fi
614
615
616 if [ "$op" = create ] || [ "$op" = populate ] || [ "$op" = use ]
617 then
618     # Reconfigure Apache.
619     a2ensite "$name"
620     service apache2 restart
621
622     # Start Zebra.
623     koha-start-zebra "$name"
624 fi
625
626
627 if [ "$op" = request ]
628 then
629     koha-disable "$name"
630 fi
631
632 echo <<eoh
633
634 Email for this instance is disabled. When you're ready to enable it, use:
635 koha-email-enable $name
636 eoh