1 # Copyright 2007 MJ Ray
2 # Copyright 2016 PTFS Europe
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it
7 # 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 # Koha is distributed in the hope that it will be useful, but
12 # 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 Koha; if not, see <http://www.gnu.org/licenses>.
19 # Current maintainer MJR http://mjr.towers.org.uk/
24 use ExtUtils::MakeMaker;
27 use Getopt::Long qw/HelpMessage/;
28 use FindBin; # we need to enforce which C4::Installer::PerlModule is used in case more than one is installed
30 use lib $FindBin::Bin;
34 my $koha_pm = C4::Installer::PerlModules->new;
37 die "perl 5.10 or later required" unless ($] >= 5.010000);
39 # Hash up directory structure & files beginning with the directory we were called from (should be the base of koha)...
41 my $dirtree = hashdir('.');
46 Makefile.PL - Koha packager and installer
50 =head2 BASIC INSTALLATION
57 =head2 UPGRADE INSTALLATION
59 NOTE: This option is only available if koha-install-log exists.
61 perl Makefile.PL --prev-install-log /path/to/koha-install-log
67 =head2 PACKAGING RELEASE TARBALLS
78 --prev-install-log Read configuration from previous installation
79 --install_mode Installation mode (dev, standard, single)
80 --db_type Database (mysql, Pg)
81 --db_host Database host (e.g. localhost)
82 --db_port Database port (e.g. 3306)
83 --db_name Database name (e.g. koha)
84 --db_user Database user (e.g. kohaadmin)
85 --db_pass Database password (e.g. katikoan)
86 --zebra_marc_format Zebra MARC format (marc21, normarc, unimarc)
87 --zebra_language Zebra language (e.g. en)
88 --zebra_tokenizer Zebra tokenizer (chr, icu)
89 --zebra_user Zebra user (e.g. kohauser)
90 --zebra_pass Zebra password (e.g. zebrastripes)
91 --zebra_sru_host Zebra SRU servername (e.g. localhost)
92 --zebra_sru_biblios_port Zebra SRU biblios port (e.g. 9998)
93 --zebra_sru_authorities_port Zebra SRU biblios port (e.g. 9999)
94 --auth_index_mode Authority index mode (grs1, dom)
95 --bib_index_mode Bibliographic index mode (grs1, dom)
96 --koha_user Koha Unix user (e.g. koha)
97 --koha_group Koha Unix group (e.g. koha)
98 --install_sru Install the SRU server (yes, no)
99 --install_pazpar2 Install PazPar2 (yes, no)
100 --use_memcached Use Memcached (yes, no)
101 --font_dir Location of fonts (e.g. /usr/share/fonts/truetype/ttf-dejavu)
102 --run_database_tests Run database dependent tests (yes, no)
103 --install_base Base directory of installation (e.g. /usr/share/koha)
104 --template-cache-dir Specify a template cache directory (e.g. /var/cache/koha)
105 --help Display this help message
109 This is a packager and installer that uses
110 ExtUtils::MakeMaker, which is fairly common
112 As well as building tar or zip files
113 and installing with the above commands,
114 it allows us to check pre-requisites
115 and generate configuration files.
119 =head2 NAME, VERSION_FROM, ABSTRACT, AUTHOR
121 Basic metadata about this software.
125 Suppress generation of META.yml file.
129 Hash of perl modules and versions required.
133 Hash of file mappings
137 This is a hash of PL scripts to run after installation and
138 the files to ask them to generate.
139 Maybe use the values from CONFIGURE
140 to generate initial configuration files in future.
146 This is a hash mapping directories and files in the
147 source tree to installation target directories. The rules
148 for this mapping are:
152 =item If a directory or file is specified, it and its
153 contents will be copied to the installation target directory.
155 =item If a subdirectory of a mapped directory is specified,
156 its target overrides the parent's target for that subdirectory.
158 =item The value of each map entry may either be a scalar containing
159 one target or a reference to a hash containing 'target' and 'trimdir'
162 =item Any files at the top level of the source tree that are
163 not included in the map will not be installed.
165 =item Any directories at the top level of the source tree
166 that are not included in the map will be installed in
167 INTRANET_CGI_DIR. This is a sensible default given the
168 current organization of the source tree, but (FIXME) it
169 would be better to reorganize the source tree to better
170 match the installation system, to allow adding new directories
171 without having to adjust Makefile.PL each time. The idea
172 is to make the C<$target_map> hash as minimal as possible.
176 The permitted installation targets are:
180 =item INTRANET_CGI_DIR
182 CGI scripts for intranet (staff) interface.
184 =item INTRANET_TMPL_DIR
186 HTML templates for the intranet interface.
188 =item INTRANET_WWW_DIR
190 HTML files, images, etc. for DocumentRoot for the intranet interface.
194 CGI scripts for OPAC (public) interface.
198 HTML templates for the OPAC interface.
202 HTML files, images, etc. for DocumentRoot for the OPAC interface.
204 =item PERL_MODULE_DIR
206 Perl modules (at present just the C4 modules) that are intimately
207 tied to Koha. Depending on the installation options, these
208 may or may not be installed one of the standard directories
209 in Perl's default @LIB.
213 Directory for Koha configuration files.
217 Directory for Zebra configuration files.
221 Directory for Zebra's lock files. This includes subdirs for authorities,
222 biblios, and the zebra rebuild function. Any activity to reindex
223 zebra from koha should interlock here with rebuild_zebra.pl.
227 Directory for Zebra's data files.
231 Directory for Zebra's UNIX-domain sockets.
235 Directory for for miscellaenous scripts, among other
236 things the translation toolkit and RSS feed tools.
240 Directory for command-line scripts and daemons to
241 be set up all for installation modes.
243 =item SCRIPT_NONDEV_DIR
245 Directory for command-line scripts that should
246 be installed in the same directory as the
247 SCRIPT_DIR target except 'dev' installs.
251 Directory for man pages created from POD -- will mostly
252 contain information of interest to Koha developers.
256 Directory for Koha documentation accessed from the
257 command-line, e.g., READMEs.
261 Directory for Apache and Zebra logs produced by Koha.
265 Directory for backup files produced by Koha.
269 Directory for external Koha plugins.
271 =item PAZPAR2_CONF_DIR
273 Directory for PazPar2 configuration files.
277 Directory where DejaVu fonts are installed.
281 This is a dummy target used to explicitly state
282 that a given file or directory is not to be installed.
283 This is used either for parts of the installer itself
284 or for development tools that are not applicable to a
285 production installation.
292 './about.pl' => 'INTRANET_CGI_DIR',
293 './acqui' => 'INTRANET_CGI_DIR',
294 './admin' => 'INTRANET_CGI_DIR',
295 './api' => { target => 'API_CGI_DIR', trimdir => -1 },
296 './authorities' => 'INTRANET_CGI_DIR',
297 './basket' => 'INTRANET_CGI_DIR',
298 './C4' => 'PERL_MODULE_DIR',
299 './C4/SIP/t' => 'NONE',
300 './C4/SIP/koha_test' => 'NONE',
301 './C4/tests' => 'NONE',
302 './catalogue' => 'INTRANET_CGI_DIR',
303 './cataloguing' => 'INTRANET_CGI_DIR',
304 './changelanguage.pl' => 'INTRANET_CGI_DIR',
305 './check_sysprefs.pl' => 'NONE',
306 './circ' => 'INTRANET_CGI_DIR',
307 './clubs' => 'INTRANET_CGI_DIR',
308 './course_reserves' => 'INTRANET_CGI_DIR',
309 './docs/history.txt' => { target => 'DOC_DIR', trimdir => -1 },
310 './offline_circ' => 'INTRANET_CGI_DIR',
311 './edithelp.pl' => 'INTRANET_CGI_DIR',
312 './etc' => { target => 'KOHA_CONF_DIR', trimdir => -1 },
313 './etc/zebradb' => { target => 'ZEBRA_CONF_DIR', trimdir => -1 },
314 './etc/pazpar2' => { target => 'PAZPAR2_CONF_DIR', trimdir => -1 },
315 './help.pl' => 'INTRANET_CGI_DIR',
316 './ill' => 'INTRANET_CGI_DIR',
317 './installer-CPAN.pl' => 'NONE',
318 './installer' => 'INTRANET_CGI_DIR',
319 './errors' => {target => 'INTRANET_CGI_DIR'},
320 './Koha' => 'PERL_MODULE_DIR',
321 './Koha.pm' => 'PERL_MODULE_DIR',
322 './koha-tmpl/intranet-tmpl' => {target => 'INTRANET_TMPL_DIR', trimdir => -1},
323 './koha-tmpl/opac-tmpl' => {target => 'OPAC_TMPL_DIR', trimdir => -1},
324 './kohaversion.pl' => 'INTRANET_CGI_DIR',
325 './labels' => 'INTRANET_CGI_DIR',
326 './mainpage.pl' => 'INTRANET_CGI_DIR',
327 './Makefile.PL' => 'NONE',
328 './MANIFEST.SKIP' => 'NONE',
329 './members' => 'INTRANET_CGI_DIR',
330 './misc' => { target => 'SCRIPT_NONDEV_DIR', trimdir => -1 },
331 './misc/bin' => { target => 'SCRIPT_DIR', trimdir => -1 },
332 './misc/release_notes' => { target => 'DOC_DIR', trimdir => 2 },
333 './misc/translator' => { target => 'MISC_DIR', trimdir => 2 },
334 './misc/koha-install-log' => { target => 'MISC_DIR', trimdir => -1 },
335 './misc/installer_devel_notes' => 'NONE',
336 './opac' => 'OPAC_CGI_DIR',
337 './OpenILS' => 'PERL_MODULE_DIR',
338 './README.txt' => 'NONE',
339 './patroncards' => 'INTRANET_CGI_DIR',
340 './patron_lists' => 'INTRANET_CGI_DIR',
341 './plugins' => 'INTRANET_CGI_DIR',
342 './reports' => 'INTRANET_CGI_DIR',
343 './reserve' => 'INTRANET_CGI_DIR',
344 './reviews' => 'INTRANET_CGI_DIR',
345 './rewrite-config.PL' => 'NONE',
346 './reviews' => 'INTRANET_CGI_DIR',
347 './rotating_collections' => 'INTRANET_CGI_DIR',
348 './serials' => 'INTRANET_CGI_DIR',
349 './services' => 'INTRANET_CGI_DIR',
351 './skel/var/log/koha' => { target => 'LOG_DIR', trimdir => -1 },
352 './skel/var/spool/koha' => { target => 'BACKUP_DIR', trimdir => -1 },
353 './skel/var/run/koha/zebradb' => { target => 'ZEBRA_RUN_DIR', trimdir => -1 },
354 './skel/var/lock/koha/zebradb/authorities' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
355 './skel/var/lib/koha/zebradb/authorities/key' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
356 './skel/var/lib/koha/zebradb/authorities/register' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
357 './skel/var/lib/koha/zebradb/authorities/shadow' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
358 './skel/var/lib/koha/zebradb/authorities/tmp' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
359 './skel/var/lock/koha/zebradb/biblios' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
360 './skel/var/lib/koha/zebradb/biblios/key' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
361 './skel/var/lib/koha/zebradb/biblios/register' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
362 './skel/var/lib/koha/zebradb/biblios/shadow' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
363 './skel/var/lib/koha/zebradb/biblios/tmp' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
364 './skel/var/lock/koha/zebradb/rebuild' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
365 './skel/var/lib/koha/plugins' => { target => 'PLUGINS_DIR', trimdir => 6 },
366 './sms' => 'INTRANET_CGI_DIR',
367 './suggestion' => 'INTRANET_CGI_DIR',
368 './svc' => 'INTRANET_CGI_DIR',
370 './tags' => 'INTRANET_CGI_DIR',
371 './tmp' => 'NONE', # FIXME need to determine whether
372 # Koha generates any persistent temp files
373 # that should go in /var/tmp/koha
374 './tools' => 'INTRANET_CGI_DIR',
375 './virtualshelves' => 'INTRANET_CGI_DIR',
376 './xml_sax.pl' => 'PERL_MODULE_DIR',
377 # ignore files and directories created by the install itself
378 './pm_to_blib' => 'NONE',
380 '.sass-lint.yml' => 'NONE',
381 '.scss-lint.yml' => 'NONE',
382 'gulpfile.js' => 'NONE',
383 'package.json' => 'NONE',
384 'yarn.lock' => 'NONE',
387 =head1 CONFIGURATION OPTIONS
389 The following configuration options are used by the installer.
395 Specifies whether installation will be FHS-compliant (default,
396 assumes user has root), put everything under
397 a single directory (for users installing on a web host
398 that allows CGI scripts and a MySQL database but not root
399 access), or development (for a developer who wants to run
400 Koha from a git clone with no fuss).
404 Directory under which most components will go. Default
405 value will vary depending on INSTALL_MODE.
409 Type of DBMS (e.g., mysql or Pg).
417 Port that DBMS server is listening on.
421 Name of the DBMS database for Koha.
425 Name of DBMS user account for Koha's database.
429 Pasword of DMBS user account for Koha's database.
431 =item ZEBRA_MARC_FORMAT
433 Specifies format of MARC records to be indexed by Zebra.
437 Specifies primary language of records that will be
442 Internal Zebra user account for the index.
446 Internal Zebra user account's password.
450 System user account that will own Koha's files.
454 System group that will own Koha's files.
460 # default configuration options
461 my %config_defaults = (
462 'DB_TYPE' => 'mysql',
463 'DB_HOST' => 'localhost',
465 'DB_USER' => 'kohaadmin',
466 'DB_PASS' => 'katikoan',
467 'DB_USE_TLS' => 'no',
468 'DB_TLS_CA_CERTIFICATE' => '/etc/mysql-ssl/server-ca.pem',
469 'DB_TLS_CLIENT_CERTIFICATE' => '/etc/mysql-ssl/client-cert.pem',
470 'DB_TLS_CLIENT_KEY' => '/etc/mysql-ssl/client-key.pem',
471 'INSTALL_SRU' => 'yes',
472 'INSTALL_PAZPAR2' => 'no',
473 'AUTH_INDEX_MODE' => 'dom',
474 'BIB_INDEX_MODE' => 'dom',
475 'ZEBRA_MARC_FORMAT' => 'marc21',
476 'ZEBRA_LANGUAGE' => 'en',
477 'ZEBRA_TOKENIZER' => 'chr',
478 'ZEBRA_USER' => 'kohauser',
479 'ZEBRA_PASS' => 'zebrastripes',
480 'ZEBRA_SRU_HOST' => 'localhost',
481 'ZEBRA_SRU_BIBLIOS_PORT' => '9998',
482 'ZEBRA_SRU_AUTHORITIES_PORT' => '9999',
483 'KOHA_USER' => 'koha',
484 'KOHA_GROUP' => 'koha',
485 'MERGE_SERVER_HOST' => 'localhost',
486 'MERGE_SERVER_PORT' => '11001',
487 'PAZPAR2_HOST' => 'localhost',
488 'PAZPAR2_PORT' => '11002',
489 'RUN_DATABASE_TESTS' => 'no',
490 'PATH_TO_ZEBRA' => '',
491 'USE_MEMCACHED' => 'yes',
492 'MEMCACHED_SERVERS' => '127.0.0.1:11211',
493 'MEMCACHED_NAMESPACE' => 'KOHA',
494 'TEMPLATE_CACHE_DIR' => '/tmp/koha',
495 'FONT_DIR' => '/usr/share/fonts/truetype/ttf-dejavu'
498 # set some default configuration options based on OS
499 # more conditions need to be added for other OS's
501 warn "Your platform appears to be $^O.\n" if $DEBUG;
503 if ( $^O eq 'cygwin' ) {
504 # Most Unix2Win32 ports seem to poke everything into the Program Files directory
505 # this could be changed to put some files (ie. libraries) into system32, etc.
506 $config_defaults{'INSTALL_MODE'} = 'single';
507 $config_defaults{'INSTALL_BASE'} = 'c:/progra~1/koha'; # Use 8.3 names to be safe...
510 $config_defaults{'INSTALL_MODE'} = 'standard';
511 $config_defaults{'INSTALL_BASE'} = '/usr/share/koha';
514 # valid values for certain configuration options
515 my %valid_config_values = (
516 'INSTALL_MODE' => { 'standard' => 1, 'single' => 1, 'dev' => 1 },
517 'DB_TYPE' => { 'mysql' => 1, 'Pg' => 1 },
518 'DB_USE_TLS' => {'yes', 'no'},
519 'INSTALL_SRU' => { 'yes' => 1, 'no' => 1 },
520 'AUTH_INDEX_MODE' => { 'grs1' => 1, 'dom' => 1 },
521 'BIB_INDEX_MODE' => { 'grs1' => 1, 'dom' => 1 },
522 'ZEBRA_MARC_FORMAT' => { 'marc21' => 1, 'normarc' => 1, 'unimarc' => 1 }, # FIXME should generate from contents of distributation
523 'ZEBRA_LANGUAGE' => { 'cs' => 1, 'en' => 1, 'es' => 1, 'fr' => 1, 'gr' => 1, 'nb' => 1, 'ru' => 1, 'uk' => 1 }, # FIXME should generate from contents of distribution
524 'ZEBRA_TOKENIZER' => { chr => 1, icu => 1 },
525 'RUN_DATABASE_TESTS' => { 'yes' => 1, 'no' => 1 },
526 'USE_MEMCACHED' => { 'yes' => 1, 'no' => 1 },
529 # get settings from command-line
530 my $koha_install_log = "";
531 my $cli_koha_install_mode = "";
532 my $cli_koha_db_type = "";
533 my $cli_koha_db_host = "";
534 my $cli_koha_db_port = "";
535 my $cli_koha_db_name = "";
536 my $cli_koha_db_user = "";
537 my $cli_koha_db_pass = "";
538 my $cli_zebra_marc_format = "";
539 my $cli_zebra_language = "",
540 my $cli_zebra_tokenizer = "";
541 my $cli_zebra_user = "";
542 my $cli_zebra_pass = "";
543 my $cli_zebra_sru_host = "";
544 my $cli_zebra_sru_bib_port = "";
545 my $cli_zebra_sru_auth_port = "";
546 my $cli_koha_auth_index_mode = "";
547 my $cli_koha_bib_index_mode = "";
548 my $cli_koha_user = "";
549 my $cli_koha_group = "";
550 my $cli_koha_install_sru = "";
551 my $cli_koha_install_pazpar2 = "";
552 my $cli_koha_use_memcached = "";
553 my $cli_koha_font_dir = "";
554 my $cli_koha_run_database_tests = "";
555 my $cli_koha_install_base = "";
556 my $cli_koha_template_cache_dir = "";
557 Getopt::Long::Configure('pass_through');
558 my $results = GetOptions(
559 "prev-install-log=s" => \$koha_install_log,
560 "install_mode=s" => \$cli_koha_install_mode,
561 "db_type=s" => \$cli_koha_db_type,
562 "db_host=s" => \$cli_koha_db_host,
563 "db_port=s" => \$cli_koha_db_port,
564 "db_name=s" => \$cli_koha_db_name,
565 "db_user=s" => \$cli_koha_db_user,
566 "db_pass=s" => \$cli_koha_db_pass,
567 "zebra_marc_format=s" => \$cli_zebra_marc_format,
568 "zebra_language=s" => \$cli_zebra_language,
569 "zebra_tokenizer=s" => \$cli_zebra_tokenizer,
570 "zebra_user=s" => \$cli_zebra_user,
571 "zebra_pass=s" => \$cli_zebra_pass,
572 "zebra_sru_host=s" => \$cli_zebra_sru_host,
573 "zebra_sru_biblios_port=s" => \$cli_zebra_sru_bib_port,
574 "zebra_sru_authorities_port=s" => \$cli_zebra_sru_auth_port,
575 "auth_index_mode=s" => \$cli_koha_auth_index_mode,
576 "bib_index_mode=s" => \$cli_koha_bib_index_mode,
577 "koha_user=s" => \$cli_koha_user,
578 "koha_group=s" => \$cli_koha_group,
579 "install_sru=s" => \$cli_koha_install_sru,
580 "install_pazpar2=s" => \$cli_koha_install_pazpar2,
581 "use_memcached=s" => \$cli_koha_use_memcached,
582 "font_dir=s" => \$cli_koha_font_dir,
583 "run_database_tests=s" => \$cli_koha_run_database_tests,
584 "install_base=s" => \$cli_koha_install_base,
585 "template-cache-dir=s" => \$cli_koha_template_cache_dir,
586 "help" => sub { HelpMessage(0) },
589 my %install_log_values = ();
590 if ($koha_install_log ne "") {
591 get_install_log_values($koha_install_log, \%install_log_values);
593 # Try to set install_log_values for provided values;
594 get_cli_values(\%install_log_values);
597 my %config = get_configuration(\%config_defaults, \%valid_config_values, \%install_log_values);
598 my ($target_directories, $skip_directories) = get_target_directories(\%config);
599 display_configuration(\%config, $target_directories);
601 get_file_map($target_map, $dirtree, $file_map);
604 'rewrite-config.PL' => [
605 'blib/KOHA_CONF_DIR/koha-conf.xml',
606 'blib/KOHA_CONF_DIR/koha-httpd.conf',
607 'blib/KOHA_CONF_DIR/log4perl.conf',
608 'blib/ZEBRA_CONF_DIR/etc/default.idx',
609 'blib/MISC_DIR/koha-install-log'
611 'fix-perl-path.PL' => [ # this script ensures the correct shebang line for the platform installed on...
616 push @{ $pl_files->{'rewrite-config.PL'} }, (
617 'blib/ZEBRA_CONF_DIR/etc/passwd',
618 'blib/ZEBRA_CONF_DIR/zebra-biblios.cfg',
619 'blib/ZEBRA_CONF_DIR/zebra-biblios-dom.cfg',
620 'blib/ZEBRA_CONF_DIR/zebra-authorities.cfg',
621 'blib/ZEBRA_CONF_DIR/zebra-authorities-dom.cfg',
622 'blib/ZEBRA_CONF_DIR/explain-authorities.xml',
623 'blib/ZEBRA_CONF_DIR/explain-biblios.xml',
624 'blib/ZEBRA_CONF_DIR/retrieval-info-auth-grs1.xml',
625 'blib/ZEBRA_CONF_DIR/retrieval-info-auth-dom.xml',
626 'blib/ZEBRA_CONF_DIR/retrieval-info-bib-grs1.xml',
627 'blib/ZEBRA_CONF_DIR/retrieval-info-bib-dom.xml',
629 push @{ $pl_files->{'rewrite-config.PL'} }, (
630 'blib/SCRIPT_DIR/koha-zebra-ctl.sh',
631 'blib/SCRIPT_DIR/koha-pazpar2-ctl.sh',
632 'blib/SCRIPT_DIR/koha-index-daemon-ctl.sh',
634 if ($config{'INSTALL_PAZPAR2'} eq 'yes') {
635 push @{ $pl_files->{'rewrite-config.PL'} }, (
636 'blib/PAZPAR2_CONF_DIR/koha-biblios.xml',
637 'blib/PAZPAR2_CONF_DIR/pazpar2.xml'
640 $config{'ZEBRA_AUTH_CFG'} = $config{'AUTH_INDEX_MODE'} eq 'dom'
641 ? 'zebra-authorities-dom.cfg'
642 : 'zebra-authorities.cfg';
643 $config{'ZEBRA_BIB_CFG'} = $config{'BIB_INDEX_MODE'} eq 'dom'
644 ? 'zebra-biblios-dom.cfg'
645 : 'zebra-biblios.cfg';
646 $config{'AUTH_RETRIEVAL_CFG'} = $config{'AUTH_INDEX_MODE'} eq 'dom'
647 ? 'retrieval-info-auth-dom.xml'
648 : 'retrieval-info-auth-grs1.xml';
649 $config{'BIB_RETRIEVAL_CFG'} = $config{'BIB_INDEX_MODE'} eq 'dom'
650 ? 'retrieval-info-bib-dom.xml'
651 : 'retrieval-info-bib-grs1.xml';
654 if ($config{'INSTALL_MODE'} ne "dev") {
655 push @{ $pl_files->{'rewrite-config.PL'} }, (
656 'blib/PERL_MODULE_DIR/C4/Context.pm',
657 'blib/SCRIPT_NONDEV_DIR/kohalib.pl'
661 $config{ZEBRA_TOKENIZER_STMT} = $config{ZEBRA_TOKENIZER} eq 'icu'
662 ? 'icuchain words-icu.xml'
663 : 'charmap word-phrase-utf.chr';
665 $config{ZEBRA_PTOKENIZER_STMT} = $config{ZEBRA_TOKENIZER} eq 'icu'
666 ? 'icuchain phrases-icu.xml'
667 : 'charmap word-phrase-utf.chr';
669 my %test_suite_override_dirs = (
670 KOHA_CONF_DIR => ['etc'],
671 ZEBRA_CONF_DIR => ['etc', 'zebradb'],
672 LOG_DIR => ['var', 'log'],
673 BACKUP_DIR => ['var', 'spool'],
674 SCRIPT_DIR => ['bin'],
675 ZEBRA_LOCK_DIR => ['var', 'lock', 'zebradb'],
676 ZEBRA_DATA_DIR => ['var', 'lib', 'zebradb'],
677 ZEBRA_RUN_DIR => ['var', 'run', 'zebradb'],
682 #VERSION => strftime('2.9.%Y%m%d%H',gmtime),
683 VERSION_FROM => 'kohaversion.pl',
684 ABSTRACT => 'Award-winning integrated library system (ILS) and Web OPAC',
685 AUTHOR => 'Koha Contributors <http://koha-community.org/>',
687 PREREQ_PM => $koha_pm->prereq_pm,
692 # Man pages generated from POD
693 # ExtUtils::MakeMaker already manage $(DESTDIR)
694 INSTALLMAN1DIR => File::Spec->catdir(_strip_destdir($target_directories->{'MAN_DIR'}), 'man1'),
695 INSTALLMAN3DIR => File::Spec->catdir(_strip_destdir($target_directories->{'MAN_DIR'}), 'man3'),
697 PL_FILES => $pl_files,
704 This function recurses through the directory structure and builds
705 a hash of hashes containing the structure with arrays holding filenames.
706 This directory hashing routine was taken from BrowserUK @ http://www.perlmonks.org/?node_id=219919
712 opendir my $dh, $dir or die $!;
713 my $tree = {}->{$dir} = {};
714 while( my $file = readdir($dh) ) {
715 next if $file =~ m/^\.{1,2}/ and $file !~ /^\.htaccess/; # .htaccess is a special case
716 my $path = $dir .'/' . $file;
717 $tree->{$file} = hashdir($path), next if -d $path;
718 push @{$tree->{'.'}}, $file;
725 This function combines the target_map and file hash to
726 map each source file to its destination relative to
727 the set of installation targets.
729 Output will be a hash mapping from each source file
730 to its destination value, like this:
732 'mainpage.pl' => '$(INTRANET_CGI_DIR)/mainpage.pl'
737 my $target_map = shift;
739 my $file_map = shift;
740 my $curr_path = @_ ? shift : ['.'];
742 # Traverse the directory tree.
743 # For each file or directory, identify the
744 # most specific match in the target_map
745 foreach my $dir (sort keys %{ $dirtree }) {
747 # deal with files in directory
748 foreach my $file (sort @{ $dirtree->{$dir} }) {
749 my $targetdir = undef;
750 my $matchlevel = undef;
751 # first, see if there is a match on this specific
752 # file in the target map
753 my $filepath = join("/", @$curr_path, $file);
754 if (exists $target_map->{$filepath}) {
755 $targetdir = $target_map->{$filepath};
756 $matchlevel = scalar(@$curr_path) + 1;
758 # no match on the specific file; look for
760 for (my $i = scalar(@$curr_path) - 1; $i >= 0; $i--) {
761 my $dirpath = join("/", @$curr_path[0..$i]);
762 if (exists $target_map->{$dirpath}) {
763 $targetdir = $target_map->{$dirpath};
764 $matchlevel = $i + 1;
769 if (defined $targetdir) {
770 _add_to_file_map($file_map, $targetdir, $curr_path, $file, $matchlevel);
772 my $path = join("/", @$curr_path);
773 print "failed to map: $path/$file\n" if $DEBUG;
777 # dealing with subdirectory
778 push @$curr_path, $dir;
779 get_file_map($target_map, $dirtree->{$dir}, $file_map, $curr_path);
785 sub _add_to_file_map {
786 my $file_map = shift;
787 my $targetdir = shift;
788 my $curr_path = shift;
790 my $matchlevel = shift;
791 my $dest_path = @_ ? shift : $curr_path;
793 # The target can be one of the following:
794 # 1. scalar representing target symbol
795 # 2. hash ref containing target and trimdir keys
797 # Consequently, this routine traverses this structure,
798 # calling itself recursively, until it deals with
799 # all of the scalar target symbols.
800 if (ref $targetdir eq 'HASH') {
801 my $subtarget = $targetdir->{target};
802 if (exists $targetdir->{trimdir}) {
803 # if we get here, we've specified that
804 # rather than installing the file to
805 # $(TARGET)/matching/dirs/subdirs/file,
806 # we want to install it to
807 # $(TARGET)/subdirs/file
809 # Note that this the only place where
810 # $matchlevel is used.
811 my @new_dest_path = @$dest_path;
812 if ($targetdir->{trimdir} == -1) {
813 splice @new_dest_path, 0, $matchlevel;
815 splice @new_dest_path, 0, $targetdir->{trimdir};
817 _add_to_file_map($file_map, $subtarget, $curr_path, $file, $matchlevel, \@new_dest_path);
819 # actually getting here means that the
820 # target was unnecessarily listed
821 # as a hash, but we'll forgive that
822 _add_to_file_map($file_map, $subtarget, $curr_path, $file, $matchlevel);
824 } elsif ($targetdir ne 'NONE' and $targetdir ne '') {
825 my $source = File::Spec->catfile(@$curr_path, $file);
826 my $destination = File::Spec->catfile('blib', $targetdir, @$dest_path, $file);
827 #print "$source => $destination\n"; # DEBUG
828 # quote spaces in file names
829 # FIXME: this is of questionable portability and
830 # probably depends on user's make recognizing this
831 # quoting syntax -- probably better to remove
832 # spaces and shell metacharacters from all file names
833 $source =~ s/ /\\ /g;
834 $destination =~ s/ /\\ /g;
836 $file_map->{$source} = $destination;
840 =head2 get_cli_values
842 Reads values provided on cli for configuration values
849 INSTALL_MODE => $cli_koha_install_mode,
850 DB_TYPE => $cli_koha_db_type,
851 DB_HOST => $cli_koha_db_host,
852 DB_PORT => $cli_koha_db_port,
853 DB_NAME => $cli_koha_db_name,
854 DB_USER => $cli_koha_db_user,
855 DB_PASS => $cli_koha_db_pass,
856 ZEBRA_MARC_FORMAT => $cli_zebra_marc_format,
857 ZEBRA_LANGUAGE => $cli_zebra_language,
858 ZEBRA_TOKENIZER => $cli_zebra_tokenizer,
859 ZEBRA_USER => $cli_zebra_user,
860 ZEBRA_PASS => $cli_zebra_pass,
861 ZEBRA_SRU_HOST => $cli_zebra_sru_host,
862 ZEBRA_SRU_BIBLIOS_PORT => $cli_zebra_sru_bib_port,
863 ZEBRA_SRU_AUTHORITIES_PORT => $cli_zebra_sru_auth_port,
864 AUTH_INDEX_MODE => $cli_koha_auth_index_mode,
865 BIB_INDEX_MODE => $cli_koha_bib_index_mode,
866 KOHA_USER => $cli_koha_user,
867 KOHA_GROUP => $cli_koha_group,
868 INSTALL_SRU => $cli_koha_install_sru,
869 INSTALL_PAZPAR2 => $cli_koha_install_pazpar2,
870 USE_MEMCACHED => $cli_koha_use_memcached,
871 FONT_DIR => $cli_koha_font_dir,
872 RUN_DATABASE_TESTS => $cli_koha_run_database_tests,
873 INSTALL_BASE => $cli_koha_install_base,
874 TEMPLATE_CACHE_DIR => $cli_koha_template_cache_dir
876 foreach my $key (keys %{$map}) {
877 $values->{$key} = $map->{$key} if ($map->{$key});
881 =head2 get_install_log_values
883 Reads value from the Koha install log specified by
888 sub get_install_log_values {
889 my $install_log = shift;
892 open LOG, "<$install_log" or die "Cannot open install log $install_log: $!\n";
895 next if /^#/ or /^\s*$/;
899 my ($key, $value) = split /=/, $_, 2;
900 $values->{$key} = $value;
904 print <<_EXPLAIN_INSTALL_LOG_;
905 Reading values from install log $install_log. You
906 will be prompted only for settings that have been
907 added since the last time you installed Koha. To
908 be prompted for all settings, run 'perl Makefile.PL'
909 without the --prev-install-log option.
910 _EXPLAIN_INSTALL_LOG_
913 =head2 get_configuration
915 This prompts the user for various configuration options.
919 sub get_configuration {
920 my $defaults = shift;
921 my $valid_values = shift;
922 my $install_log_values = shift;
926 By default, Koha can be installed in one of three ways:
928 standard: Install files in conformance with the Filesystem
929 Hierarchy Standard (FHS). This is the default mode
930 and should be used when installing a production
931 Koha system. On Unix systems, root access is
932 needed to complete a standard installation.
934 single: Install files under a single directory. This option
935 is useful for installing Koha without root access, e.g.,
936 on a web host that allows CGI scripts and MySQL databases
937 but requires the user to keep all files under the user's
940 dev: Create a set of symbolic links and configuration files to
941 allow Koha to run directly from the source distribution.
942 This mode is useful for developers who want to run
943 Koha from a git clone.
946 $msg .= _add_valid_values_disp('INSTALL_MODE', $valid_values);
947 $config{'INSTALL_MODE'} = _get_value('INSTALL_MODE', $msg, $defaults->{'INSTALL_MODE'}, $valid_values, $install_log_values);
949 # set message and default value for INSTALL_BASE
950 # depending on value of INSTALL_MODE
951 my $install_base_default = $defaults->{'INSTALL_BASE'};
952 if ($config{'INSTALL_MODE'} eq 'dev') {
954 Please specify the directory in which to install Koha's
955 active configuration files and (if applicable) the
956 Zebra database. Koha's CGI scripts and templates will
957 be run from the current directory.
959 Configuration directory:);
960 # FIXME - home directory portability consideration apply
961 $install_base_default =
963 || ( exists $ENV{HOME} ? "$ENV{HOME}/koha-dev" : "$defaults->{'INSTALL_BASE'}-dev" )
965 } elsif ($config{'INSTALL_MODE'} eq 'single') {
966 $msg = "\nPlease specify the directory in which to install Koha";
967 # FIXME -- we're assuming under a 'single' mode install
968 # that user will likely want to install under the home
969 # directory. This is OK in and of itself, but we should
970 # use File::HomeDir to locate the home directory portably.
971 # This is deferred for now because File::HomeDir is not yet
973 # --we must also keep this portable to the major OS's -fbcit
974 $install_base_default = (exists $ENV{'HOME'}) ? "$ENV{'HOME'}/koha" : $defaults->{'INSTALL_BASE'};
978 Please specify the directory under which most Koha files
981 Note that if you are planning in installing more than
982 one instance of Koha, you may want to modify the last
983 component of the directory path, which will be used
984 as the package name in the FHS layout.
986 Base installation directory);
988 $config{'INSTALL_BASE'} = _get_value('INSTALL_BASE', $msg, $install_base_default, $valid_values, $install_log_values);
990 $config{'INSTALL_BASE'} = File::Spec->rel2abs($config{'INSTALL_BASE'});
991 print "INSTALL_BASE=$config{'INSTALL_BASE'}\r\n" if $DEBUG;
992 if ($config{'INSTALL_MODE'} eq "standard") {
994 Since you are using the 'standard' install
995 mode, you should run 'make install' as root.
996 However, it is recommended that a non-root
997 user (on Unix and Linux platforms) have
998 ownership of Koha's files, including the
999 Zebra indexes if applicable.
1001 Please specify a user account. This
1002 user account does not need to exist
1003 right now, but it needs to exist
1004 before you run 'make install'. Please
1005 note that for security reasons, this
1006 user should not be the same as the user
1007 account Apache runs under.
1010 $config{'KOHA_USER'} = _get_value('KOHA_USER', $msg, $defaults->{'KOHA_USER'}, $valid_values, $install_log_values);
1013 Please specify the group that should own
1014 Koha's files. As above, this group need
1015 not exist right now, but should be created
1016 before you run 'make install'.
1019 $config{'KOHA_GROUP'} = _get_value('KOHA_GROUP', $msg, $defaults->{'KOHA_GROUP'}, $valid_values, $install_log_values);
1023 Please specify which database engine you will use
1024 to store data in Koha. The choices are MySQL and
1025 PostgreSQL; please note that at the moment
1026 PostgreSQL support is highly experimental.
1029 $msg .= _add_valid_values_disp('DB_TYPE', $valid_values);
1030 $config{'DB_TYPE'} = _get_value('DB_TYPE', $msg, $defaults->{'DB_TYPE'}, $valid_values, $install_log_values);
1033 Please specify the name or address of your
1034 database server. Note that the database
1035 does not have to exist at this point, it
1036 can be created after running 'make install'
1037 and before you try using Koha for the first time.
1040 $config{'DB_HOST'} = _get_value('DB_HOST', $msg, $defaults->{'DB_HOST'}, $valid_values, $install_log_values);
1043 Please specify the port used to connect to the
1045 my $db_port_default = $config{'DB_TYPE'} eq 'mysql' ? '3306' : '5432';
1046 $config{'DB_PORT'} = _get_value('DB_PORT', $msg, $db_port_default, $valid_values, $install_log_values);
1049 Please specify the name of the database to be
1051 $config{'DB_NAME'} = _get_value('DB_NAME', $msg, $defaults->{'DB_NAME'}, $valid_values, $install_log_values);
1052 if ($config{'DB_TYPE'} eq 'mysql'){
1054 Please specify whether the connection to MySQL will use TLS
1056 $config{'DB_USE_TLS'} = _get_value('DB_USE_TLS', $msg, $defaults->{'DB_USE_TLS'}, $valid_values, $install_log_values);
1058 if ($config{'DB_USE_TLS'} eq 'yes'){
1060 Please enter the path to the CA certificate for TLS
1062 $config{'DB_TLS_CA_CERTIFICATE'} = _get_value('DB_TLS_CA_CERTIFICATE', $msg, $defaults->{'DB_TLS_CA_CERTIFICATE'}, $valid_values, $install_log_values);
1065 Please enter the path to the client certificate for TLS
1067 $config{'DB_TLS_CLIENT_CERTIFICATE'} = _get_value('DB_TLS_CLIENT_CERTIFICATE', $msg, $defaults->{'DB_TLS_CLIENT_CERTIFICATE'}, $valid_values, $install_log_values);
1069 Please enter the path to the client key for TLS
1071 $config{'DB_TLS_CLIENT_KEY'} = _get_value('DB_TLS_CLIENT_KEY', $msg, $defaults->{'DB_TLS_CLIENT_KEY'}, $valid_values, $install_log_values);
1075 Please specify the user that owns the database to be
1077 $config{'DB_USER'} = _get_value('DB_USER', $msg, $defaults->{'DB_USER'}, $valid_values, $install_log_values);
1080 Please specify the password of the user that owns the
1081 database to be used by Koha);
1082 $config{'DB_PASS'} = _get_value('DB_PASS', $msg, $defaults->{'DB_PASS'}, $valid_values, $install_log_values);
1085 Koha uses the Zebra search engine for high-performance
1086 searching of bibliographic and authority records. Checking
1087 to see if you have installed the Zebra software...
1090 if (defined(my $zebra_path = find_zebra())) {
1091 $config{'PATH_TO_ZEBRA'} = $zebra_path;
1093 Found 'zebrasrv' and 'zebraidx' in $zebra_path.
1097 Unable to find the Zebra programs 'zebrasrv' and 'zebraidx'
1098 in your PATH or in some of the usual places. If you haven't
1099 installed Zebra yet, please do so and run Makefile.PL again.
1105 You must specify the primary MARC format of the
1106 records to be indexed by Zebra.
1108 Koha provides Zebra configuration files for MARC21,
1109 NORMARC and UNIMARC.
1111 MARC format for Zebra indexing);
1112 $msg .= _add_valid_values_disp('ZEBRA_MARC_FORMAT', $valid_values);
1113 $config{'ZEBRA_MARC_FORMAT'} = _get_value('ZEBRA_MARC_FORMAT', $msg, $defaults->{'ZEBRA_MARC_FORMAT'}, $valid_values, $install_log_values);
1115 Koha supplies Zebra configuration files tuned for
1116 searching either English (en) or French (fr) MARC
1119 Primary language for Zebra indexing);
1120 $msg .= _add_valid_values_disp('ZEBRA_LANGUAGE', $valid_values);
1121 $config{'ZEBRA_LANGUAGE'} = _get_value('ZEBRA_LANGUAGE', $msg, $defaults->{'ZEBRA_LANGUAGE'}, $valid_values, $install_log_values);
1124 Koha can use one of two different indexing modes
1125 for the MARC bibliographic records:
1127 dom - uses the DOM XML filter; offers improved
1129 grs1 - [DEPRECATED] uses the Zebra GRS-1 filter,
1130 available for legacy support
1132 Bibliographic indexing mode);
1133 $msg .= _add_valid_values_disp('BIB_INDEX_MODE', $valid_values);
1134 $config{'BIB_INDEX_MODE'} = _get_value('BIB_INDEX_MODE', $msg, $defaults->{'BIB_INDEX_MODE'}, $valid_values, $install_log_values);
1138 Koha can use one of two different indexing modes
1139 for the MARC authorities records:
1141 dom - uses the DOM XML filter; offers improved
1143 grs1 - [DEPRECATED] uses the Zebra GRS-1 filter,
1144 available for legacy support
1146 Authorities indexing mode);
1147 $msg .= _add_valid_values_disp('AUTH_INDEX_MODE', $valid_values);
1148 $config{'AUTH_INDEX_MODE'} = _get_value('AUTH_INDEX_MODE', $msg, $defaults->{'AUTH_INDEX_MODE'}, $valid_values, $install_log_values);
1151 Zebra has two methods to perform records tokenization
1152 and characters normalization: CHR and ICU. ICU is
1153 recommended for catalogs containing non-Latin
1156 $msg .= _add_valid_values_disp('ZEBRA_TOKENIZER', $valid_values);
1157 $config{'ZEBRA_TOKENIZER'} = _get_value('ZEBRA_TOKENIZER', $msg, $defaults->{'ZEBRA_TOKENIZER'}, $valid_values, $install_log_values);
1160 Please specify Zebra database user);
1161 $config{'ZEBRA_USER'} = _get_value('ZEBRA_USER', $msg, $defaults->{'ZEBRA_USER'}, $valid_values, $install_log_values);
1164 Please specify the Zebra database password);
1165 $config{'ZEBRA_PASS'} = _get_value('ZEBRA_PASS', $msg, $defaults->{'ZEBRA_PASS'}, $valid_values, $install_log_values);
1168 Since you've chosen to use Zebra, you can enable the SRU/
1169 Z39.50 Server if you so choose, but you must specify a
1170 few configuration options for it.
1172 Please note that if you choose *NOT* to configure SRU,
1173 koha-conf.xml will still contain some references to SRU
1174 settings. Those references will be ignored by Koha.
1176 Install the SRU configuration files?);
1177 $msg .= _add_valid_values_disp('INSTALL_SRU', $valid_values);
1178 $config{'INSTALL_SRU'} = _get_value('INSTALL_SRU', $msg, $defaults->{'INSTALL_SRU'}, $valid_values, $install_log_values);
1180 if ($config{'INSTALL_SRU'} eq 'yes') {
1182 Since you've chosen to configure SRU, you must
1183 specify the host and port(s) that the SRU
1184 Servers (bibliographic and authority) should run on.
1187 SRU Database host?);
1188 $config{'ZEBRA_SRU_HOST'} = _get_value('ZEBRA_SRU_HOST', $msg, $defaults->{'ZEBRA_SRU_HOST'}, $valid_values, $install_log_values);
1191 SRU port for bibliographic data?);
1192 $config{'ZEBRA_SRU_BIBLIOS_PORT'} = _get_value('ZEBRA_SRU_BIBLIOS_PORT', $msg, $defaults->{'ZEBRA_SRU_BIBLIOS_PORT'}, $valid_values, $install_log_values);
1195 SRU port for authority data?);
1196 $config{'ZEBRA_SRU_AUTHORITIES_PORT'} = _get_value('ZEBRA_SRU_AUTHORITIES_PORT', $msg, $defaults->{'ZEBRA_SRU_AUTHORITIES_PORT'}, $valid_values, $install_log_values);
1201 Along with Zebra, you can also choose to install PazPar2,
1202 which is a metasearch tool. With PazPar2,
1203 Koha can perform on-the-fly merging of bibliographic
1204 records during searching, allowing for FRBRization of
1207 Install the PazPar2 configuration files?);
1208 $msg .= _add_valid_values_disp('INSTALL_PAZPAR2', $valid_values);
1209 $config{'INSTALL_PAZPAR2'} = _get_value('INSTALL_PAZPAR2', $msg, $defaults->{'INSTALL_PAZPAR2'}, $valid_values, $install_log_values);
1211 if ($config{'INSTALL_PAZPAR2'} eq 'yes') {
1213 Since you've chosen to configure PazPar2, you must
1214 specify the host and port(s) that PazPar2
1218 Zebra bibliographic server host?);
1219 $config{'MERGE_SERVER_HOST'} = _get_value('MERGE_SERVER_HOST', $msg, $defaults->{'MERGE_SERVER_HOST'}, $valid_values, $install_log_values);
1222 Zebra bibliographic port for PazPar2 to use?);
1223 $config{'MERGE_SERVER_PORT'} = _get_value('MERGE_SERVER_PORT', $msg, $defaults->{'MERGE_SERVER_PORT'}, $valid_values, $install_log_values);
1227 $config{'PAZPAR2_HOST'} = _get_value('PAZPAR2_HOST', $msg, $defaults->{'PAZPAR2_HOST'}, $valid_values, $install_log_values);
1231 $config{'PAZPAR2_PORT'} = _get_value('PAZPAR2_PORT', $msg, $defaults->{'PAZPAR2_PORT'}, $valid_values, $install_log_values);
1236 Use memcached to cache the results of some function calls?
1237 This provides a signficant performance improvement.
1238 You will need a Memcached server running.);
1239 $msg .= _add_valid_values_disp('USE_MEMCACHED', $valid_values);
1240 $config{'USE_MEMCACHED'} = _get_value('USE_MEMCACHED', $msg, $defaults->{'USE_MEMCACHED'}, $valid_values, $install_log_values);
1241 if ($config{'USE_MEMCACHED'} eq 'yes'){
1243 Since you've chosen to use caching, you must specify the memcached servers and the namespace to use:
1246 Memcached server address?);
1247 $config{'MEMCACHED_SERVERS'} = _get_value('MEMCACHED_SERVERS', $msg, $defaults->{'MEMCACHED_SERVERS'}, $valid_values, $install_log_values);
1250 Memcached namespace?);
1251 $config{'MEMCACHED_NAMESPACE'} = _get_value('MEMCACHED_NAMESPACE', $msg, $defaults->{'MEMCACHED_NAMESPACE'}, $valid_values, $install_log_values);
1255 Template cache directory?);
1256 $config{'TEMPLATE_CACHE_DIR'} = _get_value('TEMPLATE_CACHE_DIR', $msg, $defaults->{'TEMPLATE_CACHE_DIR'}, $valid_values, $install_log_values);
1259 Path to DejaVu fonts?);
1260 $config{'FONT_DIR'} = _get_value('FONT_DIR', $msg, $defaults->{'FONT_DIR'}, $valid_values, $install_log_values);
1264 Would you like to run the database-dependent test suite?);
1265 $msg .= _add_valid_values_disp( 'RUN_DATABASE_TESTS', $valid_values );
1266 $config{'RUN_DATABASE_TESTS'} = _get_value( 'RUN_DATABASE_TESTS', $msg, $defaults->{'RUN_DATABASE_TESTS'}, $valid_values, $install_log_values );
1268 if ( $config{'RUN_DATABASE_TESTS'} eq 'yes' ) {
1269 $config{'TEST_DB_TYPE'} = $config{'DB_TYPE'};
1270 $config{'TEST_DB_HOST'} = $config{'DB_HOST'};
1271 $msg = q(TEST DATABASE
1273 THE DATA IN THIS DATABASE WILL BE DESTROYED during the process of
1274 testing. Please don't do this on your production database. It is not
1277 YOU WILL SUFFER DATA LOSS if you run this test suite on your test
1278 database. You are better off not running this optional test suite than
1279 doing it in a database that you don't want to lose.
1281 Please specify the name of the test database to be
1284 $config{'TEST_DB_NAME'} = _get_value('TEST_DB_NAME', $msg, $defaults->{'TEST_DB_NAME'}, $valid_values, $install_log_values);
1285 while ( $config{'TEST_DB_NAME'} eq $config{'DB_NAME'} ) {
1286 $msg = q(Please do not use the same database for testing as you do for production. You run the severe risk of data loss.);
1287 $config{'TEST_DB_NAME'} = _get_value('TEST_DB_NAME', $msg, $defaults->{'TEST_DB_NAME'}, $valid_values, $install_log_values);
1291 Please specify the user that owns the database to be
1293 $config{'TEST_DB_USER'} = _get_value('TEST_DB_USER', $msg, $defaults->{'TEST_DB_USER'}, $valid_values, $install_log_values);
1296 Please specify the password of the user that owns the
1297 database to be used by Koha);
1298 $config{'TEST_DB_PASS'} = _get_value('TEST_DB_PASS', $msg, $defaults->{'TEST_DB_PASS'}, $valid_values, $install_log_values);
1303 # add version number
1304 my $version = "no_version_found";
1306 require 'kohaversion.pl';
1307 $version = kohaversion();
1309 $config{'KOHA_INSTALLED_VERSION'} = $version;
1314 sub _add_valid_values_disp {
1316 my $valid_values = shift;
1319 if (exists $valid_values->{$key}) {
1320 $disp = " (" . join(", ", sort keys %{ $valid_values->{$key} }) . ")";
1328 my $default = shift;
1329 my $valid_values = shift;
1330 my $install_log_values = shift;
1332 # take value from install log if present
1333 if (exists $install_log_values{$key}) {
1334 $install_log_values{$key} =~ s/\$/\$\$/g;
1335 return $install_log_values{$key};
1338 # override default value from environment
1339 if (exists $ENV{$key}) {
1340 $default = $ENV{$key};
1341 $msg .= " (default from environment)";
1344 my $val = prompt($msg, $default);
1346 while (exists $valid_values->{$key} and
1347 $val ne $default and
1348 not exists $valid_values->{$key}->{$val}) {
1349 my $retry_msg = "Value '$val' is not a valid option.\n";
1350 $retry_msg .= "Please enter a value";
1351 $retry_msg .= _add_valid_values_disp($key, $valid_values);
1352 $val = prompt($retry_msg, $default);
1354 $val =~ s/\$/\$\$/g;
1358 =head2 get_target_directories
1360 Creates a hash mapping from symbols for installation target
1361 directories to actual directory paths.
1363 Also returns a hash indicating targets for which
1364 files need not be copied -- this is used for the 'dev'
1365 mode installation, where some files are installed in place.
1369 sub get_target_directories {
1372 my $base = $config->{'INSTALL_BASE'};
1373 my $mode = $config->{'INSTALL_MODE'};
1375 # get last component of install base directory
1376 # to treat as package name
1377 my ($volume, $directories, $file) = File::Spec->splitpath($base, 1);
1379 my @basedir = File::Spec->splitdir($directories);
1381 if ( $^O eq 'cygwin' ) { shift @basedir; unshift @basedir, 'c:'; } # in a cygwin environment, $volume is returned empty
1383 my $package = pop @basedir;
1388 if ($mode eq 'single') {
1389 $dirmap{'API_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'api');
1390 $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
1391 $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs', 'intranet-tmpl');
1392 $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs');
1393 $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
1394 $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl');
1395 $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs');
1396 $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
1397 $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
1398 $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
1399 $dirmap{'PAZPAR2_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'pazpar2');
1400 $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
1401 $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
1402 $dirmap{'SCRIPT_NONDEV_DIR'} = $dirmap{'SCRIPT_DIR'};
1403 $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
1404 $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
1405 $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
1406 $dirmap{'LOG_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'log');
1407 $dirmap{'BACKUP_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'spool');
1408 $dirmap{'PLUGINS_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'koha', 'plugins');
1409 $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
1410 $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
1411 } elsif ($mode eq 'dev') {
1412 my $curdir = File::Spec->rel2abs(File::Spec->curdir());
1413 $dirmap{'API_CGI_DIR'} = File::Spec->catdir($curdir, 'api');
1414 $skipdirs{'API_CGI_DIR'} = 1;
1415 $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir($curdir);
1416 $skipdirs{'INTRANET_CGI_DIR'} = 1;
1417 $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'intranet-tmpl');
1418 $skipdirs{'INTRANET_TMPL_DIR'} = 1;
1419 $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl');
1420 $skipdirs{'INTRANET_WWW_DIR'} = 1;
1421 $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir($curdir);
1422 $skipdirs{'OPAC_CGI_DIR'} = 1;
1423 $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'opac-tmpl');
1424 $skipdirs{'OPAC_TMPL_DIR'} = 1;
1425 $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl');
1426 $skipdirs{'OPAC_WWW_DIR'} = 1;
1427 $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir($curdir);
1428 $skipdirs{'PERL_MODULE_DIR'} = 1;
1429 $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
1430 $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
1431 $dirmap{'PAZPAR2_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'pazpar2');
1432 $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
1433 $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
1434 #For dev install, point NONDEV_DIR to misc in current dir (not base)
1435 #Used by supportdir in koha-conf.xml (BZ 12031)
1436 $dirmap{'SCRIPT_NONDEV_DIR'} = File::Spec->catdir($curdir, 'misc');
1437 $skipdirs{'SCRIPT_NONDEV_DIR'} = 1;
1438 $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
1439 $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
1440 $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
1441 $dirmap{'LOG_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'log');
1442 $dirmap{'BACKUP_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'spool');
1443 $dirmap{'PLUGINS_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'plugins');
1444 $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
1445 $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
1447 # mode is standard, i.e., 'fhs'
1448 $dirmap{'API_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'api');
1449 $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
1450 $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs', 'intranet-tmpl');
1451 $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs');
1452 $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
1453 $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl');
1454 $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs');
1455 $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
1456 $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package);
1457 $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package, 'zebradb');
1458 $dirmap{'PAZPAR2_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package, 'pazpar2');
1459 $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
1460 $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
1461 $dirmap{'SCRIPT_NONDEV_DIR'} = $dirmap{'SCRIPT_DIR'};
1462 $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
1463 $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
1464 $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lock', $package, 'zebradb');
1465 $dirmap{'LOG_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'log', $package);
1466 $dirmap{'BACKUP_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'spool', $package);
1467 $dirmap{'PLUGINS_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'plugins');
1468 $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'zebradb');
1469 $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'run', $package, 'zebradb');
1472 _get_env_overrides(\%dirmap);
1473 _get_argv_overrides(\%dirmap);
1474 _add_destdir(\%dirmap);
1476 return \%dirmap, \%skipdirs;
1481 Map a directory target to the corresponding path for
1489 my @basedir = (File::Spec->rel2abs(File::Spec->curdir()), 't', 'run');
1490 if (exists $test_suite_override_dirs{$dirname}) {
1491 return File::Spec->catdir(@basedir, @{ $test_suite_override_dirs{$dirname} });
1498 sub _get_env_overrides {
1501 foreach my $key (keys %$dirmap) {
1502 if (exists $ENV{$key}) {
1503 $dirmap->{$key} = $ENV{$key};
1504 print "Setting $key from environment\n";
1509 sub _get_argv_overrides {
1513 for (my $i = 0; $i <= $#ARGV; $i++) {
1514 if ($ARGV[$i] =~ /^([^=]+)=([^=]+)$/ and exists $dirmap->{$1}) {
1517 push @new_argv, $ARGV[$i];
1523 sub _strip_destdir {
1525 $dir =~ s/^\$\(DESTDIR\)//;
1532 foreach my $key (keys %$dirmap) {
1533 $dirmap->{$key} = '$(DESTDIR)'.$dirmap->{$key};
1537 sub display_configuration {
1540 my @version = grep /\/usr\/share\/perl\//, @INC;
1541 push @version, ('/usr/share/perl/5.10') if !$version[0];
1542 print "\n\nKoha will be installed with the following configuration parameters:\n\n";
1543 foreach my $key (sort keys %$config) {
1544 print sprintf("%-25.25s%s\n", $key, $config->{$key});
1547 print "\nand in the following directories:\n\n";
1548 foreach my $key (sort keys %$dirmap) {
1549 print sprintf("%-25.25s%s\n", $key, $dirmap->{$key});
1551 print "\n\nTo change any configuration setting, please run\n";
1552 print "perl Makefile.PL again. To override one of the target\n";
1553 print "directories, you can do so on the command line like this:\n";
1554 print "\nperl Makefile.PL PERL_MODULE_DIR=$version[0]\n\n";
1555 print "You can also set different default values for parameters\n";
1556 print "or override directory locations by using environment variables.\n";
1557 print "\nFor example:\n\n";
1558 print "export DB_USER=my_koha\n";
1559 print "perl Makefile.PL\n";
1561 print "DB_USER=my_koha DOC_DIR=/usr/local/info perl Makefile.PL\n\n";
1566 Attempt to find Zebra - check user's PATH and
1567 a few other directories for zebrasrv and zebraidx.
1572 my @search_dirs = map {
1573 my $abs = File::Spec->rel2abs($_);
1574 my ($toss, $directories);
1575 ($toss, $directories, $toss) = File::Spec->splitpath($abs, 1);
1577 } split /:/, $ENV{PATH};
1578 push @search_dirs, qw(/usr/local/bin /opt/local/bin /usr/bin);
1579 my @zebrasrv_dirs = grep { -x File::Spec->catpath('', $_, 'zebrasrv') } @search_dirs;
1580 return unless @zebrasrv_dirs;
1581 # verify that directory that contains zebrasrv also contains zebraidx
1582 foreach my $dir (@zebrasrv_dirs) {
1583 return $dir if -x File::Spec->catpath('', $dir, 'zebraidx');
1592 my $test = $self->SUPER::test(@_);
1593 $test =~ s!\$\(INST_LIB\)!blib/PERL_MODULE_DIR!g;
1596 $test =~ s!\$\(FULLPERLRUN\)!KOHA_CONF=blib/KOHA_CONF_DIR/koha-conf.xml \$(FULLPERLRUN)!g;
1603 # NOTE: we're *not* doing this: my $install = $self->SUPER::install(@_);
1604 # This means that we're completely overriding EU::MM's default
1605 # installation and uninstallation targets.
1607 # If installation is on Win32, we need to do permissions different from *nix
1608 if ( $^O =~ /darwin|linux|cygwin|freebsd|solaris/ ) { # this value needs to be verified for each platform and modified accordingly
1609 foreach my $key (sort keys %$target_directories) {
1611 KOHA_INST_$key = blib/$key
1612 KOHA_DEST_$key = $target_directories->{$key}
1613 ) unless exists $skip_directories->{$key};
1616 install :: all install_koha set_koha_ownership set_koha_permissions warn_koha_env_vars
1617 \t\$(NOECHO) \$(NOOP)
1619 $install .= "install_koha ::\n";
1620 $install .= "\t\$(NOECHO) umask 022; \$(MOD_INSTALL) \\\n";
1621 foreach my $key (sort keys %$target_directories) {
1622 $install .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
1623 unless exists $skip_directories->{$key};
1625 $install .= "\t\t\$(INST_MAN1DIR) \$(DESTINSTALLMAN1DIR) \\\n";
1626 $install .= "\t\t\$(INST_MAN3DIR) \$(DESTINSTALLMAN3DIR)\n";
1629 $install .= "set_koha_ownership ::\n";
1630 # Do not try to change ownership if DESTDIR is set
1631 if ($config{'INSTALL_MODE'} eq 'standard' and $config{'KOHA_USER'} ne "root") {
1632 foreach my $key (sort keys %$target_directories) {
1633 $install .= "\t\$(NOECHO) if test -z \"\$(DESTDIR)\"; then chown -R $config{'KOHA_USER'}:$config{'KOHA_GROUP'} \$(KOHA_DEST_$key); fi\n"
1634 unless exists $skip_directories->{$key};
1637 $install .= "\t\t\$(NOECHO) \$(NOOP)\n\n";
1641 $install .= "set_koha_permissions ::\n";
1642 # This is necessary because EU::MM installs files
1643 # as either 0444 or 0555, and we want the owner
1644 # of Koha's files to have write permission by default.
1645 foreach my $key (sort keys %$target_directories) {
1646 $install .= "\t\$(NOECHO) chmod -R u+w \$(KOHA_DEST_$key)\n"
1647 unless exists $skip_directories->{$key};
1653 $install .= "warn_koha_env_vars ::\n";
1654 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1655 $install .= "\t\$(NOECHO) \$(ECHO) Koha\\'s files have now been installed. \n";
1656 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1657 $install .= "\t\$(NOECHO) \$(ECHO) In order to use Koha\\'s command-line batch jobs,\n";
1658 $install .= "\t\$(NOECHO) \$(ECHO) you should set the following environment variables:\n";
1659 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1660 $install .= "\t\$(NOECHO) \$(ECHO) export KOHA_CONF=\$(KOHA_DEST_KOHA_CONF_DIR)/koha-conf.xml\n";
1661 $install .= "\t\$(NOECHO) \$(ECHO) export PERL5LIB=$target_directories->{'PERL_MODULE_DIR'}\n";
1662 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1663 $install .= "\t\$(NOECHO) \$(ECHO) For other post-installation tasks, please consult the README.\n";
1664 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1666 $install .= _update_zebra_conf_target();
1668 $install .= upgrade();
1673 =head2 _update_zebra_conf_target
1675 Add an installation target for updating
1676 Zebra's configuration files.
1680 sub _update_zebra_conf_target {
1682 my $target = "\nupdate_zebra_conf ::\n";
1683 $target .= "\tumask 022; \$(MOD_INSTALL) \\\n";
1684 $target .= "\t\t\$(KOHA_INST_ZEBRA_CONF_DIR) \$(KOHA_DEST_ZEBRA_CONF_DIR) \n";
1685 $target .= "\t\$(NOECHO) chmod -R u+w \$(KOHA_DEST_ZEBRA_CONF_DIR)\n";
1686 $target .= "\tumask 022; \$(MOD_INSTALL) \\\n";
1687 $target .= "\t\t\$(KOHA_INST_PAZPAR2_CONF_DIR) \$(KOHA_DEST_PAZPAR2_CONF_DIR) \n";
1688 $target .= "\t\$(NOECHO) chmod -R u+w \$(KOHA_DEST_PAZPAR2_CONF_DIR)\n";
1697 if (exists $install_log_values{'KOHA_INSTALLED_VERSION'}) {
1698 my $version = $install_log_values{'KOHA_INSTALLED_VERSION'};
1699 $version =~ s/\./_/g;
1700 $backup_suffix = "_koha_$version";
1702 $backup_suffix = "_upgrade_backup";
1706 MOD_BACKUP = \$(ABSPERLRUN) -MC4::Installer::UpgradeBackup -e 'backup_changed_files({\@ARGV}, '$backup_suffix', '\''\$(VERBINST)'\'', '\''\$(UNINST)'\'');' --
1708 upgrade :: make_upgrade_backup install
1709 \t\$(NOECHO) \$(NOOP)
1710 make_upgrade_backup ::
1711 \t\$(NOECHO) umask 022; \$(MOD_BACKUP) \\
1713 foreach my $key (qw/KOHA_CONF_DIR INTRANET_TMPL_DIR INTRANET_WWW_DIR OPAC_TMPL_DIR OPAC_WWW_DIR
1714 PAZPAR2_CONF_DIR ZEBRA_CONF_DIR PLUGINS_DIR/) {
1715 $upgrade .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
1716 unless exists $skip_directories->{$key} or
1717 not exists $target_directories->{$key};
1719 $upgrade =~ s/\\\n$/\n/;
1724 # put directory mappings into Makefile
1725 # so that Make will export as environment
1726 # variables -- this is for the use of
1730 # Hereagain, we must alter syntax per platform...
1732 $env = join("\n", map { "export __${_}__ := $target_directories->{$_}" } keys %$target_directories);
1734 $env .= join("\n", map { "export __${_}__ := $config{$_}" } keys %config);
1746 ExtUtils::MakeMaker(3)
1750 MJ Ray mjr at phonecoop.coop
1751 Galen Charlton galen.charlton at liblime.com
1755 FIXME: deal with .htaccess