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