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