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