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