Bug 19080: Handle non-existing patrons gratefully
[koha.git] / Makefile.PL
1 # Copyright 2007 MJ Ray
2 # Copyright 2016 PTFS Europe
3 #
4 # This file is part of Koha.
5 #
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.
10 #
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.
15 #
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>.
18 #
19 # Current maintainer MJR http://mjr.towers.org.uk/
20 #
21
22 use strict;
23 use warnings;
24 use ExtUtils::MakeMaker;
25 use POSIX;
26 use File::Spec;
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
29
30 use lib $FindBin::Bin;
31
32 use C4::Installer;
33
34 my $koha_pm = C4::Installer::PerlModules->new;
35
36 my $DEBUG = 0;
37 die "perl 5.10 or later required" unless ($] >= 5.010000);
38
39 # Hash up directory structure & files beginning with the directory we were called from (should be the base of koha)...
40
41 my $dirtree = hashdir('.');
42 my %result = ();
43
44 =head1 NAME
45
46 Makefile.PL - Koha packager and installer
47
48 =head1 SYNOPSIS
49
50 =head2 BASIC INSTALLATION
51
52     perl Makefile.PL
53     make
54     make test
55     sudo make install
56
57 =head2 UPGRADE INSTALLATION
58
59     NOTE: This option is only available if koha-install-log exists.
60
61     perl Makefile.PL --prev-install-log /path/to/koha-install-log
62
63     make
64     make test
65     sudo make upgrade
66
67 =head2 PACKAGING RELEASE TARBALLS
68
69     make manifest tardist
70     make manifest zipdist
71
72 =head2 CLEANING UP
73
74         make clean
75
76 =head2 CLI PARAMETERS
77
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     --help                       Display this help message
105
106 =head1 DESCRIPTION
107
108 This is a packager and installer that uses
109 ExtUtils::MakeMaker, which is fairly common
110 on perl systems.
111 As well as building tar or zip files
112 and installing with the above commands,
113 it allows us to check pre-requisites
114 and generate configuration files.
115
116 =head1 VARIABLES
117
118 =head2 NAME, VERSION_FROM, ABSTRACT, AUTHOR
119
120 Basic metadata about this software.
121
122 =head2 NO_META
123
124 Suppress generation of META.yml file.
125
126 =head2 PREREQ_PM
127
128 Hash of perl modules and versions required.
129
130 =head2 PM
131
132 Hash of file mappings
133
134 =head2 PL_FILES
135
136 This is a hash of PL scripts to run after installation and
137 the files to ask them to generate.
138 Maybe use the values from CONFIGURE
139 to generate initial configuration files in future.
140
141 =cut
142
143 =head2 target_map
144
145 This is a hash mapping directories and files in the
146 source tree to installation target directories.  The rules
147 for this mapping are:
148
149 =over 4
150
151 =item If a directory or file is specified, it and its
152 contents will be copied to the installation target directory.
153
154 =item If a subdirectory of a mapped directory is specified,
155 its target overrides the parent's target for that subdirectory.
156
157 =item The value of each map entry may either be a scalar containing
158 one target or a reference to a hash containing 'target' and 'trimdir'
159 keys.
160
161 =item Any files at the top level of the source tree that are
162 not included in the map will not be installed.
163
164 =item Any directories at the top level of the source tree
165 that are not included in the map will be installed in
166 INTRANET_CGI_DIR.  This is a sensible default given the
167 current organization of the source tree, but (FIXME) it
168 would be better to reorganize the source tree to better
169 match the installation system, to allow adding new directories
170 without having to adjust Makefile.PL each time.  The idea
171 is to make the C<$target_map> hash as minimal as possible.
172
173 =back
174
175 The permitted installation targets are:
176
177 =over 4
178
179 =item INTRANET_CGI_DIR
180
181 CGI scripts for intranet (staff) interface.
182
183 =item INTRANET_TMPL_DIR
184
185 HTML templates for the intranet interface.
186
187 =item INTRANET_WWW_DIR
188
189 HTML files, images, etc. for DocumentRoot for the intranet interface.
190
191 =item OPAC_CGI_DIR
192
193 CGI scripts for OPAC (public) interface.
194
195 =item OPAC_TMPL_DIR
196
197 HTML templates for the OPAC interface.
198
199 =item OPAC_WWW_DIR
200
201 HTML files, images, etc. for DocumentRoot for the OPAC interface.
202
203 =item PERL_MODULE_DIR
204
205 Perl modules (at present just the C4 modules) that are intimately
206 tied to Koha.  Depending on the installation options, these
207 may or may not be installed one of the standard directories
208 in Perl's default @LIB.
209
210 =item KOHA_CONF_DIR
211
212 Directory for Koha configuration files.
213
214 =item ZEBRA_CONF_DIR
215
216 Directory for Zebra configuration files.
217
218 =item ZEBRA_LOCK_DIR
219
220 Directory for Zebra's lock files.  This includes subdirs for authorities,
221 biblios, and the zebra rebuild function.  Any activity to reindex
222 zebra from koha should interlock here with rebuild_zebra.pl.
223
224 =item ZEBRA_DATA_DIR
225
226 Directory for Zebra's data files.
227
228 =item ZEBRA_RUN_DIR
229
230 Directory for Zebra's UNIX-domain sockets.
231
232 =item MISC_DIR
233
234 Directory for for miscellaenous scripts, among other
235 things the translation toolkit and RSS feed tools.
236
237 =item SCRIPT_DIR
238
239 Directory for command-line scripts and daemons to
240 be set up all for installation modes.
241
242 =item SCRIPT_NONDEV_DIR
243
244 Directory for command-line scripts that should
245 be installed in the same directory as the
246 SCRIPT_DIR target except 'dev' installs.
247
248 =item MAN_DIR
249
250 Directory for man pages created from POD -- will mostly
251 contain information of interest to Koha developers.
252
253 =item DOC_DIR
254
255 Directory for Koha documentation accessed from the
256 command-line, e.g., READMEs.
257
258 =item LOG_DIR
259
260 Directory for Apache and Zebra logs produced by Koha.
261
262 =item BACKUP_DIR
263
264 Directory for backup files produced by Koha.
265
266 =item PLUGINS_DIR
267
268 Directory for external Koha plugins.
269
270 =item PAZPAR2_CONF_DIR
271
272 Directory for PazPar2 configuration files.
273
274 =item FONT_DIR
275
276 Directory where DejaVu fonts are installed.
277
278 =item NONE
279
280 This is a dummy target used to explicitly state
281 that a given file or directory is not to be installed.
282 This is used either for parts of the installer itself
283 or for development tools that are not applicable to a
284 production installation.
285
286 =back
287
288 =cut
289
290 my $target_map = {
291   './about.pl'                  => 'INTRANET_CGI_DIR',
292   './acqui'                     => 'INTRANET_CGI_DIR',
293   './admin'                     => 'INTRANET_CGI_DIR',
294   './api'                       => { target => 'API_CGI_DIR', trimdir => -1 },
295   './authorities'               => 'INTRANET_CGI_DIR',
296   './basket'                    => 'INTRANET_CGI_DIR',
297   './C4'                        => 'PERL_MODULE_DIR',
298   './C4/SIP/t'                  => 'NONE',
299   './C4/SIP/koha_test'          => 'NONE',
300   './C4/tests'                  => 'NONE',
301   './catalogue'                 => 'INTRANET_CGI_DIR',
302   './cataloguing'               => 'INTRANET_CGI_DIR',
303   './changelanguage.pl'         => 'INTRANET_CGI_DIR',
304   './check_sysprefs.pl'         => 'NONE',
305   './circ'                      => 'INTRANET_CGI_DIR',
306   './clubs'                     => 'INTRANET_CGI_DIR',
307   './course_reserves'           => 'INTRANET_CGI_DIR',
308   './docs/history.txt'          => { target => 'DOC_DIR', trimdir => -1 },
309   './offline_circ'              => 'INTRANET_CGI_DIR',
310   './edithelp.pl'               => 'INTRANET_CGI_DIR',
311   './etc'                       => { target => 'KOHA_CONF_DIR', trimdir => -1 },
312   './etc/zebradb'               => { target => 'ZEBRA_CONF_DIR', trimdir => -1 },
313   './etc/pazpar2'               => { target => 'PAZPAR2_CONF_DIR', trimdir => -1 },
314   './help.pl'                   => 'INTRANET_CGI_DIR',
315   './installer-CPAN.pl'         => 'NONE',
316   './installer'                 => 'INTRANET_CGI_DIR',
317   './errors'                    => {target => 'INTRANET_CGI_DIR'},
318   './Koha'                      => 'PERL_MODULE_DIR',
319   './Koha.pm'                   => 'PERL_MODULE_DIR',
320   './koha-tmpl/intranet-tmpl'   => {target => 'INTRANET_TMPL_DIR', trimdir => -1},
321   './koha-tmpl/opac-tmpl'       => {target => 'OPAC_TMPL_DIR', trimdir => -1},
322   './kohaversion.pl'            => 'INTRANET_CGI_DIR',
323   './labels'                    => 'INTRANET_CGI_DIR',
324   './mainpage.pl'               => 'INTRANET_CGI_DIR',
325   './Makefile.PL'               => 'NONE',
326   './MANIFEST.SKIP'             => 'NONE',
327   './members'                   => 'INTRANET_CGI_DIR',
328   './misc'                      => { target => 'SCRIPT_NONDEV_DIR', trimdir => -1 },
329   './misc/bin'                  => { target => 'SCRIPT_DIR', trimdir => -1 },
330   './misc/release_notes'        => { target => 'DOC_DIR', trimdir => 2 },
331   './misc/translator'           => { target => 'MISC_DIR', trimdir => 2 },
332   './misc/koha-install-log'     => { target => 'MISC_DIR', trimdir => -1 },
333   './misc/installer_devel_notes' => 'NONE',
334   './opac'                      => 'OPAC_CGI_DIR',
335   './OpenILS'                   => 'PERL_MODULE_DIR',
336   './README.txt'                => 'NONE',
337   './patroncards'               => 'INTRANET_CGI_DIR',
338   './patron_lists'              => 'INTRANET_CGI_DIR',
339   './plugins'                   => 'INTRANET_CGI_DIR',
340   './reports'                   => 'INTRANET_CGI_DIR',
341   './reserve'                   => 'INTRANET_CGI_DIR',
342   './reviews'                   => 'INTRANET_CGI_DIR',
343   './rewrite-config.PL'         => 'NONE',
344   './reviews'                   => 'INTRANET_CGI_DIR',
345   './rotating_collections'      => 'INTRANET_CGI_DIR',
346   './serials'                   => 'INTRANET_CGI_DIR',
347   './services'                  => 'INTRANET_CGI_DIR',
348   './skel'                      => 'NONE',
349   './skel/var/log/koha'         => { target => 'LOG_DIR', trimdir => -1 },
350   './skel/var/spool/koha'       => { target => 'BACKUP_DIR', trimdir => -1 },
351   './skel/var/run/koha/zebradb' => { target => 'ZEBRA_RUN_DIR', trimdir => -1 },
352   './skel/var/lock/koha/zebradb/authorities' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
353   './skel/var/lib/koha/zebradb/authorities/key'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
354   './skel/var/lib/koha/zebradb/authorities/register'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
355   './skel/var/lib/koha/zebradb/authorities/shadow'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
356   './skel/var/lib/koha/zebradb/authorities/tmp'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
357   './skel/var/lock/koha/zebradb/biblios' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
358   './skel/var/lib/koha/zebradb/biblios/key'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
359   './skel/var/lib/koha/zebradb/biblios/register'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
360   './skel/var/lib/koha/zebradb/biblios/shadow'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
361   './skel/var/lib/koha/zebradb/biblios/tmp'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
362   './skel/var/lock/koha/zebradb/rebuild' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
363   './skel/var/lib/koha/plugins' => { target => 'PLUGINS_DIR', trimdir => 6 },
364   './sms'                       => 'INTRANET_CGI_DIR',
365   './suggestion'                => 'INTRANET_CGI_DIR',
366   './svc'                       => 'INTRANET_CGI_DIR',
367   './t'                         => 'NONE',
368   './tags'                      => 'INTRANET_CGI_DIR',
369   './tmp'                       => 'NONE', # FIXME need to determine whether
370                                            # Koha generates any persistent temp files
371                                            # that should go in /var/tmp/koha
372   './tools'                     => 'INTRANET_CGI_DIR',
373   './virtualshelves'            => 'INTRANET_CGI_DIR',
374   './xml_sax.pl'                => 'PERL_MODULE_DIR',
375   # ignore files and directories created by the install itself
376   './pm_to_blib'                => 'NONE',
377   './blib'                      => 'NONE',
378 };
379
380 =head1 CONFIGURATION OPTIONS
381
382 The following configuration options are used by the installer.
383
384 =over 4
385
386 =item INSTALL_MODE
387
388 Specifies whether installation will be FHS-compliant (default,
389 assumes user has root), put everything under
390 a single directory (for users installing on a web host
391 that allows CGI scripts and a MySQL database but not root
392 access), or development (for a developer who wants to run
393 Koha from a git clone with no fuss).
394
395 =item INSTALL_BASE
396
397 Directory under which most components will go.  Default
398 value will vary depending on INSTALL_MODE.
399
400 =item DB_TYPE
401
402 Type of DBMS (e.g., mysql or Pg).
403
404 =item DB_HOST
405
406 Name of DBMS server.
407
408 =item DB_PORT
409
410 Port that DBMS server is listening on.
411
412 =item DB_NAME
413
414 Name of the DBMS database for Koha.
415
416 =item DB_USER
417
418 Name of DBMS user account for Koha's database.
419
420 =item DB_PASS
421
422 Pasword of DMBS user account for Koha's database.
423
424 =item ZEBRA_MARC_FORMAT
425
426 Specifies format of MARC records to be indexed by Zebra.
427
428 =item ZEBRA_LANGUAGE
429
430 Specifies primary language of records that will be
431 indexed by Zebra.
432
433 =item ZEBRA_USER
434
435 Internal Zebra user account for the index.
436
437 =item ZEBRA_PASS
438
439 Internal Zebra user account's password.
440
441 =item KOHA_USER
442
443 System user account that will own Koha's files.
444
445 =item KOHA_GROUP
446
447 System group that will own Koha's files.
448
449 =back
450
451 =cut
452
453 # default configuration options
454 my %config_defaults = (
455   'DB_TYPE'           => 'mysql',
456   'DB_HOST'           => 'localhost',
457   'DB_NAME'           => 'koha',
458   'DB_USER'           => 'kohaadmin',
459   'DB_PASS'           => 'katikoan',
460   'DB_USE_TLS'        => 'no',
461   'DB_TLS_CA_CERTIFICATE'  => '/etc/mysql-ssl/server-ca.pem',
462   'DB_TLS_CLIENT_CERTIFICATE'  => '/etc/mysql-ssl/client-cert.pem',
463   'DB_TLS_CLIENT_KEY' => '/etc/mysql-ssl/client-key.pem',
464   'INSTALL_SRU'       => 'yes',
465   'INSTALL_PAZPAR2'   => 'no',
466   'AUTH_INDEX_MODE'   => 'dom',
467   'BIB_INDEX_MODE'    => 'dom',
468   'ZEBRA_MARC_FORMAT' => 'marc21',
469   'ZEBRA_LANGUAGE'    => 'en',
470   'ZEBRA_TOKENIZER'   => 'chr',
471   'ZEBRA_USER'        => 'kohauser',
472   'ZEBRA_PASS'        => 'zebrastripes',
473   'ZEBRA_SRU_HOST'    => 'localhost',
474   'ZEBRA_SRU_BIBLIOS_PORT'    => '9998',
475   'ZEBRA_SRU_AUTHORITIES_PORT'    => '9999',
476   'KOHA_USER'         => 'koha',
477   'KOHA_GROUP'        => 'koha',
478   'MERGE_SERVER_HOST' => 'localhost',
479   'MERGE_SERVER_PORT' => '11001',
480   'PAZPAR2_HOST' => 'localhost',
481   'PAZPAR2_PORT' => '11002',
482   'RUN_DATABASE_TESTS' => 'no',
483   'PATH_TO_ZEBRA' => '',
484   'USE_MEMCACHED'     => 'no',
485   'MEMCACHED_SERVERS' => '127.0.0.1:11211',
486   'MEMCACHED_NAMESPACE' => 'KOHA',
487   'FONT_DIR'          => '/usr/share/fonts/truetype/ttf-dejavu'
488 );
489
490 # set some default configuration options based on OS
491 # more conditions need to be added for other OS's
492
493 warn "Your platform appears to be $^O.\n" if $DEBUG;
494
495 if ( $^O eq 'cygwin' ) {
496         # Most Unix2Win32 ports seem to poke everything into the Program Files directory
497         # this could be changed to put some files (ie. libraries) into system32, etc.
498         $config_defaults{'INSTALL_MODE'} = 'single';
499         $config_defaults{'INSTALL_BASE'} = 'c:/progra~1/koha';  # Use 8.3 names to be safe...
500 }
501 else {
502         $config_defaults{'INSTALL_MODE'} = 'standard';
503         $config_defaults{'INSTALL_BASE'} = '/usr/share/koha';
504 }
505
506 # valid values for certain configuration options
507 my %valid_config_values = (
508   'INSTALL_MODE'  => { 'standard' => 1, 'single' => 1, 'dev' => 1 },
509   'DB_TYPE' => { 'mysql' => 1, 'Pg' => 1 },
510   'DB_USE_TLS' => {'yes', 'no'},
511   'INSTALL_SRU' => { 'yes' => 1, 'no' => 1 },
512   'AUTH_INDEX_MODE' => { 'grs1' => 1, 'dom' => 1 },
513   'BIB_INDEX_MODE'  => { 'grs1' => 1, 'dom' => 1 },
514   'ZEBRA_MARC_FORMAT' => { 'marc21' => 1, 'normarc' => 1, 'unimarc' => 1 }, # FIXME should generate from contents of distributation
515   '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
516   'ZEBRA_TOKENIZER' => { chr => 1, icu => 1 },
517   'RUN_DATABASE_TESTS' => { 'yes' => 1, 'no' => 1 },
518   'USE_MEMCACHED'      => { 'yes' => 1, 'no' => 1 },
519 );
520
521 # get settings from command-line
522 my $koha_install_log = "";
523 my $cli_koha_install_mode = "";
524 my $cli_koha_db_type = "";
525 my $cli_koha_db_host = "";
526 my $cli_koha_db_port = "";
527 my $cli_koha_db_name = "";
528 my $cli_koha_db_user = "";
529 my $cli_koha_db_pass = "";
530 my $cli_zebra_marc_format = "";
531 my $cli_zebra_language = "",
532 my $cli_zebra_tokenizer = "";
533 my $cli_zebra_user = "";
534 my $cli_zebra_pass = "";
535 my $cli_zebra_sru_host = "";
536 my $cli_zebra_sru_bib_port = "";
537 my $cli_zebra_sru_auth_port = "";
538 my $cli_koha_auth_index_mode = "";
539 my $cli_koha_bib_index_mode = "";
540 my $cli_koha_user = "";
541 my $cli_koha_group = "";
542 my $cli_koha_install_sru = "";
543 my $cli_koha_install_pazpar2 = "";
544 my $cli_koha_use_memcached = "";
545 my $cli_koha_font_dir = "";
546 my $cli_koha_run_database_tests = "";
547 my $cli_koha_install_base = "";
548 Getopt::Long::Configure('pass_through');
549 my $results = GetOptions(
550     "prev-install-log=s"           => \$koha_install_log,
551     "install_mode=s"               => \$cli_koha_install_mode,
552     "db_type=s"                    => \$cli_koha_db_type,
553     "db_host=s"                    => \$cli_koha_db_host,
554     "db_port=s"                    => \$cli_koha_db_port,
555     "db_name=s"                    => \$cli_koha_db_name,
556     "db_user=s"                    => \$cli_koha_db_user,
557     "db_pass=s"                    => \$cli_koha_db_pass,
558     "zebra_marc_format=s"          => \$cli_zebra_marc_format,
559     "zebra_language=s"             => \$cli_zebra_language,
560     "zebra_tokenizer=s"            => \$cli_zebra_tokenizer,
561     "zebra_user=s"                 => \$cli_zebra_user,
562     "zebra_pass=s"                 => \$cli_zebra_pass,
563     "zebra_sru_host=s"             => \$cli_zebra_sru_host,
564     "zebra_sru_biblios_port=s"     => \$cli_zebra_sru_bib_port,
565     "zebra_sru_authorities_port=s" => \$cli_zebra_sru_auth_port,
566     "auth_index_mode=s"            => \$cli_koha_auth_index_mode,
567     "bib_index_mode=s"             => \$cli_koha_bib_index_mode,
568     "koha_user=s"                  => \$cli_koha_user,
569     "koha_group=s"                 => \$cli_koha_group,
570     "install_sru=s"                => \$cli_koha_install_sru,
571     "install_pazpar2=s"            => \$cli_koha_install_pazpar2,
572     "use_memcached=s"              => \$cli_koha_use_memcached,
573     "font_dir=s"                   => \$cli_koha_font_dir,
574     "run_database_tests=s"         => \$cli_koha_run_database_tests,
575     "install_base=s"               => \$cli_koha_install_base,
576     "help"                         => sub { HelpMessage(0) },
577 ) or HelpMessage(1);
578
579 my %install_log_values = ();
580 if ($koha_install_log ne "") {
581     get_install_log_values($koha_install_log, \%install_log_values);
582 } else {
583     # Try to set install_log_values for provided values;
584     get_cli_values(\%install_log_values);
585 }
586
587 my %config = get_configuration(\%config_defaults, \%valid_config_values, \%install_log_values);
588 my ($target_directories, $skip_directories) = get_target_directories(\%config);
589 display_configuration(\%config, $target_directories);
590 my $file_map = {};
591 get_file_map($target_map, $dirtree, $file_map);
592
593 my $pl_files = {
594       'rewrite-config.PL' => [
595          'blib/KOHA_CONF_DIR/koha-conf.xml',
596          'blib/KOHA_CONF_DIR/koha-httpd.conf',
597          'blib/KOHA_CONF_DIR/log4perl.conf',
598          'blib/ZEBRA_CONF_DIR/etc/default.idx',
599          'blib/MISC_DIR/koha-install-log'
600          ],
601           'fix-perl-path.PL' => [       # this script ensures the correct shebang line for the platform installed on...
602                  'blib'
603                  ],
604 };
605
606 push @{ $pl_files->{'rewrite-config.PL'} }, (
607     'blib/ZEBRA_CONF_DIR/etc/passwd',
608     'blib/ZEBRA_CONF_DIR/zebra-biblios.cfg',
609     'blib/ZEBRA_CONF_DIR/zebra-biblios-dom.cfg',
610     'blib/ZEBRA_CONF_DIR/zebra-authorities.cfg',
611     'blib/ZEBRA_CONF_DIR/zebra-authorities-dom.cfg',
612     'blib/ZEBRA_CONF_DIR/explain-authorities.xml',
613     'blib/ZEBRA_CONF_DIR/explain-biblios.xml',
614     'blib/ZEBRA_CONF_DIR/retrieval-info-auth-grs1.xml',
615     'blib/ZEBRA_CONF_DIR/retrieval-info-auth-dom.xml',
616     'blib/ZEBRA_CONF_DIR/retrieval-info-bib-grs1.xml',
617     'blib/ZEBRA_CONF_DIR/retrieval-info-bib-dom.xml',
618 );
619 push @{ $pl_files->{'rewrite-config.PL'} }, (
620     'blib/SCRIPT_DIR/koha-zebra-ctl.sh',
621     'blib/SCRIPT_DIR/koha-pazpar2-ctl.sh',
622     'blib/SCRIPT_DIR/koha-index-daemon-ctl.sh',
623 );
624 if ($config{'INSTALL_PAZPAR2'} eq 'yes') {
625     push @{ $pl_files->{'rewrite-config.PL'} }, (
626         'blib/PAZPAR2_CONF_DIR/koha-biblios.xml',
627         'blib/PAZPAR2_CONF_DIR/pazpar2.xml'
628     );
629 }
630 $config{'ZEBRA_AUTH_CFG'} = $config{'AUTH_INDEX_MODE'} eq 'dom'
631                               ? 'zebra-authorities-dom.cfg'
632                               : 'zebra-authorities.cfg';
633 $config{'ZEBRA_BIB_CFG'}  = $config{'BIB_INDEX_MODE'} eq 'dom'
634                               ? 'zebra-biblios-dom.cfg'
635                               : 'zebra-biblios.cfg';
636 $config{'AUTH_RETRIEVAL_CFG'} = $config{'AUTH_INDEX_MODE'} eq 'dom'
637                                   ? 'retrieval-info-auth-dom.xml'
638                                   : 'retrieval-info-auth-grs1.xml';
639 $config{'BIB_RETRIEVAL_CFG'}  = $config{'BIB_INDEX_MODE'} eq 'dom'
640                                   ? 'retrieval-info-bib-dom.xml'
641                                   : 'retrieval-info-bib-grs1.xml';
642
643
644 if ($config{'INSTALL_MODE'} ne "dev") {
645     push @{ $pl_files->{'rewrite-config.PL'} }, (
646         'blib/PERL_MODULE_DIR/C4/Context.pm',
647         'blib/SCRIPT_NONDEV_DIR/kohalib.pl'
648     );
649 }
650
651 $config{ZEBRA_TOKENIZER_STMT} = $config{ZEBRA_TOKENIZER} eq 'icu'
652     ? 'icuchain words-icu.xml'
653     : 'charmap word-phrase-utf.chr';
654
655 $config{ZEBRA_PTOKENIZER_STMT} = $config{ZEBRA_TOKENIZER} eq 'icu'
656     ? 'icuchain phrases-icu.xml'
657     : 'charmap word-phrase-utf.chr';
658
659 my %test_suite_override_dirs = (
660     KOHA_CONF_DIR  => ['etc'],
661     ZEBRA_CONF_DIR => ['etc', 'zebradb'],
662     LOG_DIR        => ['var', 'log'],
663     BACKUP_DIR     => ['var', 'spool'],
664     SCRIPT_DIR     => ['bin'],
665     ZEBRA_LOCK_DIR => ['var', 'lock', 'zebradb'],
666     ZEBRA_DATA_DIR => ['var', 'lib', 'zebradb'],
667     ZEBRA_RUN_DIR  => ['var', 'run', 'zebradb'],
668 );
669
670 WriteMakefile(
671               NAME         => 'koha',
672               #VERSION     => strftime('2.9.%Y%m%d%H',gmtime),
673               VERSION_FROM => 'kohaversion.pl',
674               ABSTRACT     => 'Award-winning integrated library system (ILS) and Web OPAC',
675               AUTHOR       => 'Koha Contributors <http://koha-community.org/>',
676               NO_META      => 1,
677               PREREQ_PM    => $koha_pm->prereq_pm,
678
679               # File tree mapping
680               PM => $file_map,
681
682               # Man pages generated from POD
683               # ExtUtils::MakeMaker already manage $(DESTDIR)
684               INSTALLMAN1DIR => File::Spec->catdir(_strip_destdir($target_directories->{'MAN_DIR'}), 'man1'),
685               INSTALLMAN3DIR => File::Spec->catdir(_strip_destdir($target_directories->{'MAN_DIR'}), 'man3'),
686
687               PL_FILES => $pl_files,
688 );
689
690 =head1 FUNCTIONS
691
692 =head2 hashdir
693
694 This function recurses through the directory structure and builds
695 a hash of hashes containing the structure with arrays holding filenames.
696 This directory hashing routine was taken from BrowserUK @ http://www.perlmonks.org/?node_id=219919
697
698 =cut
699
700 sub hashdir{
701     my $dir = shift;
702     opendir my $dh, $dir or die $!;
703     my $tree = {}->{$dir} = {};
704     while( my $file = readdir($dh) ) {
705         next if $file =~ m/^\.{1,2}/ and $file !~ /^\.htaccess/; # .htaccess is a special case
706         my $path = $dir .'/' . $file;
707         $tree->{$file} = hashdir($path), next if -d $path;
708         push @{$tree->{'.'}}, $file;
709     }
710     return $tree;
711 }
712
713 =head2 get_file_map
714
715 This function combines the target_map and file hash to
716 map each source file to its destination relative to
717 the set of installation targets.
718
719 Output will be a hash mapping from each source file
720 to its destination value, like this:
721
722 'mainpage.pl' => '$(INTRANET_CGI_DIR)/mainpage.pl'
723
724 =cut
725
726 sub get_file_map {
727     my $target_map = shift;
728     my $dirtree = shift;
729     my $file_map = shift;
730     my $curr_path = @_ ? shift : ['.'];
731
732     # Traverse the directory tree.
733     # For each file or directory, identify the
734     # most specific match in the target_map
735     foreach my $dir (sort keys %{ $dirtree }) {
736         if ($dir eq '.') {
737             # deal with files in directory
738             foreach my $file (sort @{ $dirtree->{$dir} }) {
739                 my $targetdir = undef;
740                 my $matchlevel = undef;
741                 # first, see if there is a match on this specific
742                 # file in the target map
743                 my $filepath = join("/", @$curr_path, $file);
744                 if (exists $target_map->{$filepath}) {
745                     $targetdir = $target_map->{$filepath};
746                     $matchlevel = scalar(@$curr_path) + 1;
747                 } else {
748                     # no match on the specific file; look for
749                     # a directory match
750                     for (my $i = scalar(@$curr_path) - 1; $i >= 0; $i--)  {
751                         my $dirpath = join("/", @$curr_path[0..$i]);
752                         if (exists $target_map->{$dirpath}) {
753                             $targetdir = $target_map->{$dirpath};
754                             $matchlevel = $i + 1;
755                             last;
756                         }
757                     }
758                 }
759                 if (defined $targetdir) {
760                      _add_to_file_map($file_map, $targetdir, $curr_path, $file, $matchlevel);
761                 } else {
762                     my $path = join("/", @$curr_path);
763                     print "failed to map: $path/$file\n" if $DEBUG;
764                 }
765             }
766         } else {
767             # dealing with subdirectory
768             push @$curr_path, $dir;
769             get_file_map($target_map, $dirtree->{$dir}, $file_map, $curr_path);
770             pop @$curr_path;
771         }
772     }
773 }
774
775 sub _add_to_file_map {
776     my $file_map = shift;
777     my $targetdir = shift;
778     my $curr_path = shift;
779     my $file = shift;
780     my $matchlevel = shift;
781     my $dest_path = @_ ? shift : $curr_path;
782
783     # The target can be one of the following:
784     # 1. scalar representing target symbol
785     # 2. hash ref containing target and trimdir keys
786     #
787     # Consequently, this routine traverses this structure,
788     # calling itself recursively, until it deals with
789     # all of the scalar target symbols.
790     if (ref $targetdir eq 'HASH') {
791         my $subtarget = $targetdir->{target};
792         if (exists $targetdir->{trimdir}) {
793             # if we get here, we've specified that
794             # rather than installing the file to
795             # $(TARGET)/matching/dirs/subdirs/file,
796             # we want to install it to
797             # $(TARGET)/subdirs/file
798             #
799             # Note that this the only place where
800             # $matchlevel is used.
801             my @new_dest_path = @$dest_path;
802             if ($targetdir->{trimdir} == -1)  {
803                 splice @new_dest_path, 0, $matchlevel;
804             } else {
805                 splice @new_dest_path, 0, $targetdir->{trimdir};
806             }
807             _add_to_file_map($file_map, $subtarget, $curr_path, $file, $matchlevel, \@new_dest_path);
808         } else {
809             # actually getting here means that the
810             # target was unnecessarily listed
811             # as a hash, but we'll forgive that
812             _add_to_file_map($file_map, $subtarget, $curr_path, $file, $matchlevel);
813         }
814     } elsif ($targetdir ne 'NONE' and $targetdir ne '') {
815         my $source = File::Spec->catfile(@$curr_path, $file);
816         my $destination = File::Spec->catfile('blib', $targetdir, @$dest_path, $file);
817         #print "$source => $destination\n"; # DEBUG
818         # quote spaces in file names
819         # FIXME: this is of questionable portability and
820         # probably depends on user's make recognizing this
821         # quoting syntax -- probably better to remove
822         # spaces and shell metacharacters from all file names
823         $source =~ s/ /\\ /g;
824         $destination =~ s/ /\\ /g;
825
826         $file_map->{$source} = $destination;
827     }
828 }
829
830 =head2 get_cli_values
831
832 Reads values provided on cli for configuration values
833
834 =cut
835
836 sub get_cli_values {
837     my $values = shift;
838     my $map = {
839         INSTALL_MODE               => $cli_koha_install_mode,
840         DB_TYPE                    => $cli_koha_db_type,
841         DB_HOST                    => $cli_koha_db_host,
842         DB_PORT                    => $cli_koha_db_port,
843         DB_NAME                    => $cli_koha_db_name,
844         DB_USER                    => $cli_koha_db_user,
845         DB_PASS                    => $cli_koha_db_pass,
846         ZEBRA_MARC_FORMAT          => $cli_zebra_marc_format,
847         ZEBRA_LANGUAGE             => $cli_zebra_language,
848         ZEBRA_TOKENIZER            => $cli_zebra_tokenizer,
849         ZEBRA_USER                 => $cli_zebra_user,
850         ZEBRA_PASS                 => $cli_zebra_pass,
851         ZEBRA_SRU_HOST             => $cli_zebra_sru_host,
852         ZEBRA_SRU_BIBLIOS_PORT     => $cli_zebra_sru_bib_port,
853         ZEBRA_SRU_AUTHORITIES_PORT => $cli_zebra_sru_auth_port,
854         AUTH_INDEX_MODE            => $cli_koha_auth_index_mode,
855         BIB_INDEX_MODE             => $cli_koha_bib_index_mode,
856         KOHA_USER                  => $cli_koha_user,
857         KOHA_GROUP                 => $cli_koha_group,
858         INSTALL_SRU                => $cli_koha_install_sru,
859         INSTALL_PAZPAR2            => $cli_koha_install_pazpar2,
860         USE_MEMCACHED              => $cli_koha_use_memcached,
861         FONT_DIR                   => $cli_koha_font_dir,
862         RUN_DATABASE_TESTS         => $cli_koha_run_database_tests,
863         INSTALL_BASE               => $cli_koha_install_base
864     };
865     foreach my $key (keys %{$map}) {
866         $values->{$key} = $map->{$key} if ($map->{$key});
867     }
868 }
869
870 =head2 get_install_log_values
871
872 Reads value from the Koha install log specified by
873 --prev-install-log
874
875 =cut
876
877 sub get_install_log_values {
878     my $install_log = shift;
879     my $values = shift;
880
881     open LOG, "<$install_log" or die "Cannot open install log $install_log: $!\n";
882     while (<LOG>) {
883         chomp;
884         next if /^#/ or /^\s*$/;
885         next if /^=/;
886         next unless m/=/;
887         s/\s+$//g;
888         my ($key, $value) = split /=/, $_, 2;
889         $values->{$key} = $value;
890     }
891     close LOG;
892
893     print <<_EXPLAIN_INSTALL_LOG_;
894 Reading values from install log $install_log.  You
895 will be prompted only for settings that have been
896 added since the last time you installed Koha.  To
897 be prompted for all settings, run 'perl Makefile.PL'
898 without the --prev-install-log option.
899 _EXPLAIN_INSTALL_LOG_
900 }
901
902 =head2 get_configuration
903
904 This prompts the user for various configuration options.
905
906 =cut
907
908 sub get_configuration {
909   my $defaults = shift;
910   my $valid_values = shift;
911   my $install_log_values = shift;
912   my %config = ();
913
914   my $msg = q(
915 By default, Koha can be installed in one of three ways:
916
917 standard: Install files in conformance with the Filesystem
918           Hierarchy Standard (FHS).  This is the default mode
919           and should be used when installing a production
920           Koha system.  On Unix systems, root access is
921           needed to complete a standard installation.
922
923 single:   Install files under a single directory.  This option
924           is useful for installing Koha without root access, e.g.,
925           on a web host that allows CGI scripts and MySQL databases
926           but requires the user to keep all files under the user's
927           HOME directory.
928
929 dev:      Create a set of symbolic links and configuration files to
930           allow Koha to run directly from the source distribution.
931           This mode is useful for developers who want to run
932           Koha from a git clone.
933
934 Installation mode);
935     $msg .= _add_valid_values_disp('INSTALL_MODE', $valid_values);
936     $config{'INSTALL_MODE'} = _get_value('INSTALL_MODE', $msg, $defaults->{'INSTALL_MODE'}, $valid_values, $install_log_values);
937
938     # set message and default value for INSTALL_BASE
939     # depending on value of INSTALL_MODE
940     my $install_base_default = $defaults->{'INSTALL_BASE'};
941     if ($config{'INSTALL_MODE'} eq 'dev') {
942         $msg = q(
943 Please specify the directory in which to install Koha's
944 active configuration files and (if applicable) the
945 Zebra database.  Koha's CGI scripts and templates will
946 be run from the current directory.
947
948 Configuration directory:);
949         # FIXME - home directory portability consideration apply
950         $install_base_default =
951             $ENV{DESTDIR}
952             || ( exists $ENV{HOME} ? "$ENV{HOME}/koha-dev" : "$defaults->{'INSTALL_BASE'}-dev" )
953         ;
954     } elsif ($config{'INSTALL_MODE'} eq 'single') {
955         $msg = "\nPlease specify the directory in which to install Koha";
956         # FIXME -- we're assuming under a 'single' mode install
957         # that user will likely want to install under the home
958         # directory.  This is OK in and of itself, but we should
959         # use File::HomeDir to locate the home directory portably.
960         # This is deferred for now because File::HomeDir is not yet
961         # core.
962                 # --we must also keep this portable to the major OS's -fbcit
963         $install_base_default = (exists $ENV{'HOME'}) ? "$ENV{'HOME'}/koha" : $defaults->{'INSTALL_BASE'};
964     } else {
965         # must be standard
966         $msg = q(
967 Please specify the directory under which most Koha files
968 will be installed.
969
970 Note that if you are planning in installing more than
971 one instance of Koha, you may want to modify the last
972 component of the directory path, which will be used
973 as the package name in the FHS layout.
974
975 Base installation directory);
976     }
977     $config{'INSTALL_BASE'} = _get_value('INSTALL_BASE', $msg, $install_base_default, $valid_values, $install_log_values);
978
979     $config{'INSTALL_BASE'} = File::Spec->rel2abs($config{'INSTALL_BASE'});
980         print "INSTALL_BASE=$config{'INSTALL_BASE'}\r\n" if $DEBUG;
981     if ($config{'INSTALL_MODE'} eq "standard") {
982         $msg = q(
983 Since you are using the 'standard' install
984 mode, you should run 'make install' as root.
985 However, it is recommended that a non-root
986 user (on Unix and Linux platforms) have
987 ownership of Koha's files, including the
988 Zebra indexes if applicable.
989
990 Please specify a user account.  This
991 user account does not need to exist
992 right now, but it needs to exist
993 before you run 'make install'.  Please
994 note that for security reasons, this
995 user should not be the same as the user
996 account Apache runs under.
997
998 User account);
999         $config{'KOHA_USER'} = _get_value('KOHA_USER', $msg, $defaults->{'KOHA_USER'}, $valid_values, $install_log_values);
1000
1001         $msg = q(
1002 Please specify the group that should own
1003 Koha's files.  As above, this group need
1004 not exist right now, but should be created
1005 before you run 'make install'.
1006
1007 Group);
1008         $config{'KOHA_GROUP'} = _get_value('KOHA_GROUP', $msg, $defaults->{'KOHA_GROUP'}, $valid_values, $install_log_values);
1009     }
1010
1011     $msg = q(
1012 Please specify which database engine you will use
1013 to store data in Koha.  The choices are MySQL and
1014 PostgreSQL; please note that at the moment
1015 PostgreSQL support is highly experimental.
1016
1017 DBMS to use);
1018     $msg .= _add_valid_values_disp('DB_TYPE', $valid_values);
1019     $config{'DB_TYPE'} = _get_value('DB_TYPE', $msg, $defaults->{'DB_TYPE'}, $valid_values, $install_log_values);
1020
1021     $msg = q(
1022 Please specify the name or address of your
1023 database server.  Note that the database
1024 does not have to exist at this point, it
1025 can be created after running 'make install'
1026 and before you try using Koha for the first time.
1027
1028 Database server);
1029     $config{'DB_HOST'} = _get_value('DB_HOST', $msg, $defaults->{'DB_HOST'}, $valid_values, $install_log_values);
1030
1031     $msg = q(
1032 Please specify the port used to connect to the
1033 DMBS);
1034     my $db_port_default = $config{'DB_TYPE'} eq 'mysql' ? '3306' : '5432';
1035     $config{'DB_PORT'} = _get_value('DB_PORT', $msg, $db_port_default, $valid_values, $install_log_values);
1036
1037     $msg = q(
1038 Please specify the name of the database to be
1039 used by Koha);
1040     $config{'DB_NAME'} = _get_value('DB_NAME', $msg, $defaults->{'DB_NAME'}, $valid_values, $install_log_values);
1041     if ($config{'DB_TYPE'} eq 'mysql'){
1042         $msg = q(
1043 Please specify whether the connection to MySQL will use TLS
1044         );
1045         $config{'DB_USE_TLS'} = _get_value('DB_USE_TLS', $msg, $defaults->{'DB_USE_TLS'}, $valid_values, $install_log_values);
1046     }
1047     if ($config{'DB_USE_TLS'} eq 'yes'){
1048         $msg = q(
1049 Please enter the path to the CA certificate for TLS
1050         );
1051         $config{'DB_TLS_CA_CERTIFICATE'} = _get_value('DB_TLS_CA_CERTIFICATE', $msg, $defaults->{'DB_TLS_CA_CERTIFICATE'}, $valid_values, $install_log_values);
1052
1053         $msg = q(
1054 Please enter the path to the client certificate for TLS
1055         );
1056         $config{'DB_TLS_CLIENT_CERTIFICATE'} = _get_value('DB_TLS_CLIENT_CERTIFICATE', $msg, $defaults->{'DB_TLS_CLIENT_CERTIFICATE'}, $valid_values, $install_log_values);
1057         $msg = q(
1058 Please enter the path to the client key for TLS
1059         );
1060         $config{'DB_TLS_CLIENT_KEY'} = _get_value('DB_TLS_CLIENT_KEY', $msg, $defaults->{'DB_TLS_CLIENT_KEY'}, $valid_values, $install_log_values);
1061     }
1062
1063     $msg = q(
1064 Please specify the user that owns the database to be
1065 used by Koha);
1066     $config{'DB_USER'} = _get_value('DB_USER', $msg, $defaults->{'DB_USER'}, $valid_values, $install_log_values);
1067
1068     $msg = q(
1069 Please specify the password of the user that owns the
1070 database to be used by Koha);
1071     $config{'DB_PASS'} = _get_value('DB_PASS', $msg, $defaults->{'DB_PASS'}, $valid_values, $install_log_values);
1072
1073     print q(
1074 Koha uses the Zebra search engine for high-performance
1075 searching of bibliographic and authority records.  Checking
1076 to see if you have installed the Zebra software...
1077 );
1078
1079     if (defined(my $zebra_path = find_zebra())) {
1080         $config{'PATH_TO_ZEBRA'} = $zebra_path;
1081         print qq(
1082 Found 'zebrasrv' and 'zebraidx' in $zebra_path.
1083 );
1084     } else {
1085         print q(
1086 Unable to find the Zebra programs 'zebrasrv' and 'zebraidx'
1087 in your PATH or in some of the usual places.  If you haven't
1088 installed Zebra yet, please do so and run Makefile.PL again.
1089
1090 );
1091     }
1092
1093     $msg = q(
1094 You must specify the primary MARC format of the
1095 records to be indexed by Zebra.
1096
1097 Koha provides Zebra configuration files for MARC21,
1098 NORMARC and UNIMARC.
1099
1100 MARC format for Zebra indexing);
1101     $msg .= _add_valid_values_disp('ZEBRA_MARC_FORMAT', $valid_values);
1102     $config{'ZEBRA_MARC_FORMAT'} = _get_value('ZEBRA_MARC_FORMAT', $msg, $defaults->{'ZEBRA_MARC_FORMAT'}, $valid_values, $install_log_values);
1103     $msg = q(
1104 Koha supplies Zebra configuration files tuned for
1105 searching either English (en) or French (fr) MARC
1106 records.
1107
1108 Primary language for Zebra indexing);
1109     $msg .= _add_valid_values_disp('ZEBRA_LANGUAGE', $valid_values);
1110     $config{'ZEBRA_LANGUAGE'} = _get_value('ZEBRA_LANGUAGE', $msg, $defaults->{'ZEBRA_LANGUAGE'}, $valid_values, $install_log_values);
1111
1112     $msg = q(
1113 Koha can use one of  two different indexing modes
1114 for the MARC bibliographic records:
1115
1116 dom  - uses the DOM XML filter; offers improved
1117        functionality.
1118 grs1 - [DEPRECATED] uses the Zebra GRS-1 filter,
1119        available for legacy support
1120
1121 Bibliographic indexing mode);
1122     $msg .= _add_valid_values_disp('BIB_INDEX_MODE', $valid_values);
1123     $config{'BIB_INDEX_MODE'} = _get_value('BIB_INDEX_MODE', $msg, $defaults->{'BIB_INDEX_MODE'}, $valid_values, $install_log_values);
1124
1125
1126     $msg = q(
1127 Koha can use one of  two different indexing modes
1128 for the MARC authorities records:
1129
1130 dom  - uses the DOM XML filter; offers improved
1131        functionality.
1132 grs1 - [DEPRECATED] uses the Zebra GRS-1 filter,
1133        available for legacy support
1134
1135 Authorities indexing mode);
1136     $msg .= _add_valid_values_disp('AUTH_INDEX_MODE', $valid_values);
1137     $config{'AUTH_INDEX_MODE'} = _get_value('AUTH_INDEX_MODE', $msg, $defaults->{'AUTH_INDEX_MODE'}, $valid_values, $install_log_values);
1138
1139     $msg = q(
1140 Zebra has two methods to perform records tokenization
1141 and characters normalization: CHR and ICU. ICU is
1142 recommended for catalogs containing non-Latin
1143 characters.);
1144
1145     $msg .= _add_valid_values_disp('ZEBRA_TOKENIZER', $valid_values);
1146     $config{'ZEBRA_TOKENIZER'} = _get_value('ZEBRA_TOKENIZER', $msg, $defaults->{'ZEBRA_TOKENIZER'}, $valid_values, $install_log_values);
1147
1148     $msg = q(
1149 Please specify Zebra database user);
1150     $config{'ZEBRA_USER'} = _get_value('ZEBRA_USER', $msg, $defaults->{'ZEBRA_USER'}, $valid_values, $install_log_values);
1151
1152     $msg = q(
1153 Please specify the Zebra database password);
1154     $config{'ZEBRA_PASS'} = _get_value('ZEBRA_PASS', $msg, $defaults->{'ZEBRA_PASS'}, $valid_values, $install_log_values);
1155
1156     $msg = q(
1157 Since you've chosen to use Zebra, you can enable the SRU/
1158 Z39.50 Server if you so choose, but you must specify a
1159 few configuration options for it.
1160
1161 Please note that if you choose *NOT* to configure SRU,
1162 koha-conf.xml will still contain some references to SRU
1163 settings.  Those references will be ignored by Koha.
1164
1165 Install the SRU configuration files?);
1166     $msg .= _add_valid_values_disp('INSTALL_SRU', $valid_values);
1167     $config{'INSTALL_SRU'} = _get_value('INSTALL_SRU', $msg, $defaults->{'INSTALL_SRU'}, $valid_values, $install_log_values);
1168
1169     if ($config{'INSTALL_SRU'} eq 'yes') {
1170         $msg = q(
1171 Since you've chosen to configure SRU, you must
1172 specify the host and port(s) that the SRU
1173 Servers (bibliographic and authority) should run on.
1174 );
1175         $msg = q(
1176 SRU Database host?);
1177         $config{'ZEBRA_SRU_HOST'} = _get_value('ZEBRA_SRU_HOST', $msg, $defaults->{'ZEBRA_SRU_HOST'}, $valid_values, $install_log_values);
1178
1179         $msg = q(
1180 SRU port for bibliographic data?);
1181         $config{'ZEBRA_SRU_BIBLIOS_PORT'} = _get_value('ZEBRA_SRU_BIBLIOS_PORT', $msg, $defaults->{'ZEBRA_SRU_BIBLIOS_PORT'}, $valid_values, $install_log_values);
1182
1183         $msg = q(
1184 SRU port for authority data?);
1185         $config{'ZEBRA_SRU_AUTHORITIES_PORT'} = _get_value('ZEBRA_SRU_AUTHORITIES_PORT', $msg, $defaults->{'ZEBRA_SRU_AUTHORITIES_PORT'}, $valid_values, $install_log_values);
1186
1187     }
1188
1189     $msg = q(
1190 Along with Zebra, you can also choose to install PazPar2,
1191 which is a metasearch tool.  With PazPar2,
1192 Koha can perform on-the-fly merging of bibliographic
1193 records during searching, allowing for FRBRization of
1194 the results list.
1195
1196 Install the PazPar2 configuration files?);
1197     $msg .= _add_valid_values_disp('INSTALL_PAZPAR2', $valid_values);
1198     $config{'INSTALL_PAZPAR2'} = _get_value('INSTALL_PAZPAR2', $msg, $defaults->{'INSTALL_PAZPAR2'}, $valid_values, $install_log_values);
1199
1200     if ($config{'INSTALL_PAZPAR2'} eq 'yes') {
1201         $msg = q(
1202 Since you've chosen to configure PazPar2, you must
1203 specify the host and port(s) that PazPar2
1204 uses:
1205 );
1206         $msg = q(
1207 Zebra bibliographic server host?);
1208         $config{'MERGE_SERVER_HOST'} = _get_value('MERGE_SERVER_HOST', $msg, $defaults->{'MERGE_SERVER_HOST'}, $valid_values, $install_log_values);
1209
1210         $msg = q(
1211 Zebra bibliographic port for PazPar2 to use?);
1212         $config{'MERGE_SERVER_PORT'} = _get_value('MERGE_SERVER_PORT', $msg, $defaults->{'MERGE_SERVER_PORT'}, $valid_values, $install_log_values);
1213
1214         $msg = q(
1215 PazPar2 host?);
1216         $config{'PAZPAR2_HOST'} = _get_value('PAZPAR2_HOST', $msg, $defaults->{'PAZPAR2_HOST'}, $valid_values, $install_log_values);
1217
1218         $msg = q(
1219 PazPar2 port?);
1220         $config{'PAZPAR2_PORT'} = _get_value('PAZPAR2_PORT', $msg, $defaults->{'PAZPAR2_PORT'}, $valid_values, $install_log_values);
1221
1222     }
1223
1224   $msg = q(
1225 Use memcached to cache the results of some function calls?
1226 This provides a signficant performance improvement.
1227 You will need a Memcached server running.);
1228   $msg .= _add_valid_values_disp('USE_MEMCACHED', $valid_values);
1229   $config{'USE_MEMCACHED'} = _get_value('USE_MEMCACHED', $msg, $defaults->{'USE_MEMCACHED'}, $valid_values, $install_log_values);
1230   if ($config{'USE_MEMCACHED'} eq 'yes'){
1231       $msg = q(
1232 Since you've chosen to use caching, you must specify the memcached servers and the namespace to use:
1233 );
1234       $msg = q(
1235 Memcached server address?);
1236       $config{'MEMCACHED_SERVERS'} = _get_value('MEMCACHED_SERVERS', $msg, $defaults->{'MEMCACHED_SERVERS'}, $valid_values, $install_log_values);
1237
1238       $msg = q(
1239 Memcached namespace?);
1240       $config{'MEMCACHED_NAMESPACE'} = _get_value('MEMCACHED_NAMESPACE', $msg, $defaults->{'MEMCACHED_NAMESPACE'}, $valid_values, $install_log_values);
1241   }
1242
1243   $msg = q(
1244 Path to DejaVu fonts?);
1245   $config{'FONT_DIR'} = _get_value('FONT_DIR', $msg, $defaults->{'FONT_DIR'}, $valid_values, $install_log_values);
1246
1247
1248   $msg = q(
1249 Would you like to run the database-dependent test suite?);
1250   $msg .= _add_valid_values_disp( 'RUN_DATABASE_TESTS', $valid_values );
1251     $config{'RUN_DATABASE_TESTS'} = _get_value( 'RUN_DATABASE_TESTS', $msg, $defaults->{'RUN_DATABASE_TESTS'}, $valid_values, $install_log_values );
1252
1253   if ( $config{'RUN_DATABASE_TESTS'} eq 'yes' ) {
1254       $config{'TEST_DB_TYPE'} = $config{'DB_TYPE'};
1255       $config{'TEST_DB_HOST'} = $config{'DB_HOST'};
1256       $msg = q(TEST DATABASE
1257
1258 THE DATA IN THIS DATABASE WILL BE DESTROYED during the process of
1259 testing. Please don't do this on your production database. It is not
1260 reversable.
1261
1262 YOU WILL SUFFER DATA LOSS if you run this test suite on your test
1263 database. You are better off not running this optional test suite than
1264 doing it in a database that you don't want to lose.
1265
1266 Please specify the name of the test database to be
1267 used by Koha);
1268
1269       $config{'TEST_DB_NAME'} = _get_value('TEST_DB_NAME', $msg, $defaults->{'TEST_DB_NAME'}, $valid_values, $install_log_values);
1270       while ( $config{'TEST_DB_NAME'} eq $config{'DB_NAME'} ) {
1271           $msg = q(Please do not use the same database for testing as you do for production. You run the severe risk of data loss.);
1272           $config{'TEST_DB_NAME'} = _get_value('TEST_DB_NAME', $msg, $defaults->{'TEST_DB_NAME'}, $valid_values, $install_log_values);
1273       }
1274
1275       $msg = q(
1276 Please specify the user that owns the database to be
1277 used by Koha);
1278     $config{'TEST_DB_USER'} = _get_value('TEST_DB_USER', $msg, $defaults->{'TEST_DB_USER'}, $valid_values, $install_log_values);
1279
1280       $msg = q(
1281 Please specify the password of the user that owns the
1282 database to be used by Koha);
1283       $config{'TEST_DB_PASS'} = _get_value('TEST_DB_PASS', $msg, $defaults->{'TEST_DB_PASS'}, $valid_values, $install_log_values);
1284   }
1285
1286     print "\n\n";
1287
1288     # add version number
1289     my $version = "no_version_found";
1290     eval {
1291         require 'kohaversion.pl';
1292         $version = kohaversion();
1293     };
1294     $config{'KOHA_INSTALLED_VERSION'} = $version;
1295
1296     return %config;
1297 }
1298
1299 sub _add_valid_values_disp {
1300     my $key = shift;
1301     my $valid_values = shift;
1302
1303     my $disp = "";
1304     if (exists $valid_values->{$key}) {
1305         $disp = " (" . join(", ", sort keys %{ $valid_values->{$key} }) . ")";
1306     }
1307     return $disp;
1308 }
1309
1310 sub _get_value {
1311     my $key = shift;
1312     my $msg = shift;
1313     my $default = shift;
1314     my $valid_values = shift;
1315     my $install_log_values = shift;
1316
1317     # take value from install log if present
1318     if (exists $install_log_values{$key}) {
1319         $install_log_values{$key} =~ s/\$/\$\$/g;
1320         return $install_log_values{$key};
1321     }
1322
1323     # override default value from environment
1324     if (exists $ENV{$key}) {
1325         $default = $ENV{$key};
1326         $msg .= " (default from environment)";
1327     }
1328
1329     my $val = prompt($msg, $default);
1330
1331     while (exists $valid_values->{$key} and
1332            $val ne $default and
1333            not exists $valid_values->{$key}->{$val}) {
1334         my $retry_msg = "Value '$val' is not a valid option.\n";
1335         $retry_msg .= "Please enter a value";
1336         $retry_msg .= _add_valid_values_disp($key, $valid_values);
1337         $val = prompt($retry_msg, $default);
1338     }
1339     $val =~ s/\$/\$\$/g;
1340     return $val;
1341 }
1342
1343 =head2 get_target_directories
1344
1345 Creates a hash mapping from symbols for installation target
1346 directories to actual directory paths.
1347
1348 Also returns a hash indicating targets for which
1349 files need not be copied -- this is used for the 'dev'
1350 mode installation, where some files are installed in place.
1351
1352 =cut
1353
1354 sub get_target_directories {
1355     my $config = shift;
1356
1357     my $base = $config->{'INSTALL_BASE'};
1358     my $mode = $config->{'INSTALL_MODE'};
1359
1360     # get last component of install base directory
1361     # to treat as package name
1362     my ($volume, $directories, $file) = File::Spec->splitpath($base, 1);
1363
1364     my @basedir = File::Spec->splitdir($directories);
1365
1366     if ( $^O eq 'cygwin' ) { shift @basedir; unshift @basedir, 'c:'; }   # in a cygwin environment, $volume is returned empty
1367
1368     my $package = pop @basedir;
1369
1370
1371     my %dirmap = ();
1372     my %skipdirs = ();
1373     if ($mode eq 'single') {
1374         $dirmap{'API_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'api');
1375         $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
1376         $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs', 'intranet-tmpl');
1377         $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs');
1378         $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
1379         $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl');
1380         $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs');
1381         $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
1382         $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
1383         $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
1384         $dirmap{'PAZPAR2_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'pazpar2');
1385         $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
1386         $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
1387         $dirmap{'SCRIPT_NONDEV_DIR'} = $dirmap{'SCRIPT_DIR'};
1388         $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
1389         $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
1390         $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
1391         $dirmap{'LOG_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'log');
1392         $dirmap{'BACKUP_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'spool');
1393         $dirmap{'PLUGINS_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'lib', 'koha', 'plugins');
1394         $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
1395         $dirmap{'ZEBRA_RUN_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
1396     } elsif ($mode eq 'dev') {
1397         my $curdir = File::Spec->rel2abs(File::Spec->curdir());
1398         $dirmap{'API_CGI_DIR'} = File::Spec->catdir($curdir, 'api');
1399         $skipdirs{'API_CGI_DIR'} = 1;
1400         $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir($curdir);
1401         $skipdirs{'INTRANET_CGI_DIR'} = 1;
1402         $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'intranet-tmpl');
1403         $skipdirs{'INTRANET_TMPL_DIR'} = 1;
1404         $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl');
1405         $skipdirs{'INTRANET_WWW_DIR'} = 1;
1406         $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir($curdir);
1407         $skipdirs{'OPAC_CGI_DIR'} = 1;
1408         $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'opac-tmpl');
1409         $skipdirs{'OPAC_TMPL_DIR'} = 1;
1410         $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl');
1411         $skipdirs{'OPAC_WWW_DIR'} = 1;
1412         $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir($curdir);
1413         $skipdirs{'PERL_MODULE_DIR'} = 1;
1414         $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
1415         $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
1416         $dirmap{'PAZPAR2_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'pazpar2');
1417         $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
1418         $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
1419         #For dev install, point NONDEV_DIR to misc in current dir (not base)
1420         #Used by supportdir in koha-conf.xml (BZ 12031)
1421         $dirmap{'SCRIPT_NONDEV_DIR'} = File::Spec->catdir($curdir, 'misc');
1422         $skipdirs{'SCRIPT_NONDEV_DIR'} = 1;
1423         $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
1424         $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
1425         $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
1426         $dirmap{'LOG_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'log');
1427         $dirmap{'BACKUP_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'spool');
1428         $dirmap{'PLUGINS_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'lib', 'plugins');
1429         $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
1430         $dirmap{'ZEBRA_RUN_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
1431     } else {
1432         # mode is standard, i.e., 'fhs'
1433         $dirmap{'API_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'api');
1434         $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
1435         $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs', 'intranet-tmpl');
1436         $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs');
1437         $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
1438         $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl');
1439         $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs');
1440         $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
1441         $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package);
1442         $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package, 'zebradb');
1443         $dirmap{'PAZPAR2_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package, 'pazpar2');
1444         $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
1445         $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
1446         $dirmap{'SCRIPT_NONDEV_DIR'} = $dirmap{'SCRIPT_DIR'};
1447         $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
1448         $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
1449         $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lock', $package, 'zebradb');
1450         $dirmap{'LOG_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'log', $package);
1451         $dirmap{'BACKUP_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'spool', $package);
1452         $dirmap{'PLUGINS_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'plugins');
1453         $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'zebradb');
1454         $dirmap{'ZEBRA_RUN_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'run', $package, 'zebradb');
1455     }
1456
1457     _get_env_overrides(\%dirmap);
1458     _get_argv_overrides(\%dirmap);
1459     _add_destdir(\%dirmap);
1460
1461     return \%dirmap, \%skipdirs;
1462 }
1463
1464 =head2 get_test_dir
1465
1466 Map a directory target to the corresponding path for
1467 the test suite.
1468
1469 =cut
1470
1471 sub get_test_dir {
1472     my ($dirname) = @_;
1473
1474     my @basedir = (File::Spec->rel2abs(File::Spec->curdir()), 't', 'run');
1475     if (exists $test_suite_override_dirs{$dirname}) {
1476         return File::Spec->catdir(@basedir, @{ $test_suite_override_dirs{$dirname} });
1477     } else {
1478         return;
1479     }
1480
1481 }
1482
1483 sub _get_env_overrides {
1484     my $dirmap = shift;
1485
1486     foreach my $key (keys %$dirmap) {
1487         if (exists $ENV{$key}) {
1488             $dirmap->{$key} = $ENV{$key};
1489             print "Setting $key from environment\n";
1490         }
1491     }
1492 }
1493
1494 sub _get_argv_overrides {
1495     my $dirmap = shift;
1496
1497     my @new_argv = ();
1498     for (my $i = 0; $i <= $#ARGV; $i++) {
1499         if ($ARGV[$i] =~ /^([^=]+)=([^=]+)$/ and exists $dirmap->{$1}) {
1500             $dirmap->{$1} = $2;
1501         } else {
1502             push @new_argv, $ARGV[$i];
1503         }
1504     }
1505     @ARGV = @new_argv;
1506 }
1507
1508 sub _strip_destdir {
1509     my $dir = shift;
1510     $dir =~ s/^\$\(DESTDIR\)//;
1511     return $dir;
1512 }
1513
1514 sub _add_destdir {
1515     my $dirmap = shift;
1516
1517     foreach my $key (keys %$dirmap) {
1518         $dirmap->{$key} = '$(DESTDIR)'.$dirmap->{$key};
1519     }
1520 }
1521
1522 sub display_configuration {
1523     my $config = shift;
1524     my $dirmap = shift;
1525     my @version = grep /\/usr\/share\/perl\//, @INC;
1526     push @version, ('/usr/share/perl/5.10') if !$version[0];
1527     print "\n\nKoha will be installed with the following configuration parameters:\n\n";
1528     foreach my $key (sort keys %$config) {
1529         print sprintf("%-25.25s%s\n", $key, $config->{$key});
1530     }
1531
1532     print "\nand in the following directories:\n\n";
1533     foreach my $key (sort keys %$dirmap) {
1534         print sprintf("%-25.25s%s\n", $key, $dirmap->{$key});
1535     }
1536     print "\n\nTo change any configuration setting, please run\n";
1537     print "perl Makefile.PL again.  To override one of the target\n";
1538     print "directories, you can do so on the command line like this:\n";
1539     print "\nperl Makefile.PL PERL_MODULE_DIR=$version[0]\n\n";
1540     print "You can also set different default values for parameters\n";
1541     print "or override directory locations by using environment variables.\n";
1542     print "\nFor example:\n\n";
1543     print "export DB_USER=my_koha\n";
1544     print "perl Makefile.PL\n";
1545     print "\nor\n\n";
1546     print "DB_USER=my_koha DOC_DIR=/usr/local/info perl Makefile.PL\n\n";
1547 }
1548
1549 =head2 find_zebra
1550
1551 Attempt to find Zebra - check user's PATH and
1552 a few other directories for zebrasrv and zebraidx.
1553
1554 =cut
1555
1556 sub find_zebra {
1557     my @search_dirs = map {
1558                             my $abs = File::Spec->rel2abs($_);
1559                             my ($toss, $directories);
1560                             ($toss, $directories, $toss) = File::Spec->splitpath($abs, 1);
1561                             $directories;
1562                         }  split /:/, $ENV{PATH};
1563     push @search_dirs, qw(/usr/local/bin /opt/local/bin /usr/bin);
1564     my @zebrasrv_dirs = grep { -x File::Spec->catpath('', $_, 'zebrasrv') } @search_dirs;
1565     return unless @zebrasrv_dirs;
1566     # verify that directory that contains zebrasrv also contains zebraidx
1567     foreach my $dir (@zebrasrv_dirs) {
1568         return $dir if -x File::Spec->catpath('', $dir, 'zebraidx');
1569     }
1570     return;
1571 }
1572
1573 package MY;
1574
1575 sub test {
1576     my $self = shift;
1577     my $test = $self->SUPER::test(@_);
1578     $test =~ s!\$\(INST_LIB\)!blib/PERL_MODULE_DIR!g;
1579
1580     # set KOHA_CONF
1581     $test =~ s!\$\(FULLPERLRUN\)!KOHA_CONF=blib/KOHA_CONF_DIR/koha-conf.xml \$(FULLPERLRUN)!g;
1582     return $test;
1583 }
1584
1585 sub install {
1586     my $self = shift;
1587     my $install = "";
1588     # NOTE: we're *not* doing this: my $install = $self->SUPER::install(@_);
1589     # This means that we're completely overriding EU::MM's default
1590     # installation and uninstallation targets.
1591
1592 # If installation is on Win32, we need to do permissions different from *nix
1593     if ( $^O =~ /darwin|linux|cygwin|freebsd|solaris/ ) { # this value needs to be verified for each platform and modified accordingly
1594             foreach my $key (sort keys %$target_directories) {
1595                     $install .= qq(
1596 KOHA_INST_$key = blib/$key
1597 KOHA_DEST_$key = $target_directories->{$key}
1598 ) unless exists $skip_directories->{$key};
1599                 }
1600                 $install .= qq(
1601 install :: all install_koha set_koha_ownership set_koha_permissions warn_koha_env_vars
1602 \t\$(NOECHO) \$(NOOP)
1603 );
1604                         $install .= "install_koha ::\n";
1605                         $install .= "\t\$(NOECHO) umask 022; \$(MOD_INSTALL) \\\n";
1606                         foreach my $key (sort keys %$target_directories) {
1607                                 $install .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
1608           unless exists $skip_directories->{$key};
1609                         }
1610                         $install .= "\t\t\$(INST_MAN1DIR) \$(DESTINSTALLMAN1DIR) \\\n";
1611                         $install .= "\t\t\$(INST_MAN3DIR) \$(DESTINSTALLMAN3DIR)\n";
1612
1613                         $install .= "\n";
1614                         $install .= "set_koha_ownership ::\n";
1615 # Do not try to change ownership if DESTDIR is set
1616                         if ($config{'INSTALL_MODE'} eq 'standard' and $config{'KOHA_USER'} ne "root") {
1617                                 foreach my $key (sort keys %$target_directories) {
1618             $install .= "\t\$(NOECHO) if test -z \"\$(DESTDIR)\"; then chown -R $config{'KOHA_USER'}:$config{'KOHA_GROUP'} \$(KOHA_DEST_$key); fi\n"
1619             unless exists $skip_directories->{$key};
1620                                 }
1621                         } else {
1622                                 $install .= "\t\t\$(NOECHO) \$(NOOP)\n\n";
1623                         }
1624
1625                         $install .= "\n";
1626                         $install .= "set_koha_permissions ::\n";
1627                         # This is necessary because EU::MM installs files
1628                         # as either 0444 or 0555, and we want the owner
1629                         # of Koha's files to have write permission by default.
1630                         foreach my $key (sort keys %$target_directories) {
1631                                 $install .= "\t\$(NOECHO) chmod -R u+w \$(KOHA_DEST_$key)\n"
1632           unless exists $skip_directories->{$key};
1633                         }
1634         }
1635
1636         $install .= "\n";
1637
1638     $install .= "warn_koha_env_vars ::\n";
1639     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1640     $install .= "\t\$(NOECHO) \$(ECHO) Koha\\'s files have now been installed. \n";
1641     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1642     $install .= "\t\$(NOECHO) \$(ECHO) In order to use Koha\\'s command-line batch jobs,\n";
1643     $install .= "\t\$(NOECHO) \$(ECHO) you should set the following environment variables:\n";
1644     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1645     $install .= "\t\$(NOECHO) \$(ECHO) export KOHA_CONF=\$(KOHA_DEST_KOHA_CONF_DIR)/koha-conf.xml\n";
1646     $install .= "\t\$(NOECHO) \$(ECHO) export PERL5LIB=$target_directories->{'PERL_MODULE_DIR'}\n";
1647     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1648     $install .= "\t\$(NOECHO) \$(ECHO) For other post-installation tasks, please consult the README.\n";
1649     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1650
1651     $install .= _update_zebra_conf_target();
1652
1653     $install .= upgrade();
1654
1655     return $install;
1656 }
1657
1658 =head2 _update_zebra_conf_target
1659
1660 Add an installation target for updating
1661 Zebra's configuration files.
1662
1663 =cut
1664
1665 sub _update_zebra_conf_target {
1666
1667     my $target = "\nupdate_zebra_conf ::\n";
1668     $target .= "\tumask 022; \$(MOD_INSTALL) \\\n";
1669     $target .= "\t\t\$(KOHA_INST_ZEBRA_CONF_DIR) \$(KOHA_DEST_ZEBRA_CONF_DIR) \n";
1670     $target .= "\t\$(NOECHO) chmod -R u+w \$(KOHA_DEST_ZEBRA_CONF_DIR)\n";
1671     $target .= "\tumask 022; \$(MOD_INSTALL) \\\n";
1672     $target .= "\t\t\$(KOHA_INST_PAZPAR2_CONF_DIR) \$(KOHA_DEST_PAZPAR2_CONF_DIR) \n";
1673     $target .= "\t\$(NOECHO) chmod -R u+w \$(KOHA_DEST_PAZPAR2_CONF_DIR)\n";
1674
1675     return $target;
1676 }
1677
1678 sub upgrade {
1679     my $upgrade = "";
1680
1681     my $backup_suffix;
1682     if (exists $install_log_values{'KOHA_INSTALLED_VERSION'}) {
1683         my $version = $install_log_values{'KOHA_INSTALLED_VERSION'};
1684         $version =~ s/\./_/g;
1685         $backup_suffix = "_koha_$version";
1686     } else {
1687         $backup_suffix = "_upgrade_backup";
1688     }
1689
1690     $upgrade .= qq/
1691 MOD_BACKUP = \$(ABSPERLRUN) -MC4::Installer::UpgradeBackup -e 'backup_changed_files({\@ARGV}, '$backup_suffix', '\''\$(VERBINST)'\'', '\''\$(UNINST)'\'');' --
1692
1693 upgrade :: make_upgrade_backup install
1694 \t\$(NOECHO) \$(NOOP)
1695 make_upgrade_backup ::
1696 \t\$(NOECHO) umask 022; \$(MOD_BACKUP) \\
1697 /;
1698     foreach my $key (qw/KOHA_CONF_DIR INTRANET_TMPL_DIR INTRANET_WWW_DIR OPAC_TMPL_DIR OPAC_WWW_DIR
1699                      PAZPAR2_CONF_DIR ZEBRA_CONF_DIR PLUGINS_DIR/) {
1700         $upgrade .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
1701             unless exists $skip_directories->{$key} or
1702                    not exists $target_directories->{$key};
1703     }
1704     $upgrade =~ s/\\\n$/\n/;
1705
1706     return $upgrade;
1707 }
1708 sub postamble {
1709     # put directory mappings into Makefile
1710     # so that Make will export as environment
1711     # variables -- this is for the use of
1712     # rewrite-confg.PL
1713
1714     my $env;
1715         # Hereagain, we must alter syntax per platform...
1716         {
1717                 $env = join("\n", map { "export __${_}__ := $target_directories->{$_}" } keys %$target_directories);
1718                 $env .= "\n\n";
1719                 $env .= join("\n", map { "export __${_}__ := $config{$_}" } keys %config);
1720         }
1721
1722     return "$env\n";
1723 }
1724
1725
1726 __END__
1727
1728
1729 =head1 SEE ALSO
1730
1731 ExtUtils::MakeMaker(3)
1732
1733 =head1 AUTHORS
1734
1735 MJ Ray mjr at phonecoop.coop
1736 Galen Charlton galen.charlton at liblime.com
1737
1738 =cut
1739
1740 FIXME: deal with .htaccess