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