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