Bug 21899: Update MARC21 frameworks to Update 27 (November 2018)
[koha.git] / Makefile.PL
blobce323ef163a50db1162f3ef08354e885e8f07628
1 # Copyright 2007 MJ Ray
2 # Copyright 2016 PTFS Europe
4 # This file is part of Koha.
6 # Koha is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
11 # Koha is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with Koha; if not, see <http://www.gnu.org/licenses>.
19 # Current maintainer MJR http://mjr.towers.org.uk/
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
30 use lib $FindBin::Bin;
32 use C4::Installer;
34 my $koha_pm = C4::Installer::PerlModules->new;
36 my $DEBUG = 0;
37 die "perl 5.10 or later required" unless ($] >= 5.010000);
39 # Hash up directory structure & files beginning with the directory we were called from (should be the base of koha)...
41 my $dirtree = hashdir('.');
42 my %result = ();
44 =head1 NAME
46 Makefile.PL - Koha packager and installer
48 =head1 SYNOPSIS
50 =head2 BASIC INSTALLATION
52     perl Makefile.PL
53     make
54     make test
55     sudo make install
57 =head2 UPGRADE INSTALLATION
59     NOTE: This option is only available if koha-install-log exists.
61     perl Makefile.PL --prev-install-log /path/to/koha-install-log
63     make
64     make test
65     sudo make upgrade
67 =head2 PACKAGING RELEASE TARBALLS
69     make manifest tardist
70     make manifest zipdist
72 =head2 CLEANING UP
74         make clean
76 =head2 CLI PARAMETERS
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     --koha_user                  Koha Unix user (e.g. koha)
95     --koha_group                 Koha Unix group (e.g. koha)
96     --install_sru                Install the SRU server (yes, no)
97     --install_pazpar2            Install PazPar2 (yes, no)
98     --use_memcached              Use Memcached (yes, no)
99     --font_dir                   Location of fonts (e.g. /usr/share/fonts/truetype/ttf-dejavu)
100     --run_database_tests         Run database dependent tests (yes, no)
101     --install_base               Base directory of installation (e.g. /usr/share/koha)
102     --template-cache-dir         Specify a template cache directory (e.g. /var/cache/koha)
103     --help                       Display this help message
105 =head1 DESCRIPTION
107 This is a packager and installer that uses
108 ExtUtils::MakeMaker, which is fairly common
109 on perl systems.
110 As well as building tar or zip files
111 and installing with the above commands,
112 it allows us to check pre-requisites
113 and generate configuration files.
115 =head1 VARIABLES
117 =head2 NAME, VERSION_FROM, ABSTRACT, AUTHOR
119 Basic metadata about this software.
121 =head2 NO_META
123 Suppress generation of META.yml file.
125 =head2 PREREQ_PM
127 Hash of perl modules and versions required.
129 =head2 PM
131 Hash of file mappings
133 =head2 PL_FILES
135 This is a hash of PL scripts to run after installation and
136 the files to ask them to generate.
137 Maybe use the values from CONFIGURE
138 to generate initial configuration files in future.
140 =cut
142 =head2 target_map
144 This is a hash mapping directories and files in the
145 source tree to installation target directories.  The rules
146 for this mapping are:
148 =over 4
150 =item If a directory or file is specified, it and its
151 contents will be copied to the installation target directory.
153 =item If a subdirectory of a mapped directory is specified,
154 its target overrides the parent's target for that subdirectory.
156 =item The value of each map entry may either be a scalar containing
157 one target or a reference to a hash containing 'target' and 'trimdir'
158 keys.
160 =item Any files at the top level of the source tree that are
161 not included in the map will not be installed.
163 =item Any directories at the top level of the source tree
164 that are not included in the map will be installed in
165 INTRANET_CGI_DIR.  This is a sensible default given the
166 current organization of the source tree, but (FIXME) it
167 would be better to reorganize the source tree to better
168 match the installation system, to allow adding new directories
169 without having to adjust Makefile.PL each time.  The idea
170 is to make the C<$target_map> hash as minimal as possible.
172 =back
174 The permitted installation targets are:
176 =over 4
178 =item INTRANET_CGI_DIR
180 CGI scripts for intranet (staff) interface.
182 =item INTRANET_TMPL_DIR
184 HTML templates for the intranet interface.
186 =item INTRANET_WWW_DIR
188 HTML files, images, etc. for DocumentRoot for the intranet interface.
190 =item OPAC_CGI_DIR
192 CGI scripts for OPAC (public) interface.
194 =item OPAC_TMPL_DIR
196 HTML templates for the OPAC interface.
198 =item OPAC_WWW_DIR
200 HTML files, images, etc. for DocumentRoot for the OPAC interface.
202 =item PERL_MODULE_DIR
204 Perl modules (at present just the C4 modules) that are intimately
205 tied to Koha.  Depending on the installation options, these
206 may or may not be installed one of the standard directories
207 in Perl's default @LIB.
209 =item KOHA_CONF_DIR
211 Directory for Koha configuration files.
213 =item ZEBRA_CONF_DIR
215 Directory for Zebra configuration files.
217 =item ZEBRA_LOCK_DIR
219 Directory for Zebra's lock files.  This includes subdirs for authorities,
220 biblios, and the zebra rebuild function.  Any activity to reindex
221 zebra from koha should interlock here with rebuild_zebra.pl.
223 =item ZEBRA_DATA_DIR
225 Directory for Zebra's data files.
227 =item ZEBRA_RUN_DIR
229 Directory for Zebra's UNIX-domain sockets.
231 =item MISC_DIR
233 Directory for for miscellaenous scripts, among other
234 things the translation toolkit and RSS feed tools.
236 =item SCRIPT_DIR
238 Directory for command-line scripts and daemons to
239 be set up all for installation modes.
241 =item SCRIPT_NONDEV_DIR
243 Directory for command-line scripts that should
244 be installed in the same directory as the
245 SCRIPT_DIR target except 'dev' installs.
247 =item MAN_DIR
249 Directory for man pages created from POD -- will mostly
250 contain information of interest to Koha developers.
252 =item DOC_DIR
254 Directory for Koha documentation accessed from the
255 command-line, e.g., READMEs.
257 =item LOG_DIR
259 Directory for Apache and Zebra logs produced by Koha.
261 =item BACKUP_DIR
263 Directory for backup files produced by Koha.
265 =item PLUGINS_DIR
267 Directory for external Koha plugins.
269 =item PAZPAR2_CONF_DIR
271 Directory for PazPar2 configuration files.
273 =item FONT_DIR
275 Directory where DejaVu fonts are installed.
277 =item NONE
279 This is a dummy target used to explicitly state
280 that a given file or directory is not to be installed.
281 This is used either for parts of the installer itself
282 or for development tools that are not applicable to a
283 production installation.
285 =back
287 =cut
289 my $target_map = {
290   './about.pl'                  => 'INTRANET_CGI_DIR',
291   './acqui'                     => 'INTRANET_CGI_DIR',
292   './admin'                     => 'INTRANET_CGI_DIR',
293   './api'                       => { target => 'API_CGI_DIR', trimdir => -1 },
294   './authorities'               => 'INTRANET_CGI_DIR',
295   './basket'                    => 'INTRANET_CGI_DIR',
296   './C4'                        => 'PERL_MODULE_DIR',
297   './C4/SIP/t'                  => 'NONE',
298   './C4/SIP/koha_test'          => 'NONE',
299   './C4/tests'                  => 'NONE',
300   './catalogue'                 => 'INTRANET_CGI_DIR',
301   './cataloguing'               => 'INTRANET_CGI_DIR',
302   './changelanguage.pl'         => 'INTRANET_CGI_DIR',
303   './check_sysprefs.pl'         => 'NONE',
304   './circ'                      => 'INTRANET_CGI_DIR',
305   './clubs'                     => '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   './etc'                       => { target => 'KOHA_CONF_DIR', trimdir => -1 },
310   './etc/zebradb'               => { target => 'ZEBRA_CONF_DIR', trimdir => -1 },
311   './etc/pazpar2'               => { target => 'PAZPAR2_CONF_DIR', trimdir => -1 },
312   './help.pl'                   => 'INTRANET_CGI_DIR',
313   './ill'                       => '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   # ignore files and directories created by the install itself
374   './pm_to_blib'                => 'NONE',
375   './blib'                      => 'NONE',
376   '.sass-lint.yml'              => 'NONE',
377   '.scss-lint.yml'              => 'NONE',
378   'gulpfile.js'                 => 'NONE',
379   'package.json'                => 'NONE',
380   'yarn.lock'                   => 'NONE',
383 =head1 CONFIGURATION OPTIONS
385 The following configuration options are used by the installer.
387 =over 4
389 =item INSTALL_MODE
391 Specifies whether installation will be FHS-compliant (default,
392 assumes user has root), put everything under
393 a single directory (for users installing on a web host
394 that allows CGI scripts and a MySQL database but not root
395 access), or development (for a developer who wants to run
396 Koha from a git clone with no fuss).
398 =item INSTALL_BASE
400 Directory under which most components will go.  Default
401 value will vary depending on INSTALL_MODE.
403 =item DB_TYPE
405 Type of DBMS (e.g., mysql or Pg).
407 =item DB_HOST
409 Name of DBMS server.
411 =item DB_PORT
413 Port that DBMS server is listening on.
415 =item DB_NAME
417 Name of the DBMS database for Koha.
419 =item DB_USER
421 Name of DBMS user account for Koha's database.
423 =item DB_PASS
425 Pasword of DMBS user account for Koha's database.
427 =item ZEBRA_MARC_FORMAT
429 Specifies format of MARC records to be indexed by Zebra.
431 =item ZEBRA_LANGUAGE
433 Specifies primary language of records that will be
434 indexed by Zebra.
436 =item ZEBRA_USER
438 Internal Zebra user account for the index.
440 =item ZEBRA_PASS
442 Internal Zebra user account's password.
444 =item KOHA_USER
446 System user account that will own Koha's files.
448 =item KOHA_GROUP
450 System group that will own Koha's files.
452 =back
454 =cut
456 # default configuration options
457 my %config_defaults = (
458   'DB_TYPE'           => 'mysql',
459   'DB_HOST'           => 'localhost',
460   'DB_NAME'           => 'koha',
461   'DB_USER'           => 'kohaadmin',
462   'DB_PASS'           => 'katikoan',
463   'DB_USE_TLS'        => 'no',
464   'DB_TLS_CA_CERTIFICATE'  => '/etc/mysql-ssl/server-ca.pem',
465   'DB_TLS_CLIENT_CERTIFICATE'  => '/etc/mysql-ssl/client-cert.pem',
466   'DB_TLS_CLIENT_KEY' => '/etc/mysql-ssl/client-key.pem',
467   'INSTALL_SRU'       => 'yes',
468   'INSTALL_PAZPAR2'   => 'no',
469   'ZEBRA_MARC_FORMAT' => 'marc21',
470   'ZEBRA_LANGUAGE'    => 'en',
471   'ZEBRA_TOKENIZER'   => 'chr',
472   'ZEBRA_USER'        => 'kohauser',
473   'ZEBRA_PASS'        => 'zebrastripes',
474   'ZEBRA_SRU_HOST'    => 'localhost',
475   'ZEBRA_SRU_BIBLIOS_PORT'    => '9998',
476   'ZEBRA_SRU_AUTHORITIES_PORT'    => '9999',
477   'KOHA_USER'         => 'koha',
478   'KOHA_GROUP'        => 'koha',
479   'MERGE_SERVER_HOST' => 'localhost',
480   'MERGE_SERVER_PORT' => '11001',
481   'PAZPAR2_HOST' => 'localhost',
482   'PAZPAR2_PORT' => '11002',
483   'RUN_DATABASE_TESTS' => 'no',
484   'PATH_TO_ZEBRA' => '',
485   'USE_MEMCACHED'     => 'yes',
486   'MEMCACHED_SERVERS' => '127.0.0.1:11211',
487   'MEMCACHED_NAMESPACE' => 'KOHA',
488   'TEMPLATE_CACHE_DIR' => '/tmp/koha',
489   'FONT_DIR'          => '/usr/share/fonts/truetype/ttf-dejavu'
492 # set some default configuration options based on OS
493 # more conditions need to be added for other OS's
495 warn "Your platform appears to be $^O.\n" if $DEBUG;
497 if ( $^O eq 'cygwin' ) {
498         # Most Unix2Win32 ports seem to poke everything into the Program Files directory
499         # this could be changed to put some files (ie. libraries) into system32, etc.
500         $config_defaults{'INSTALL_MODE'} = 'single';
501         $config_defaults{'INSTALL_BASE'} = 'c:/progra~1/koha';  # Use 8.3 names to be safe...
503 else {
504         $config_defaults{'INSTALL_MODE'} = 'standard';
505         $config_defaults{'INSTALL_BASE'} = '/usr/share/koha';
508 # valid values for certain configuration options
509 my %valid_config_values = (
510   'INSTALL_MODE'  => { 'standard' => 1, 'single' => 1, 'dev' => 1 },
511   'DB_TYPE' => { 'mysql' => 1, 'Pg' => 1 },
512   'DB_USE_TLS' => {'yes', 'no'},
513   'INSTALL_SRU' => { 'yes' => 1, 'no' => 1 },
514   'ZEBRA_MARC_FORMAT' => { 'marc21' => 1, 'normarc' => 1, 'unimarc' => 1 }, # FIXME should generate from contents of distributation
515   'ZEBRA_LANGUAGE'    => { 'cs' => 1, 'en' => 1, 'es' => 1, 'fr' => 1, 'gr' => 1, 'nb' => 1, 'ru' => 1, 'uk' => 1 }, # FIXME should generate from contents of distribution
516   'ZEBRA_TOKENIZER' => { chr => 1, icu => 1 },
517   'RUN_DATABASE_TESTS' => { 'yes' => 1, 'no' => 1 },
518   'USE_MEMCACHED'      => { 'yes' => 1, 'no' => 1 },
521 # get settings from command-line
522 my $koha_install_log = "";
523 my $cli_koha_install_mode = "";
524 my $cli_koha_db_type = "";
525 my $cli_koha_db_host = "";
526 my $cli_koha_db_port = "";
527 my $cli_koha_db_name = "";
528 my $cli_koha_db_user = "";
529 my $cli_koha_db_pass = "";
530 my $cli_zebra_marc_format = "";
531 my $cli_zebra_language = "",
532 my $cli_zebra_tokenizer = "";
533 my $cli_zebra_user = "";
534 my $cli_zebra_pass = "";
535 my $cli_zebra_sru_host = "";
536 my $cli_zebra_sru_bib_port = "";
537 my $cli_zebra_sru_auth_port = "";
538 my $cli_koha_user = "";
539 my $cli_koha_group = "";
540 my $cli_koha_install_sru = "";
541 my $cli_koha_install_pazpar2 = "";
542 my $cli_koha_use_memcached = "";
543 my $cli_koha_font_dir = "";
544 my $cli_koha_run_database_tests = "";
545 my $cli_koha_install_base = "";
546 my $cli_koha_template_cache_dir = "";
547 Getopt::Long::Configure('pass_through');
548 my $results = GetOptions(
549     "prev-install-log=s"           => \$koha_install_log,
550     "install_mode=s"               => \$cli_koha_install_mode,
551     "db_type=s"                    => \$cli_koha_db_type,
552     "db_host=s"                    => \$cli_koha_db_host,
553     "db_port=s"                    => \$cli_koha_db_port,
554     "db_name=s"                    => \$cli_koha_db_name,
555     "db_user=s"                    => \$cli_koha_db_user,
556     "db_pass=s"                    => \$cli_koha_db_pass,
557     "zebra_marc_format=s"          => \$cli_zebra_marc_format,
558     "zebra_language=s"             => \$cli_zebra_language,
559     "zebra_tokenizer=s"            => \$cli_zebra_tokenizer,
560     "zebra_user=s"                 => \$cli_zebra_user,
561     "zebra_pass=s"                 => \$cli_zebra_pass,
562     "zebra_sru_host=s"             => \$cli_zebra_sru_host,
563     "zebra_sru_biblios_port=s"     => \$cli_zebra_sru_bib_port,
564     "zebra_sru_authorities_port=s" => \$cli_zebra_sru_auth_port,
565     "koha_user=s"                  => \$cli_koha_user,
566     "koha_group=s"                 => \$cli_koha_group,
567     "install_sru=s"                => \$cli_koha_install_sru,
568     "install_pazpar2=s"            => \$cli_koha_install_pazpar2,
569     "use_memcached=s"              => \$cli_koha_use_memcached,
570     "font_dir=s"                   => \$cli_koha_font_dir,
571     "run_database_tests=s"         => \$cli_koha_run_database_tests,
572     "install_base=s"               => \$cli_koha_install_base,
573     "template-cache-dir=s"         => \$cli_koha_template_cache_dir,
574     "help"                         => sub { HelpMessage(0) },
575 ) or HelpMessage(1);
577 my %install_log_values = ();
578 if ($koha_install_log ne "") {
579     get_install_log_values($koha_install_log, \%install_log_values);
580 } else {
581     # Try to set install_log_values for provided values;
582     get_cli_values(\%install_log_values);
585 my %config = get_configuration(\%config_defaults, \%valid_config_values, \%install_log_values);
586 my ($target_directories, $skip_directories) = get_target_directories(\%config);
587 display_configuration(\%config, $target_directories);
588 my $file_map = {};
589 get_file_map($target_map, $dirtree, $file_map);
591 my $pl_files = {
592       'rewrite-config.PL' => [
593          'blib/KOHA_CONF_DIR/koha-conf.xml',
594          'blib/KOHA_CONF_DIR/koha-httpd.conf',
595          'blib/KOHA_CONF_DIR/log4perl.conf',
596          'blib/ZEBRA_CONF_DIR/etc/default.idx',
597          'blib/MISC_DIR/koha-install-log'
598          ],
599           'fix-perl-path.PL' => [       # this script ensures the correct shebang line for the platform installed on...
600                  'blib'
601                  ],
604 push @{ $pl_files->{'rewrite-config.PL'} }, (
605     'blib/ZEBRA_CONF_DIR/etc/passwd',
606     'blib/ZEBRA_CONF_DIR/zebra-biblios-dom.cfg',
607     'blib/ZEBRA_CONF_DIR/zebra-authorities-dom.cfg',
608     'blib/ZEBRA_CONF_DIR/explain-authorities.xml',
609     'blib/ZEBRA_CONF_DIR/explain-biblios.xml',
610     'blib/ZEBRA_CONF_DIR/retrieval-info-auth-dom.xml',
611     'blib/ZEBRA_CONF_DIR/retrieval-info-bib-dom.xml',
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',
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     );
624 $config{'ZEBRA_AUTH_CFG'} = 'zebra-authorities-dom.cfg';
625 $config{'ZEBRA_BIB_CFG'}  = 'zebra-biblios-dom.cfg';
626 $config{'AUTH_RETRIEVAL_CFG'} = 'retrieval-info-auth-dom.xml';
627 $config{'BIB_RETRIEVAL_CFG'}  = 'retrieval-info-bib-dom.xml';
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     );
636 $config{ZEBRA_TOKENIZER_STMT} = $config{ZEBRA_TOKENIZER} eq 'icu'
637     ? 'icuchain words-icu.xml'
638     : 'charmap word-phrase-utf.chr';
640 $config{ZEBRA_PTOKENIZER_STMT} = $config{ZEBRA_TOKENIZER} eq 'icu'
641     ? 'icuchain phrases-icu.xml'
642     : 'charmap word-phrase-utf.chr';
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'],
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,
664               # File tree mapping
665               PM => $file_map,
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'),
672               PL_FILES => $pl_files,
675 =head1 FUNCTIONS
677 =head2 hashdir
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
683 =cut
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;
698 =head2 get_file_map
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.
704 Output will be a hash mapping from each source file
705 to its destination value, like this:
707 'mainpage.pl' => '$(INTRANET_CGI_DIR)/mainpage.pl'
709 =cut
711 sub get_file_map {
712     my $target_map = shift;
713     my $dirtree = shift;
714     my $file_map = shift;
715     my $curr_path = @_ ? shift : ['.'];
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     }
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;
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;
811         $file_map->{$source} = $destination;
812     }
815 =head2 get_cli_values
817 Reads values provided on cli for configuration values
819 =cut
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         ZEBRA_SRU_HOST             => $cli_zebra_sru_host,
837         ZEBRA_SRU_BIBLIOS_PORT     => $cli_zebra_sru_bib_port,
838         ZEBRA_SRU_AUTHORITIES_PORT => $cli_zebra_sru_auth_port,
839         KOHA_USER                  => $cli_koha_user,
840         KOHA_GROUP                 => $cli_koha_group,
841         INSTALL_SRU                => $cli_koha_install_sru,
842         INSTALL_PAZPAR2            => $cli_koha_install_pazpar2,
843         USE_MEMCACHED              => $cli_koha_use_memcached,
844         FONT_DIR                   => $cli_koha_font_dir,
845         RUN_DATABASE_TESTS         => $cli_koha_run_database_tests,
846         INSTALL_BASE               => $cli_koha_install_base,
847         TEMPLATE_CACHE_DIR         => $cli_koha_template_cache_dir
848     };
849     foreach my $key (keys %{$map}) {
850         $values->{$key} = $map->{$key} if ($map->{$key});
851     }
854 =head2 get_install_log_values
856 Reads value from the Koha install log specified by
857 --prev-install-log
859 =cut
861 sub get_install_log_values {
862     my $install_log = shift;
863     my $values = shift;
865     open LOG, "<$install_log" or die "Cannot open install log $install_log: $!\n";
866     while (<LOG>) {
867         chomp;
868         next if /^#/ or /^\s*$/;
869         next if /^=/;
870         next unless m/=/;
871         s/\s+$//g;
872         my ($key, $value) = split /=/, $_, 2;
873         $values->{$key} = $value;
874     }
875     close LOG;
877     print <<_EXPLAIN_INSTALL_LOG_;
878 Reading values from install log $install_log.  You
879 will be prompted only for settings that have been
880 added since the last time you installed Koha.  To
881 be prompted for all settings, run 'perl Makefile.PL'
882 without the --prev-install-log option.
883 _EXPLAIN_INSTALL_LOG_
886 =head2 get_configuration
888 This prompts the user for various configuration options.
890 =cut
892 sub get_configuration {
893   my $defaults = shift;
894   my $valid_values = shift;
895   my $install_log_values = shift;
896   my %config = ();
898   my $msg = q(
899 By default, Koha can be installed in one of three ways:
901 standard: Install files in conformance with the Filesystem
902           Hierarchy Standard (FHS).  This is the default mode
903           and should be used when installing a production
904           Koha system.  On Unix systems, root access is
905           needed to complete a standard installation.
907 single:   Install files under a single directory.  This option
908           is useful for installing Koha without root access, e.g.,
909           on a web host that allows CGI scripts and MySQL databases
910           but requires the user to keep all files under the user's
911           HOME directory.
913 dev:      Create a set of symbolic links and configuration files to
914           allow Koha to run directly from the source distribution.
915           This mode is useful for developers who want to run
916           Koha from a git clone.
918 Installation mode);
919     $msg .= _add_valid_values_disp('INSTALL_MODE', $valid_values);
920     $config{'INSTALL_MODE'} = _get_value('INSTALL_MODE', $msg, $defaults->{'INSTALL_MODE'}, $valid_values, $install_log_values);
922     # set message and default value for INSTALL_BASE
923     # depending on value of INSTALL_MODE
924     my $install_base_default = $defaults->{'INSTALL_BASE'};
925     if ($config{'INSTALL_MODE'} eq 'dev') {
926         $msg = q(
927 Please specify the directory in which to install Koha's
928 active configuration files and (if applicable) the
929 Zebra database.  Koha's CGI scripts and templates will
930 be run from the current directory.
932 Configuration directory:);
933         # FIXME - home directory portability consideration apply
934         $install_base_default =
935             $ENV{DESTDIR}
936             || ( exists $ENV{HOME} ? "$ENV{HOME}/koha-dev" : "$defaults->{'INSTALL_BASE'}-dev" )
937         ;
938     } elsif ($config{'INSTALL_MODE'} eq 'single') {
939         $msg = "\nPlease specify the directory in which to install Koha";
940         # FIXME -- we're assuming under a 'single' mode install
941         # that user will likely want to install under the home
942         # directory.  This is OK in and of itself, but we should
943         # use File::HomeDir to locate the home directory portably.
944         # This is deferred for now because File::HomeDir is not yet
945         # core.
946                 # --we must also keep this portable to the major OS's -fbcit
947         $install_base_default = (exists $ENV{'HOME'}) ? "$ENV{'HOME'}/koha" : $defaults->{'INSTALL_BASE'};
948     } else {
949         # must be standard
950         $msg = q(
951 Please specify the directory under which most Koha files
952 will be installed.
954 Note that if you are planning in installing more than
955 one instance of Koha, you may want to modify the last
956 component of the directory path, which will be used
957 as the package name in the FHS layout.
959 Base installation directory);
960     }
961     $config{'INSTALL_BASE'} = _get_value('INSTALL_BASE', $msg, $install_base_default, $valid_values, $install_log_values);
963     $config{'INSTALL_BASE'} = File::Spec->rel2abs($config{'INSTALL_BASE'});
964         print "INSTALL_BASE=$config{'INSTALL_BASE'}\r\n" if $DEBUG;
965     if ($config{'INSTALL_MODE'} eq "standard") {
966         $msg = q(
967 Since you are using the 'standard' install
968 mode, you should run 'make install' as root.
969 However, it is recommended that a non-root
970 user (on Unix and Linux platforms) have
971 ownership of Koha's files, including the
972 Zebra indexes if applicable.
974 Please specify a user account.  This
975 user account does not need to exist
976 right now, but it needs to exist
977 before you run 'make install'.  Please
978 note that for security reasons, this
979 user should not be the same as the user
980 account Apache runs under.
982 User account);
983         $config{'KOHA_USER'} = _get_value('KOHA_USER', $msg, $defaults->{'KOHA_USER'}, $valid_values, $install_log_values);
985         $msg = q(
986 Please specify the group that should own
987 Koha's files.  As above, this group need
988 not exist right now, but should be created
989 before you run 'make install'.
991 Group);
992         $config{'KOHA_GROUP'} = _get_value('KOHA_GROUP', $msg, $defaults->{'KOHA_GROUP'}, $valid_values, $install_log_values);
993     }
995     $msg = q(
996 Please specify which database engine you will use
997 to store data in Koha.  The choices are MySQL and
998 PostgreSQL; please note that at the moment
999 PostgreSQL support is highly experimental.
1001 DBMS to use);
1002     $msg .= _add_valid_values_disp('DB_TYPE', $valid_values);
1003     $config{'DB_TYPE'} = _get_value('DB_TYPE', $msg, $defaults->{'DB_TYPE'}, $valid_values, $install_log_values);
1005     $msg = q(
1006 Please specify the name or address of your
1007 database server.  Note that the database
1008 does not have to exist at this point, it
1009 can be created after running 'make install'
1010 and before you try using Koha for the first time.
1012 Database server);
1013     $config{'DB_HOST'} = _get_value('DB_HOST', $msg, $defaults->{'DB_HOST'}, $valid_values, $install_log_values);
1015     $msg = q(
1016 Please specify the port used to connect to the
1017 DMBS);
1018     my $db_port_default = $config{'DB_TYPE'} eq 'mysql' ? '3306' : '5432';
1019     $config{'DB_PORT'} = _get_value('DB_PORT', $msg, $db_port_default, $valid_values, $install_log_values);
1021     $msg = q(
1022 Please specify the name of the database to be
1023 used by Koha);
1024     $config{'DB_NAME'} = _get_value('DB_NAME', $msg, $defaults->{'DB_NAME'}, $valid_values, $install_log_values);
1025     if ($config{'DB_TYPE'} eq 'mysql'){
1026         $msg = q(
1027 Please specify whether the connection to MySQL will use TLS
1028         );
1029         $config{'DB_USE_TLS'} = _get_value('DB_USE_TLS', $msg, $defaults->{'DB_USE_TLS'}, $valid_values, $install_log_values);
1030     }
1031     if ($config{'DB_USE_TLS'} eq 'yes'){
1032         $msg = q(
1033 Please enter the path to the CA certificate for TLS
1034         );
1035         $config{'DB_TLS_CA_CERTIFICATE'} = _get_value('DB_TLS_CA_CERTIFICATE', $msg, $defaults->{'DB_TLS_CA_CERTIFICATE'}, $valid_values, $install_log_values);
1037         $msg = q(
1038 Please enter the path to the client certificate for TLS
1039         );
1040         $config{'DB_TLS_CLIENT_CERTIFICATE'} = _get_value('DB_TLS_CLIENT_CERTIFICATE', $msg, $defaults->{'DB_TLS_CLIENT_CERTIFICATE'}, $valid_values, $install_log_values);
1041         $msg = q(
1042 Please enter the path to the client key for TLS
1043         );
1044         $config{'DB_TLS_CLIENT_KEY'} = _get_value('DB_TLS_CLIENT_KEY', $msg, $defaults->{'DB_TLS_CLIENT_KEY'}, $valid_values, $install_log_values);
1045     }
1047     $msg = q(
1048 Please specify the user that owns the database to be
1049 used by Koha);
1050     $config{'DB_USER'} = _get_value('DB_USER', $msg, $defaults->{'DB_USER'}, $valid_values, $install_log_values);
1052     $msg = q(
1053 Please specify the password of the user that owns the
1054 database to be used by Koha);
1055     $config{'DB_PASS'} = _get_value('DB_PASS', $msg, $defaults->{'DB_PASS'}, $valid_values, $install_log_values);
1057     print q(
1058 Koha uses the Zebra search engine for high-performance
1059 searching of bibliographic and authority records.  Checking
1060 to see if you have installed the Zebra software...
1063     if (defined(my $zebra_path = find_zebra())) {
1064         $config{'PATH_TO_ZEBRA'} = $zebra_path;
1065         print qq(
1066 Found 'zebrasrv' and 'zebraidx' in $zebra_path.
1068     } else {
1069         print q(
1070 Unable to find the Zebra programs 'zebrasrv' and 'zebraidx'
1071 in your PATH or in some of the usual places.  If you haven't
1072 installed Zebra yet, please do so and run Makefile.PL again.
1075     }
1077     $msg = q(
1078 You must specify the primary MARC format of the
1079 records to be indexed by Zebra.
1081 Koha provides Zebra configuration files for MARC21,
1082 NORMARC and UNIMARC.
1084 MARC format for Zebra indexing);
1085     $msg .= _add_valid_values_disp('ZEBRA_MARC_FORMAT', $valid_values);
1086     $config{'ZEBRA_MARC_FORMAT'} = _get_value('ZEBRA_MARC_FORMAT', $msg, $defaults->{'ZEBRA_MARC_FORMAT'}, $valid_values, $install_log_values);
1087     $msg = q(
1088 Koha supplies Zebra configuration files tuned for
1089 searching either English (en) or French (fr) MARC
1090 records.
1092 Primary language for Zebra indexing);
1093     $msg .= _add_valid_values_disp('ZEBRA_LANGUAGE', $valid_values);
1094     $config{'ZEBRA_LANGUAGE'} = _get_value('ZEBRA_LANGUAGE', $msg, $defaults->{'ZEBRA_LANGUAGE'}, $valid_values, $install_log_values);
1096     $msg = q(
1097 Zebra has two methods to perform records tokenization
1098 and characters normalization: CHR and ICU. ICU is
1099 recommended for catalogs containing non-Latin
1100 characters.);
1102     $msg .= _add_valid_values_disp('ZEBRA_TOKENIZER', $valid_values);
1103     $config{'ZEBRA_TOKENIZER'} = _get_value('ZEBRA_TOKENIZER', $msg, $defaults->{'ZEBRA_TOKENIZER'}, $valid_values, $install_log_values);
1105     $msg = q(
1106 Please specify Zebra database user);
1107     $config{'ZEBRA_USER'} = _get_value('ZEBRA_USER', $msg, $defaults->{'ZEBRA_USER'}, $valid_values, $install_log_values);
1109     $msg = q(
1110 Please specify the Zebra database password);
1111     $config{'ZEBRA_PASS'} = _get_value('ZEBRA_PASS', $msg, $defaults->{'ZEBRA_PASS'}, $valid_values, $install_log_values);
1113     $msg = q(
1114 Since you've chosen to use Zebra, you can enable the SRU/
1115 Z39.50 Server if you so choose, but you must specify a
1116 few configuration options for it.
1118 Please note that if you choose *NOT* to configure SRU,
1119 koha-conf.xml will still contain some references to SRU
1120 settings.  Those references will be ignored by Koha.
1122 Install the SRU configuration files?);
1123     $msg .= _add_valid_values_disp('INSTALL_SRU', $valid_values);
1124     $config{'INSTALL_SRU'} = _get_value('INSTALL_SRU', $msg, $defaults->{'INSTALL_SRU'}, $valid_values, $install_log_values);
1126     if ($config{'INSTALL_SRU'} eq 'yes') {
1127         $msg = q(
1128 Since you've chosen to configure SRU, you must
1129 specify the host and port(s) that the SRU
1130 Servers (bibliographic and authority) should run on.
1132         $msg = q(
1133 SRU Database host?);
1134         $config{'ZEBRA_SRU_HOST'} = _get_value('ZEBRA_SRU_HOST', $msg, $defaults->{'ZEBRA_SRU_HOST'}, $valid_values, $install_log_values);
1136         $msg = q(
1137 SRU port for bibliographic data?);
1138         $config{'ZEBRA_SRU_BIBLIOS_PORT'} = _get_value('ZEBRA_SRU_BIBLIOS_PORT', $msg, $defaults->{'ZEBRA_SRU_BIBLIOS_PORT'}, $valid_values, $install_log_values);
1140         $msg = q(
1141 SRU port for authority data?);
1142         $config{'ZEBRA_SRU_AUTHORITIES_PORT'} = _get_value('ZEBRA_SRU_AUTHORITIES_PORT', $msg, $defaults->{'ZEBRA_SRU_AUTHORITIES_PORT'}, $valid_values, $install_log_values);
1144     }
1146     $msg = q(
1147 Along with Zebra, you can also choose to install PazPar2,
1148 which is a metasearch tool.  With PazPar2,
1149 Koha can perform on-the-fly merging of bibliographic
1150 records during searching, allowing for FRBRization of
1151 the results list.
1153 Install the PazPar2 configuration files?);
1154     $msg .= _add_valid_values_disp('INSTALL_PAZPAR2', $valid_values);
1155     $config{'INSTALL_PAZPAR2'} = _get_value('INSTALL_PAZPAR2', $msg, $defaults->{'INSTALL_PAZPAR2'}, $valid_values, $install_log_values);
1157     if ($config{'INSTALL_PAZPAR2'} eq 'yes') {
1158         $msg = q(
1159 Since you've chosen to configure PazPar2, you must
1160 specify the host and port(s) that PazPar2
1161 uses:
1163         $msg = q(
1164 Zebra bibliographic server host?);
1165         $config{'MERGE_SERVER_HOST'} = _get_value('MERGE_SERVER_HOST', $msg, $defaults->{'MERGE_SERVER_HOST'}, $valid_values, $install_log_values);
1167         $msg = q(
1168 Zebra bibliographic port for PazPar2 to use?);
1169         $config{'MERGE_SERVER_PORT'} = _get_value('MERGE_SERVER_PORT', $msg, $defaults->{'MERGE_SERVER_PORT'}, $valid_values, $install_log_values);
1171         $msg = q(
1172 PazPar2 host?);
1173         $config{'PAZPAR2_HOST'} = _get_value('PAZPAR2_HOST', $msg, $defaults->{'PAZPAR2_HOST'}, $valid_values, $install_log_values);
1175         $msg = q(
1176 PazPar2 port?);
1177         $config{'PAZPAR2_PORT'} = _get_value('PAZPAR2_PORT', $msg, $defaults->{'PAZPAR2_PORT'}, $valid_values, $install_log_values);
1179     }
1181   $msg = q(
1182 Use memcached to cache the results of some function calls?
1183 This provides a significant performance improvement.
1184 You will need a Memcached server running.);
1185   $msg .= _add_valid_values_disp('USE_MEMCACHED', $valid_values);
1186   $config{'USE_MEMCACHED'} = _get_value('USE_MEMCACHED', $msg, $defaults->{'USE_MEMCACHED'}, $valid_values, $install_log_values);
1187   if ($config{'USE_MEMCACHED'} eq 'yes'){
1188       $msg = q(
1189 Since you've chosen to use caching, you must specify the memcached servers and the namespace to use:
1191       $msg = q(
1192 Memcached server address?);
1193       $config{'MEMCACHED_SERVERS'} = _get_value('MEMCACHED_SERVERS', $msg, $defaults->{'MEMCACHED_SERVERS'}, $valid_values, $install_log_values);
1195       $msg = q(
1196 Memcached namespace?);
1197       $config{'MEMCACHED_NAMESPACE'} = _get_value('MEMCACHED_NAMESPACE', $msg, $defaults->{'MEMCACHED_NAMESPACE'}, $valid_values, $install_log_values);
1198   }
1200   $msg = q(
1201 Template cache directory?);
1202   $config{'TEMPLATE_CACHE_DIR'} = _get_value('TEMPLATE_CACHE_DIR', $msg, $defaults->{'TEMPLATE_CACHE_DIR'}, $valid_values, $install_log_values);
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);
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 );
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
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 reversible.
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.
1227 Please specify the name of the test database to be
1228 used by Koha);
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       }
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);
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   }
1247     print "\n\n";
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;
1257     return %config;
1260 sub _add_valid_values_disp {
1261     my $key = shift;
1262     my $valid_values = shift;
1264     my $disp = "";
1265     if (exists $valid_values->{$key}) {
1266         $disp = " (" . join(", ", sort keys %{ $valid_values->{$key} }) . ")";
1267     }
1268     return $disp;
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;
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     }
1284     # override default value from environment
1285     if (exists $ENV{$key}) {
1286         $default = $ENV{$key};
1287         $msg .= " (default from environment)";
1288     }
1290     my $val = prompt($msg, $default);
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;
1304 =head2 get_target_directories
1306 Creates a hash mapping from symbols for installation target
1307 directories to actual directory paths.
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.
1313 =cut
1315 sub get_target_directories {
1316     my $config = shift;
1318     my $base = $config->{'INSTALL_BASE'};
1319     my $mode = $config->{'INSTALL_MODE'};
1321     # get last component of install base directory
1322     # to treat as package name
1323     my ($volume, $directories, $file) = File::Spec->splitpath($base, 1);
1325     my @basedir = File::Spec->splitdir($directories);
1327     if ( $^O eq 'cygwin' ) { shift @basedir; unshift @basedir, 'c:'; }   # in a cygwin environment, $volume is returned empty
1329     my $package = pop @basedir;
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     }
1418     _get_env_overrides(\%dirmap);
1419     _get_argv_overrides(\%dirmap);
1420     _add_destdir(\%dirmap);
1422     return \%dirmap, \%skipdirs;
1425 =head2 get_test_dir
1427 Map a directory target to the corresponding path for
1428 the test suite.
1430 =cut
1432 sub get_test_dir {
1433     my ($dirname) = @_;
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     }
1444 sub _get_env_overrides {
1445     my $dirmap = shift;
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     }
1455 sub _get_argv_overrides {
1456     my $dirmap = shift;
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;
1469 sub _strip_destdir {
1470     my $dir = shift;
1471     $dir =~ s/^\$\(DESTDIR\)//;
1472     return $dir;
1475 sub _add_destdir {
1476     my $dirmap = shift;
1478     foreach my $key (keys %$dirmap) {
1479         $dirmap->{$key} = '$(DESTDIR)'.$dirmap->{$key};
1480     }
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     }
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";
1510 =head2 find_zebra
1512 Attempt to find Zebra - check user's PATH and
1513 a few other directories for zebrasrv and zebraidx.
1515 =cut
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;
1534 package MY;
1536 sub test {
1537     my $self = shift;
1538     my $test = $self->SUPER::test(@_);
1539     $test =~ s!\$\(INST_LIB\)!blib/PERL_MODULE_DIR!g;
1541     # set KOHA_CONF
1542     $test =~ s!\$\(FULLPERLRUN\)!KOHA_CONF=blib/KOHA_CONF_DIR/koha-conf.xml \$(FULLPERLRUN)!g;
1543     return $test;
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.
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)
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";
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                         }
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         }
1597         $install .= "\n";
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";
1612     $install .= _update_zebra_conf_target();
1614     $install .= upgrade();
1616     return $install;
1619 =head2 _update_zebra_conf_target
1621 Add an installation target for updating
1622 Zebra's configuration files.
1624 =cut
1626 sub _update_zebra_conf_target {
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";
1636     return $target;
1639 sub upgrade {
1640     my $upgrade = "";
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     }
1651     $upgrade .= qq/
1652 MOD_BACKUP = \$(ABSPERLRUN) -MC4::Installer::UpgradeBackup -e 'backup_changed_files({\@ARGV}, '$backup_suffix', '\''\$(VERBINST)'\'', '\''\$(UNINST)'\'');' --
1654 upgrade :: make_upgrade_backup install
1655 \t\$(NOECHO) \$(NOOP)
1656 make_upgrade_backup ::
1657 \t\$(NOECHO) umask 022; \$(MOD_BACKUP) \\
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/;
1667     return $upgrade;
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
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         }
1683     return "$env\n";
1687 __END__
1690 =head1 SEE ALSO
1692 ExtUtils::MakeMaker(3)
1694 =head1 AUTHORS
1696 MJ Ray mjr at phonecoop.coop
1697 Galen Charlton galen.charlton at liblime.com
1699 =cut
1701 FIXME: deal with .htaccess