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