authorities - enabled DOM indexing
[koha.git] / Makefile.PL
blobbf08ff42718f313005b4f0854fec8d6e2990e688
1 # Copyright 2007 MJ Ray
3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
8 # version.
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA  02111-1307 USA
18 # Current maintainer MJR http://mjr.towers.org.uk/
19 # See http://www.koha.org/wiki/?page=KohaInstaller
22 use strict;
23 use warnings;
24 use ExtUtils::MakeMaker;
25 use POSIX;
26 use File::Spec;
28 my $DEBUG = 0;
29 die "perl 5.6.1 or later required" unless ($] >= 5.006001);
31 # Hash up directory structure & files beginning with the directory we were called from (should be the base of koha)...
33 my $dirtree = hashdir('.');
34 my %result = ();
36 =head1 NAME
38 Makefile.PL - Koha packager and installer
40 =head1 SYNOPSIS
42 =head2 BASIC INSTALLATION
44         perl Makefile.PL
45         make
46         sudo make install
48 =head2 PACKAGING RELEASE TARBALLS
50         make manifest tardist
51         make manifest zipdist
53 =head2 CLEANING UP
55         make clean
57 =head1 DESCRIPTION
59 This is a packager and installer that uses
60 ExtUtils::MakeMaker, which is fairly common
61 on perl systems.
62 As well as building tar or zip files
63 and installing with the above commands,
64 it allows us to check pre-requisites
65 and generate configuration files.
67 =head1 VARIABLES
69 =head2 NAME, VERSION_FROM, ABSTRACT, AUTHOR
71 Basic metadata about this software.
73 =head2 NO_META
75 Suppress generation of META.yml file.
77 =head2 PREREQ_PM
79 Hash of perl modules and versions required.
81 =head2 PM
83 Hash of file mappings
85 =head2 PL_FILES
87 This is a hash of PL scripts to run after installation and
88 the files to ask them to generate.
89 Maybe use the values from CONFIGURE
90 to generate initial configuration files in future.
92 =cut
94 =head2 target_map
96 This is a hash mapping directories and files in the
97 source tree to installation target directories.  The rules
98 for this mapping are:
100 =over 4
102 =item If a directory or file is specified, it and its
103 contents will be copied to the installation target directory.
105 =item If a subdirectory of a mapped directory is specified,
106 its target overrides the parent's target for that subdirectory.
108 =item The value of each map entry may either be a scalar containing 
109 one target or a reference to a hash containing 'target' and 'trimdir'
110 keys.
112 =item Any files at the top level of the source tree that are
113 not included in the map will not be installed.
115 =item Any directories at the top level of the source tree
116 that are not included in the map will be installed in
117 INTRANET_CGI_DIR.  This is a sensible default given the
118 current organization of the source tree, but (FIXME) it
119 would be better to reorganize the source tree to better
120 match the installation system, to allow adding new directories
121 without having to adjust Makefile.PL each time.  The idea
122 is to make the C<$target_map> hash as minimal as possible.
124 =back
126 The permitted installation targets are:
128 =over 4
130 =item INTRANET_CGI_DIR 
132 CGI scripts for intranet (staff) interface.
134 =item INTRANET_TMPL_DIR
136 HTML templates for the intranet interface.
138 =item INTRANET_WWW_DIR
140 HTML files, images, etc. for DocumentRoot for the intranet interface.
142 =item OPAC_CGI_DIR
144 CGI scripts for OPAC (public) interface.
146 =item OPAC_TMPL_DIR
148 HTML templates for the OPAC interface.
150 =item OPAC_WWW_DIR
152 HTML files, images, etc. for DocumentRoot for the OPAC interface.
154 =item PERL_MODULE_DIR
156 Perl modules (at present just the C4 modules) that are intimately
157 tied to Koha.  Depending on the installation options, these
158 may or may not be installed one of the standard directories
159 in Perl's default @LIB.
161 =item KOHA_CONF_DIR
163 Directory for Koha configuration files.
165 =item ZEBRA_CONF_DIR
167 Directory for Zebra configuration files.
169 =item ZEBRA_LOCK_DIR
171 Directory for Zebra's lock files.
173 =item ZEBRA_DATA_DIR
175 Directory for Zebra's data files.
177 =item ZEBRA_RUN_DIR
179 Directory for Zebra's UNIX-domain sockets.
181 =item MISC_DIR
183 Directory for for miscellaenous scripts, among other
184 things the translation toolkit and RSS feed tools.
186 =item SCRIPT_DIR
188 Directory for command-line scripts and daemons.
190 =item MAN_DIR
192 Directory for man pages created from POD -- will mostly
193 contain information of interest to Koha developers.
195 =item DOC_DIR
197 Directory for Koha documentation accessed from the 
198 command-line, e.g., READMEs.
200 =item LOG_DIR
202 Directory for Apache and Zebra logs produced by Koha.
204 =item NONE
206 This is a dummy target used to explicitly state
207 that a given file or directory is not to be installed.
208 This is used either for parts of the installer itself
209 or for development tools that are not applicable to a
210 production installation.
212 =back
214 =cut
216 my $target_map = {
217   './about.pl'                  => 'INTRANET_CGI_DIR',
218   './acqui'                     => 'INTRANET_CGI_DIR',
219   './admin'                     => 'INTRANET_CGI_DIR',
220   './authorities'               => 'INTRANET_CGI_DIR',
221   './C4'                        => 'PERL_MODULE_DIR',
222   './C4/SIP/t'                  => 'NONE',
223   './C4/SIP/koha_test'          => 'NONE',
224   './C4/tests'                  => 'NONE',
225   './catalogue'                 => 'INTRANET_CGI_DIR',
226   './cataloguing'               => 'INTRANET_CGI_DIR',
227   './changelanguage.pl'         => 'INTRANET_CGI_DIR',
228   './check_sysprefs.pl'         => 'NONE',
229   './circ'                      => 'INTRANET_CGI_DIR',
230   './edithelp.pl'               => 'INTRANET_CGI_DIR',
231   './etc'                       => { target => 'KOHA_CONF_DIR', trimdir => -1 },
232   './etc/zebradb'               => { target => 'ZEBRA_CONF_DIR', trimdir => -1 },
233   './help.pl'                   => 'INTRANET_CGI_DIR', 
234   './installer-CPAN.pl'         => 'NONE',
235   './installer'                 => 'INTRANET_CGI_DIR',
236   './koha-tmpl/errors'          => {target => 'INTRANET_CGI_DIR', trimdir => 2},
237   './koha-tmpl/intranet-tmpl'   => {target => 'INTRANET_TMPL_DIR', trimdir => -1},
238   './koha-tmpl/opac-tmpl'       => {target => 'OPAC_TMPL_DIR', trimdir => -1},
239   './kohaversion.pl'            => 'INTRANET_CGI_DIR', 
240   './labels'                    => 'INTRANET_CGI_DIR',
241   './mainpage.pl'               => 'INTRANET_CGI_DIR',
242   './Makefile.PL'               => 'NONE',
243   './MANIFEST.SKIP'             => 'NONE',
244   './members'                   => 'INTRANET_CGI_DIR',
245   './misc'                      => { target => 'SCRIPT_DIR', trimdir => -1 }, 
246   './misc/bin'                  => { target => 'SCRIPT_DIR', trimdir => -1 }, 
247   './misc/release_notes'        => { target => 'DOC_DIR', trimdir => 2 },
248   './misc/translator'           => { target => 'MISC_DIR', trimdir => 2 }, 
249   './misc/installer_devel_notes' => 'NONE',
250   './opac'                      => 'OPAC_CGI_DIR',
251   './README.txt'                => 'NONE',
252   './reports'                   => 'INTRANET_CGI_DIR',
253   './reserve'                   => 'INTRANET_CGI_DIR',
254   './reviews'                   => 'INTRANET_CGI_DIR',
255   './rewrite-config.PL'         => 'NONE',
256   './reviews'                   => 'INTRANET_CGI_DIR',
257   './rss'                       => 'MISC_DIR', 
258   './serials'                   => 'INTRANET_CGI_DIR',
259   './skel'                      => 'NONE',
260   './skel/var/log/koha'         => { target => 'LOG_DIR', trimdir => -1 },
261   './skel/var/run/koha/zebradb' => { target => 'ZEBRA_RUN_DIR', trimdir => -1 },
262   './skel/var/lock/koha/zebradb/authorities' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
263   './skel/var/lib/koha/zebradb/authorities/key'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
264   './skel/var/lib/koha/zebradb/authorities/register'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
265   './skel/var/lib/koha/zebradb/authorities/shadow'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
266   './skel/var/lib/koha/zebradb/authorities/tmp'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
267   './skel/var/lock/koha/zebradb/biblios' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
268   './skel/var/lib/koha/zebradb/biblios/key'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
269   './skel/var/lib/koha/zebradb/biblios/register'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
270   './skel/var/lib/koha/zebradb/biblios/shadow'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
271   './skel/var/lib/koha/zebradb/biblios/tmp'  => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
272   './sms'                       => 'INTRANET_CGI_DIR',
273   './suggestion'                => 'INTRANET_CGI_DIR',
274   './svc'                       => 'INTRANET_CGI_DIR',
275   './t'                         => 'NONE',
276   './tmp'                       => 'NONE', # FIXME need to determine whether 
277                                            # Koha generates any persistent temp files
278                                            # that should go in /var/tmp/koha
279   './tools'                     => 'INTRANET_CGI_DIR',
280   './virtualshelves'            => 'INTRANET_CGI_DIR',
281   # ignore files and directories created by the install itself
282   './pm_to_blib'                => 'NONE',
283   './blib'                      => 'NONE',
286 =head1 CONFIGURATION OPTIONS
288 The following configuration options are used by the installer.
290 =over 4
292 =item INSTALL_MODE
294 Specifies whether installation will be FHS-compliant (default,
295 assumes user has root), put everything under
296 a single directory (for users installing on a web host
297 that allows CGI scripts and a MySQL database but not root 
298 access), or development (for a developer who wants to run
299 Koha from a git clone with no fuss).
301 =item INSTALL_BASE
303 Directory under which most components will go.  Default
304 value will vary depending on INSTALL_MODE.
306 =item DB_TYPE
308 Type of DBMS (e.g., mysql or Pg).
310 =item DB_HOST
312 Name of DBMS server.
314 =item DB_PORT
316 Port that DBMS server is listening on.
318 =item DB_NAME
320 Name of the DBMS database for Koha.
322 =item DB_USER
324 Name of DBMS user account for Koha's database.
326 =item DB_PASS
328 Pasword of DMBS user account for Koha's database.
330 =item INSTALL_ZEBRA
332 Whether to install Zebra configuration files and data
333 directories.
335 =item ZEBRA_MARC_FORMAT
337 Specifies format of MARC records to be indexed by Zebra.
339 =item ZEBRA_LANGUAGE
341 Specifies primary language of records that will be 
342 indexed by Zebra.
344 =item ZEBRA_USER
346 Internal Zebra user account for the index.
348 =item ZEBRA_PASS
350 Internal Zebra user account's password.
352 =item KOHA_USER
354 System user account that will own Koha's files.
356 =item KOHA_GROUP
358 System group that will own Koha's files.
360 =back
362 =cut
364 # default configuration options
365 my %config_defaults = (
366   'DB_TYPE'           => 'mysql',
367   'DB_HOST'           => 'localhost',
368   'DB_NAME'           => 'koha',    
369   'DB_USER'           => 'kohaadmin',
370   'DB_PASS'           => 'katikoan',
371   'INSTALL_ZEBRA'     => 'yes',
372   'INSTALL_SRU'       => 'yes',
373   'AUTH_INDEX_MODE'   => 'grs1',
374   'ZEBRA_MARC_FORMAT' => 'marc21',
375   'ZEBRA_LANGUAGE'    => 'en',
376   'ZEBRA_USER'        => 'kohauser',
377   'ZEBRA_PASS'        => 'zebrastripes',
378   'ZEBRA_SRU_HOST'    => 'localhost',
379   'ZEBRA_SRU_BIBLIOS_PORT'    => '9998',
380   'ZEBRA_SRU_AUTHORITIES_PORT'    => '9999',
381   'KOHA_USER'         => 'koha',
382   'KOHA_GROUP'        => 'koha',
385 # set some default configuratio options based on OS
386 # more conditions need to be added for other OS's
387 # this should probably also incorporate usage of Win32::GetOSName() and/or Win32::GetOSVersion()
388 # to allow for more granular decisions based on which Win32 platform
390 warn "Your platform appears to be $^O.\n" if $DEBUG;
392 if ( $^O eq 'MSWin32' ) {
393         # Most Unix2Win32 ports seem to poke everything into the Program Files directory
394         # this could be changed to put some files (ie. libraries) into system32, etc.
395         $config_defaults{'INSTALL_MODE'} = 'single';
396         $config_defaults{'INSTALL_BASE'} = 'c:/progra~1/koha';  # Use 8.3 names to be safe...
398 elsif ( $^O eq 'cygwin' ) {
399         # Most Unix2Win32 ports seem to poke everything into the Program Files directory
400         # this could be changed to put some files (ie. libraries) into system32, etc.
401         $config_defaults{'INSTALL_MODE'} = 'single';
402         $config_defaults{'INSTALL_BASE'} = 'c:/progra~1/koha';  # Use 8.3 names to be safe...
404 else {
405         $config_defaults{'INSTALL_MODE'} = 'standard';
406         $config_defaults{'INSTALL_BASE'} = '/usr/share/koha';
409 # valid values for certain configuration options
410 my %valid_config_values = (
411   'INSTALL_MODE'  => { 'standard' => 1, 'single' => 1, 'dev' => 1 },
412   'DB_TYPE' => { 'mysql' => 1, 'Pg' => 1 },
413   'INSTALL_ZEBRA' => { 'yes' => 1, 'no' => 1 },
414   'INSTALL_SRU' => { 'yes' => 1, 'no' => 1 },
415   'AUTH_INDEX_MODE' => { 'grs1' => 1, 'dom' => 1 },
416   'ZEBRA_MARC_FORMAT' => { 'marc21' => 1, 'unimarc' => 1 }, # FIXME should generate from contents of distributation
417   'ZEBRA_LANGUAGE'    => { 'en' => 1, 'fr' => 1 }, # FIXME should generate from contents of distribution
420 my %config = get_configuration(\%config_defaults, \%valid_config_values);
421 my ($target_directories, $skip_directories) = get_target_directories(\%config);
422 display_configuration(\%config, $target_directories);
423 my $file_map = {};
424 get_file_map($target_map, $dirtree, $file_map, $config{'INSTALL_ZEBRA'} eq "yes" ? 1: 0);
426 my $pl_files = {
427       'rewrite-config.PL' => [
428          'blib/KOHA_CONF_DIR/koha-conf.xml',
429          'blib/KOHA_CONF_DIR/koha-httpd.conf'
430          ],
431           'fix-perl-path.PL' => [       # this script ensures the correct shebang line for the platform installed on...
432                  'blib'
433                  ]
436 if ($config{'INSTALL_ZEBRA'} eq "yes") {
437     push @{ $pl_files->{'rewrite-config.PL'} }, (
438         'blib/ZEBRA_CONF_DIR/etc/passwd',
439         'blib/ZEBRA_CONF_DIR/zebra-biblios.cfg',
440         'blib/ZEBRA_CONF_DIR/zebra-authorities.cfg',
441         'blib/ZEBRA_CONF_DIR/zebra-authorities-dom.cfg',
442         'blib/ZEBRA_CONF_DIR/explain-authorities.xml',
443         'blib/ZEBRA_CONF_DIR/explain-biblios.xml',
444         'blib/ZEBRA_CONF_DIR/retrieval-info-auth-grs1.xml',
445         'blib/ZEBRA_CONF_DIR/retrieval-info-auth-dom.xml',
446     );
447     if ($config{'INSTALL_MODE'} ne 'dev') {
448         push @{ $pl_files->{'rewrite-config.PL'} }, (
449             'blib/SCRIPT_DIR/koha-zebra-ctl.sh',
450             'blib/SCRIPT_DIR/koha-zebraqueue-ctl.sh',
451         );
452     }
453     $config{'ZEBRA_AUTH_CFG'} = $config{'AUTH_INDEX_MODE'} eq 'dom' ? 'zebra-authorities-dom.cfg' : 'zebra-authorities.cfg';
454     $config{'AUTH_RETRIEVAL_CFG'} = 
455         $config{'AUTH_INDEX_MODE'} eq 'dom' ? 'retrieval-info-auth-dom.xml' : 'retrieval-info-auth-grs1.xml';
458 if ($config{'INSTALL_MODE'} ne "dev") {
459     push @{ $pl_files->{'rewrite-config.PL'} }, (
460         'blib/PERL_MODULE_DIR/C4/Context.pm',
461         'blib/SCRIPT_DIR/kohalib.pl'
462     );
465 WriteMakefile(
466     NAME => 'koha',
467     #VERSION => strftime('2.9.%Y%m%d%H',gmtime),
468     VERSION_FROM => 'kohaversion.pl',
469     ABSTRACT => 'Award-winning integrated library system (ILS) and Web OPAC',
470     AUTHOR => 'Koha Developers <koha-devel@nongnu.org>',
471     NO_META => 1,
472     PREREQ_PM => {
473 # awaiting package maintainer's use of $VERSION
474 #'Algorithm::CheckDigits' => 0.48,
475 #'Algorithm::CheckDigits::M43_001' => 0.48,
476 'Biblio::EndnoteStyle' => 0.05,
477 'CGI' => 3.15,
478 'CGI::Carp' => 1.29,
479 'CGI::Session' => '4.10',
480 'Class::Factory::Util' => 1.6,
481 'Class::Accessor' => 0.30,
482 'DBD::mysql' => 4.004,
483 'DBI' => 1.53,
484 'Data::ICal' => 0.13,
485 'Data::Dumper' => 2.121_08,
486 'Date::Calc' => 5.4,
487 'Date::ICal' => 1.72,
488 'Date::Manip' => 5.44,
489 'Digest::MD5' => 2.36,
490 'File::Temp' => 0.16,
491 'GD::Barcode::UPCE' => 1.1,
492 'Getopt::Long' => 2.35,
493 'Getopt::Std' => 1.05,
494 'HTML::Template::Pro' => 0.65,
495 'HTTP::Cookies' => 1.39,
496 'HTTP::Request::Common' => 1.26,
497 'LWP::Simple' => 1.41,
498 'LWP::UserAgent' => 2.033,
499 'Lingua::Stem' => 0.82,
500 'List::Util' => 1.18,
501 'List::MoreUtils' => 0.21,
502 'Locale::Language' => 2.07,
503 'MARC::Charset' => 0.98,
504 'MARC::Crosswalk::DublinCore' => 0.02,
505 'MARC::File::XML' => 0.88,
506 'MARC::Record' => 2.00,
507 'MIME::Base64' => 3.07,
508 'MIME::QuotedPrint' => 3.07,
509 'Mail::Sendmail' => 0.79,
510 'Net::LDAP' => 0.33,
511 'Net::LDAP::Filter' => 0.14,
512 'Net::Z3950::ZOOM' => 1.16,
513 'PDF::API2' => 2.000,
514 'PDF::API2::Page' => 2.000,
515 'PDF::API2::Util' => 2.000,
516 'PDF::Reuse' => 0.33,
517 'PDF::Reuse::Barcode' => 0.05,
518 'POE' => 0.9999,
519 'POSIX' => 1.09,
520 'Schedule::At' => 1.06,
521 'Term::ANSIColor' => 1.10,
522 'Test' => 1.25,
523 'Test::Harness' => 2.56,
524 'Test::More' => 0.62,
525 'Text::CSV' => 0.01,
526 'Text::CSV_XS' => 0.32,
527 'Text::Iconv' => 1.7,
528 'Text::Wrap' => 2005.082401,
529 'Time::HiRes' => 1.86,
530 'Time::localtime' => 1.02,
531 'Unicode::Normalize' => 0.32,
532 'XML::Dumper' => 0.81,
533 'XML::LibXML' => 1.59,
534 'XML::LibXSLT' => 1.59,
535 'XML::SAX::ParserFactory' => 1.01,
536 'XML::Simple' => 2.14,
537 'XML::RSS' => 1.31,
538 'YAML::Syck' => 0.71,
539         },
541         # File tree mapping
542         PM => $file_map,
544     # Man pages generated from POD
545     INSTALLMAN1DIR => File::Spec->catdir($target_directories->{'MAN_DIR'}, 'man1'),
546     INSTALLMAN3DIR => File::Spec->catdir($target_directories->{'MAN_DIR'}, 'man3'),
548     PL_FILES => $pl_files,
552 =head1 FUNCTIONS
554 =head2 hashdir
556 This function recurses through the directory structure and builds
557 a hash of hashes containing the structure with arrays holding filenames.
558 This directory hashing routine was taken from BrowserUK @ http://www.perlmonks.org/?node_id=219919
560 =cut
562 sub hashdir{
563     my $dir = shift;
564     opendir my $dh, $dir or die $!;
565     my $tree = {}->{$dir} = {};
566     while( my $file = readdir($dh) ) {
567         next if $file =~ m/^\.{1,2}/ and $file !~ /^\.htaccess/; # .htaccess is a special case
568         my $path = $dir .'/' . $file;
569         $tree->{$file} = hashdir($path), next if -d $path;
570         push @{$tree->{'.'}}, $file;
571     }
572     return $tree;
575 =head2 get_file_map 
577 This function combines the target_map and file hash to
578 map each source file to its destination relative to
579 the set of installation targets.
581 Output will be a hash mapping from each source file
582 to its destination value, like this:
584 'mainpage.pl' => '$(INTRANET_CGI_DIR)/mainpage.pl'
586 =cut
588 sub get_file_map {
589     my $target_map = shift;
590     my $dirtree = shift;
591     my $file_map = shift;
592     my $install_zebra = shift;
593     my $curr_path = @_ ? shift : ['.'];
595     # Traverse the directory tree.
596     # For each file or directory, identify the
597     # most specific match in the target_map
598     foreach my $dir (sort keys %{ $dirtree }) {
599         if ($dir eq '.') {
600             # deal with files in directory
601             foreach my $file (sort @{ $dirtree->{$dir} }) {
602                 my $targetdir = undef;
603                 my $matchlevel = undef;
604                 # first, see if there is a match on this specific
605                 # file in the target map
606                 my $filepath = join("/", @$curr_path, $file);
607                 if (exists $target_map->{$filepath}) {
608                     $targetdir = $target_map->{$filepath};
609                     $matchlevel = scalar(@$curr_path) + 1;
610                 } else {
611                     # no match on the specific file; look for
612                     # a directory match
613                     for (my $i = scalar(@$curr_path) - 1; $i >= 0; $i--)  {
614                         my $dirpath = join("/", @$curr_path[0..$i]);
615                         if (exists $target_map->{$dirpath}) {
616                             $targetdir = $target_map->{$dirpath};
617                             $matchlevel = $i + 1;
618                             last;
619                         }
620                     }
621                 }
622                 if (defined $targetdir) {
623                      _add_to_file_map($file_map, $targetdir, $curr_path, $file, $matchlevel, $install_zebra);
624                 } else {
625                     my $path = join("/", @$curr_path);
626                     print "failed to map: $path/$file\n" if $DEBUG;
627                 }
628             }
629         } else {
630             # dealing with subdirectory
631             push @$curr_path, $dir;
632             get_file_map($target_map, $dirtree->{$dir}, $file_map, $install_zebra, $curr_path);
633             pop @$curr_path;
634         }
635     }
638 sub _add_to_file_map {
639     my $file_map = shift;
640     my $targetdir = shift;
641     my $curr_path = shift;
642     my $file = shift;
643     my $matchlevel = shift;
644     my $install_zebra = shift;
645     my $dest_path = @_ ? shift : $curr_path;
647     # The target can be one of the following:
648     # 1. scalar representing target symbol
649     # 2. hash ref containing target and trimdir keys
650     #
651     # Consequently, this routine traverses this structure,
652     # calling itself recursively, until it deals with
653     # all of the scalar target symbols.
654     if (ref $targetdir eq 'HASH') {
655         my $subtarget = $targetdir->{target};
656         if (exists $targetdir->{trimdir}) {
657             # if we get here, we've specified that
658             # rather than installing the file to
659             # $(TARGET)/matching/dirs/subdirs/file,
660             # we want to install it to
661             # $(TARGET)/subdirs/file
662             #
663             # Note that this the only place where
664             # $matchlevel is used.
665             my @new_dest_path = @$dest_path;
666             if ($targetdir->{trimdir} == -1)  {
667                 splice @new_dest_path, 0, $matchlevel;
668             } else {
669                 splice @new_dest_path, 0, $targetdir->{trimdir};
670             }
671             _add_to_file_map($file_map, $subtarget, $curr_path, $file, $matchlevel, $install_zebra, \@new_dest_path);
672         } else {
673             # actually getting here means that the
674             # target was unnecessarily listed
675             # as a hash, but we'll forgive that
676             _add_to_file_map($file_map, $subtarget, $curr_path, $file, $matchlevel, $install_zebra);
677         }
678     } elsif ($targetdir ne 'NONE' and $targetdir ne '') {
679         my $source = File::Spec->catfile(@$curr_path, $file);
680         my $destination = File::Spec->catfile('blib', $targetdir, @$dest_path, $file);
681         #print "$source => $destination\n"; # DEBUG
682         # quote spaces in file names
683         # FIXME: this is of questionable portability and
684         # probably depends on user's make recognizing this
685         # quoting syntax -- probably better to remove
686         # spaces and shell metacharacters from all file names
687         $source =~ s/ /\\ /g;
688         $destination =~ s/ /\\ /g;
689       
690         $file_map->{$source} = $destination unless (!$install_zebra and $targetdir =~ /ZEBRA/);
691     }
694 =head2 get_configuration
696 This prompts the user for various configuration options.
698 =cut
700 sub get_configuration {
701   my $defaults = shift;
702   my $valid_values = shift;
703   my %config = ();
705   my $msg = q(
706 By default, Koha can be installed in one of three ways:
708 standard: Install files in conformance with the Filesystem
709           Hierarchy Standard (FHS).  This is the default mode
710           and should be used when installing a production
711           Koha system.  On Unix systems, root access is 
712           needed to complete a standard installation.
714 single:   Install files under a single directory.  This option
715           is useful for installing Koha without root access, e.g.,
716           on a web host that allows CGI scripts and MySQL databases
717           but requires the user to keep all files under the user's
718           HOME directory.
720 dev:      Create a set of symbolic links and configuration files to
721           allow Koha to run directly from the source distribution.
722           This mode is useful for developers who want to run
723           Koha from a git clone.
725 Installation mode);
726     $msg .= _add_valid_values_disp('INSTALL_MODE', $valid_values);
727     $config{'INSTALL_MODE'} = _get_value('INSTALL_MODE', $msg, $defaults->{'INSTALL_MODE'}, $valid_values);
729     # set message and default value for INSTALL_BASE
730     # depending on value of INSTALL_MODE
731     my $install_base_default = $defaults->{'INSTALL_BASE'};
732     if ($config{'INSTALL_MODE'} eq 'dev') {
733         $msg = q(
734 Please specify the directory in which to install Koha's
735 active configuration files and (if applicable) the
736 Zebra database.  Koha's CGI scripts and templates will
737 be run from the current directory.
739 Configuration directory:);
740         # FIXME - home directory portability consideration apply
741         $install_base_default = (exists $ENV{'HOME'}) ? "$ENV{'HOME'}/koha-dev" : "$defaults->{'INSTALL_BASE'}-dev";
742     } elsif ($config{'INSTALL_MODE'} eq 'single') {
743         $msg = "\nPlease specify the directory in which to install Koha";
744         # FIXME -- we're assuming under a 'single' mode install
745         # that user will likely want to install under the home
746         # directory.  This is OK in and of itself, but we should
747         # use File::HomeDir to locate the home directory portably.  
748         # This is deferred for now because File::HomeDir is not yet
749         # core.
750                 # --we must also keep this portable to the major OS's -fbcit
751         $install_base_default = (exists $ENV{'HOME'}) ? "$ENV{'HOME'}/koha" : $defaults->{'INSTALL_BASE'};
752     } else {
753         # must be standard
754         $msg = q(
755 Please specify the directory under which most Koha files 
756 will be installed.
758 Note that if you are planning in installing more than 
759 one instance of Koha, you may want to modify the last
760 component of the directory path, which will be used
761 as the package name in the FHS layout.
763 Base installation directory);
764     }
765     $config{'INSTALL_BASE'} = _get_value('INSTALL_BASE', $msg, $install_base_default, $valid_values);
767     $config{'INSTALL_BASE'} = File::Spec->rel2abs($config{'INSTALL_BASE'});
768         print "INSTALL_BASE=$config{'INSTALL_BASE'}\r\n" if $DEBUG;
769     if ($config{'INSTALL_MODE'} eq "standard") {
770         $msg = q(
771 Since you are using the 'standard' install
772 mode, you should run 'make install' as root.
773 However, it is recommended that a non-root
774 user (on Unix and Linux platforms) have 
775 ownership of Koha's files, including the
776 Zebra indexes if applicable.
778 Please specify a user account.  This
779 user account does not need to exist
780 right now, but it needs to exist
781 before you run 'make install'.  Please
782 note that for security reasons, this
783 user should not be the same as the user
784 account Apache runs under.
786 User account);
787         $config{'KOHA_USER'} = _get_value('KOHA_USER', $msg, $defaults->{'KOHA_USER'}, $valid_values);
789         $msg = q(
790 Please specify the group that should own
791 Koha's files.  As above, this group need
792 not exist right now, but should be created
793 before you run 'make install'.
795 Group);
796         $config{'KOHA_GROUP'} = _get_value('KOHA_GROUP', $msg, $defaults->{'KOHA_GROUP'}, $valid_values);
797     }
799     $msg = q(
800 Please specify which database engine you will use
801 to store data in Koha.  The choices are MySQL and
802 PostgreSQL; please note that at the moment
803 PostgreSQL support is highly experimental.
805 DBMS to use);
806     $msg .= _add_valid_values_disp('DB_TYPE', $valid_values);
807     $config{'DB_TYPE'} = _get_value('DB_TYPE', $msg, $defaults->{'DB_TYPE'}, $valid_values);
809     $msg = q(
810 Please specify the name or address of your 
811 database server.  Note that the database 
812 does not have to exist at this point, it
813 can be created after running 'make install'
814 and before you try using Koha for the first time.
816 Database server);
817     $config{'DB_HOST'} = _get_value('DB_HOST', $msg, $defaults->{'DB_HOST'}, $valid_values);
819     $msg = q(
820 Please specify the port used to connect to the
821 DMBS);
822     my $db_port_default = $config{'DB_TYPE'} eq 'mysql' ? '3306' : '5432';
823     $config{'DB_PORT'} = _get_value('DB_PORT', $msg, $db_port_default, $valid_values);
825     $msg = q(
826 Please specify the name of the database to be
827 used by Koha);
828     $config{'DB_NAME'} = _get_value('DB_NAME', $msg, $defaults->{'DB_NAME'}, $valid_values);
830     $msg = q(
831 Please specify the user that owns the database to be
832 used by Koha);
833     $config{'DB_USER'} = _get_value('DB_USER', $msg, $defaults->{'DB_USER'}, $valid_values);
835     $msg = q(
836 Please specify the password of the user that owns the 
837 database to be used by Koha);
838     $config{'DB_PASS'} = _get_value('DB_PASS', $msg, $defaults->{'DB_PASS'}, $valid_values);
840     $msg = q(
841 Koha can use the Zebra search engine for high-performance
842 searching of bibliographic and authority records.  If you
843 have installed the Zebra software and would like to use it,
844 please answer 'yes' to the following question.  Otherwise, 
845 Koha will default to using its internal search engine.
847 Please note that if you choose *NOT* to install Zebra,
848 koha-conf.xml will still contain some references to Zebra
849 settings.  Those references will be ignored by Koha.
851 Install the Zebra configuration files?);
852     $msg .= _add_valid_values_disp('INSTALL_ZEBRA', $valid_values);
853     $config{'INSTALL_ZEBRA'} = _get_value('INSTALL_ZEBRA', $msg, $defaults->{'INSTALL_ZEBRA'}, $valid_values);
855     if ($config{'INSTALL_ZEBRA'} eq 'yes') {
856         $msg = q(
857 Since you've chosen to use Zebra with Koha,
858 you must specify the primary MARC format of the
859 records to be indexed by Zebra.
861 Koha provides Zebra configuration files for MARC 21
862 and UNIMARC.
864 MARC format for Zebra indexing);
865         $msg .= _add_valid_values_disp('ZEBRA_MARC_FORMAT', $valid_values);
866         $config{'ZEBRA_MARC_FORMAT'} = _get_value('ZEBRA_MARC_FORMAT', $msg, $defaults->{'ZEBRA_MARC_FORMAT'}, $valid_values);
867         $msg = q(
868 Koha supplies Zebra configuration files tuned for
869 searching either English (en) or French (fr) MARC
870 records.
872 Primary language for Zebra indexing);
873         $msg .= _add_valid_values_disp('ZEBRA_LANGUAGE', $valid_values);
874         $config{'ZEBRA_LANGUAGE'} = _get_value('ZEBRA_LANGUAGE', $msg, $defaults->{'ZEBRA_LANGUAGE'}, $valid_values);
875    
876         $msg = q(
877 Koha can use one of  two different indexing modes 
878 for the MARC authorities records:
880 grs1 - uses the Zebra GRS-1 filter, available 
881        for legacy support
882 dom  - uses the DOM XML filter; offers improved
883        functionality.
885 Authorities indexing mode);
886         $msg .= _add_valid_values_disp('AUTH_INDEX_MODE', $valid_values);
887         $config{'AUTH_INDEX_MODE'} = _get_value('AUTH_INDEX_MODE', $msg, $defaults->{'AUTH_INDEX_MODE'}, $valid_values);
888        
889         $msg = q(
890 Please specify Zebra database user);
891         $config{'ZEBRA_USER'} = _get_value('ZEBRA_USER', $msg, $defaults->{'ZEBRA_USER'}, $valid_values);
893         $msg = q(
894 Please specify the Zebra database password);
895         $config{'ZEBRA_PASS'} = _get_value('ZEBRA_PASS', $msg, $defaults->{'ZEBRA_PASS'}, $valid_values);
897         $msg = q(
898 Since you've chosen to use Zebra, you can enable the SRU/
899 Z39.50 Server if you so choose, but you must specify a
900 few configuration options for it.
902 Please note that if you choose *NOT* to configure SRU,
903 koha-conf.xml will still contain some references to SRU
904 settings.  Those references will be ignored by Koha.
906 Install the SRU configuration files?);
907         $msg .= _add_valid_values_disp('INSTALL_SRU', $valid_values);
908         $config{'INSTALL_SRU'} = _get_value('INSTALL_SRU', $msg, $defaults->{'INSTALL_SRU'}, $valid_values);
910         if ($config{'INSTALL_SRU'} eq 'yes') {
911             $msg = q(
912 Since you've chosen to configure SRU, you must
913 specify the host and port(s) that the SRU
914 Servers (bibliographic and authority) should run on.
916             $msg = q(
917 SRU Database host?);
918             $config{'ZEBRA_SRU_HOST'} = _get_value('ZEBRA_SRU_HOST', $msg, $defaults->{'ZEBRA_SRU_HOST'}, $valid_values);
920             $msg = q(
921 SRU port for bibliographic data?);
922             $config{'ZEBRA_SRU_BIBLIOS_PORT'} = _get_value('ZEBRA_SRU_BIBLIOS_PORT', $msg, $defaults->{'ZEBRA_SRU_BIBLIOS_PORT'}, $valid_values);
924             $msg = q(
925 SRU port for authority data?);
926             $config{'ZEBRA_SRU_AUTHORITIES_PORT'} = _get_value('ZEBRA_SRU_AUTHORITIES_PORT', $msg, $defaults->{'ZEBRA_SRU_AUTHORITIES_PORT'}, $valid_values);
928         }
929     }
931     print "\n\n";
932     return %config;
935 sub _add_valid_values_disp {
936     my $key = shift;
937     my $valid_values = shift;
938    
939     my $disp = "";
940     if (exists $valid_values->{$key}) {
941         $disp = " (" . join(", ", sort keys %{ $valid_values->{$key} }) . ")";
942     }
943     return $disp;
946 sub _get_value {
947     my $key = shift;
948     my $msg = shift;
949     my $default = shift;
950     my $valid_values = shift;
952     # override default value from environment
953     if (exists $ENV{$key}) {
954         $default = $ENV{$key};
955         $msg .= " (default from environment)";
956     }
958     my $val = prompt($msg, $default);
960     while (exists $valid_values->{$key} and 
961            $val ne $default and
962            not exists $valid_values->{$key}->{$val}) {
963         my $retry_msg = "Value '$val' is not a valid option.\n";
964         $retry_msg .= "Please enter a value";
965         $retry_msg .= _add_valid_values_disp($key, $valid_values);
966         $val = prompt($retry_msg, $default);
967     }
968     return $val;
971 =head2 get_target_directories 
973 Creates a hash mapping from symbols for installation target
974 directories to actual directory paths.
976 Also returns a hash indicating targets for which 
977 files need not be copied -- this is used for the 'dev'
978 mode installation, where some files are installed in place.
980 =cut
982 sub get_target_directories {
983     my $config = shift;
985     my $base = $config->{'INSTALL_BASE'};
986     my $mode = $config->{'INSTALL_MODE'};
988     # get last component of install base directory
989     # to treat as package name
990     my ($volume, $directories, $file) = File::Spec->splitpath($base, 1);
992     my @basedir = File::Spec->splitdir($directories);
994         # for Win32 we need to prepend the volume to the directory path
995         if ( $^O eq 'MSWin32' ) { shift @basedir; unshift @basedir, $volume; }
996         elsif ( $^O eq 'cygwin' ) { shift @basedir; unshift @basedir, 'c:'; }   # in a cygwin environment, $volume is returned empty
998     my $package = pop @basedir;
1001     my %dirmap = ();
1002     my %skipdirs = ();
1003     if ($mode eq 'single') {
1004         $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
1005         $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs', 'intranet-tmpl');
1006         $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs');
1007         $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
1008         $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl');
1009         $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs');
1010         $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
1011         $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
1012         $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
1013         $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
1014         $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
1015         $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
1016         $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
1017         $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
1018         $dirmap{'LOG_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'log');
1019         $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
1020         $dirmap{'ZEBRA_RUN_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
1021     } elsif ($mode eq 'dev') {
1022         my $curdir = File::Spec->rel2abs(File::Spec->curdir());
1023         $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir($curdir);
1024         $skipdirs{'INTRANET_CGI_DIR'} = 1;
1025         $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'intranet-tmpl');
1026         $skipdirs{'INTRANET_TMPL_DIR'} = 1;
1027         $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl');
1028         $skipdirs{'INTRANET_WWW_DIR'} = 1;
1029         $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir($curdir);
1030         $skipdirs{'OPAC_CGI_DIR'} = 1;
1031         $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'opac-tmpl');
1032         $skipdirs{'OPAC_TMPL_DIR'} = 1;
1033         $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl');
1034         $skipdirs{'OPAC_WWW_DIR'} = 1;
1035         $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir($curdir);
1036         $skipdirs{'PERL_MODULE_DIR'} = 1;
1037         $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
1038         $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
1039         $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
1040         $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
1041         $skipdirs{'SCRIPT_DIR'} = 1;
1042         $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
1043         $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
1044         $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
1045         $dirmap{'LOG_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'log');
1046         $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
1047         $dirmap{'ZEBRA_RUN_DIR'} =  File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
1048     } else {
1049         # mode is standard, i.e., 'fhs'
1050         $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
1051         $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs', 'intranet-tmpl');
1052         $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs');
1053         $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
1054         $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl');
1055         $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs');
1056         $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
1057         $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package);
1058         $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package, 'zebradb');
1059         $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
1060         $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
1061         $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
1062         $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
1063         $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lock', $package, 'zebradb');
1064         $dirmap{'LOG_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'log', $package);
1065         $dirmap{'ZEBRA_DATA_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'zebradb');
1066         $dirmap{'ZEBRA_RUN_DIR'} =  File::Spec->catdir(File::Spec->rootdir(), 'var', 'run', $package, 'zebradb');
1067     }
1069     _get_env_overrides(\%dirmap);
1070     _get_argv_overrides(\%dirmap);
1072     return \%dirmap, \%skipdirs;
1075 sub _get_env_overrides {
1076     my $dirmap = shift;
1078     foreach my $key (keys %$dirmap) {
1079         if (exists $ENV{$key}) {
1080             $dirmap->{$key} = $ENV{$key};
1081             print "Setting $key from environment\n";
1082         }
1083     }
1086 sub _get_argv_overrides {
1087     my $dirmap = shift;
1088     
1089     my @new_argv = ();
1090     for (my $i = 0; $i <= $#ARGV; $i++) {
1091         if ($ARGV[$i] =~ /^([^=]+)=([^=]+)$/ and exists $dirmap->{$1}) {
1092             $dirmap->{$1} = $2;
1093         } else {
1094             push @new_argv, $ARGV[$i];
1095         }
1096     }
1097     @ARGV = @new_argv;
1100 sub display_configuration {
1101     my $config = shift;
1102     my $dirmap = shift;
1103     print "\n\nKoha will be installed with the following configuration parameters:\n\n";
1104     foreach my $key (sort keys %$config) {
1105         print sprintf("%-25.25s%s\n", $key, $config->{$key});
1106     }
1108     print "\nand in the following directories:\n\n";
1109     foreach my $key (sort keys %$dirmap) {
1110         print sprintf("%-25.25s%s\n", $key, $dirmap->{$key});
1111     }
1112     print "\n\nTo change any configuration setting, please run\n";
1113     print "perl Makefile.PL again.  To override one of the target\n";
1114     print "directories, you can do so on the command line like this:\n";
1115     print "\nperl Makefile.PL PERL_MODULE_DIR=/usr/share/perl/5.8\n\n";
1116     print "You can also set different default values for parameters\n";
1117     print "or override directory locations by using environment variables.\n";
1118     print "\nFor example:\n\n";
1119     print "export DB_USER=my_koha\n";
1120     print "perl Makefile.PL\n";
1121     print "\nor\n\n";
1122     print "DB_USER=my_koha DOC_DIR=/usr/local/info perl Makefile.PL\n\n";
1125 package MY;
1127 # This will have to be reworked in order to accommodate Win32...
1129 sub test {
1130     my $self = shift;
1131     my $test = $self->SUPER::test(@_);
1132     $test =~ s!\$\(INST_LIB\)!blib/PERL_MODULE_DIR!g;
1134     # set KOHA_CONF 
1135     $test =~ s!\$\(FULLPERLRUN\)!KOHA_CONF=blib/KOHA_CONF_DIR/koha-conf.xml \$(FULLPERLRUN)!g;
1136     return $test;
1139 sub install {
1140     my $self = shift;
1141     my $install = ""; 
1142     # NOTE: we're *not* doing this: my $install = $self->SUPER::install(@_);
1143     # This means that we're completely overriding EU::MM's default
1144     # installation and uninstallation targets.
1146 # If installation is on Win32, we need to do permissions different from *nix
1147     if ( $^O =~ /darwin|linux|cygwin|freebsd/ ) { # this value needs to be verified for each platform and modified accordingly
1148             foreach my $key (sort keys %$target_directories) {
1149                     $install .= qq(
1150 KOHA_INST_$key = blib/$key
1151 KOHA_DEST_$key = $target_directories->{$key}
1152 )                       unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1153                 }
1154                 $install .= qq(
1155 install :: all install_koha set_koha_ownership set_koha_permissions warn_koha_env_vars
1156 \t\$(NOECHO) \$(NOOP)
1158                         $install .= "install_koha ::\n";      
1159                         $install .= "\t\$(NOECHO) umask 022; \$(MOD_INSTALL) \\\n";
1160                         foreach my $key (sort keys %$target_directories) {
1161                                 $install .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n" 
1162                                         unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1163                         }
1164                         $install .= "\t\t\$(INST_MAN1DIR) \$(DESTINSTALLMAN1DIR) \\\n";
1165                         $install .= "\t\t\$(INST_MAN3DIR) \$(DESTINSTALLMAN3DIR)\n";
1167                         $install .= "\n";
1168                         $install .= "set_koha_ownership ::\n";
1169                         if ($config{'INSTALL_MODE'} eq 'standard' and $config{'KOHA_USER'} ne "root") {
1170                                 foreach my $key (sort keys %$target_directories) {
1171                                         $install .= "\t\$(NOECHO) chown -R $config{'KOHA_USER'}:$config{'KOHA_GROUP'} \$(KOHA_DEST_$key)\n"
1172                                                 unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1173                                 }
1174                         } else {
1175                                 $install .= "\t\t\$(NOECHO) \$(NOOP)\n\n";
1176                         }
1178                         $install .= "\n";
1179                         $install .= "set_koha_permissions ::\n";
1180                         # This is necessary because EU::MM installs files
1181                         # as either 0444 or 0555, and we want the owner
1182                         # of Koha's files to have write permission by default.
1183                         foreach my $key (sort keys %$target_directories) {
1184                                 $install .= "\t\$(NOECHO) chmod -R u+w \$(KOHA_DEST_$key)\n"
1185                                         unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1186                         }
1187         }
1188         elsif ($^O eq 'MSWin32' ) {     # On Win32, the install probably needs to be done under the user account koha will be running as...
1189                                                                 # We can attempt some creative things with command line utils such as CACLS which allows permission
1190                                                                 # management from Win32 cmd.exe, but permissions really only apply to NTFS.
1191             foreach my $key (sort keys %$target_directories) {
1192                     $install .= qq(
1193 KOHA_INST_$key = blib/$key
1194 KOHA_DEST_$key = $target_directories->{$key}
1195 )                       unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1196                 }
1197                 $install .= qq(
1198 install :: all install_koha warn_koha_env_vars
1199 \t\$(NOECHO) \$(NOOP)
1201                 $install .= "install_koha ::\n";
1202                 $install .= "\t\$(MOD_INSTALL) \\\n";
1203                 foreach my $key (sort keys %$target_directories) {
1204                         $install .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n" 
1205                                 unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1206                 }
1207         }
1208         $install .= "\n";
1210     $install .= "warn_koha_env_vars ::\n";
1211     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1212     $install .= "\t\$(NOECHO) \$(ECHO) Koha\\'s files have now been installed. \n";
1213     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1214     $install .= "\t\$(NOECHO) \$(ECHO) In order to use Koha\\'s command-line batch jobs,\n";
1215     $install .= "\t\$(NOECHO) \$(ECHO) you should set the following environment variables:\n";
1216     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1217     $install .= "\t\$(NOECHO) \$(ECHO) export KOHA_CONF=\$(KOHA_DEST_KOHA_CONF_DIR)/koha-conf.xml\n";
1218     $install .= "\t\$(NOECHO) \$(ECHO) export PERL5LIB=$target_directories->{'PERL_MODULE_DIR'}\n";
1219     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1220     $install .= "\t\$(NOECHO) \$(ECHO) If installing on a Win32 platform, be sure to use:\n";
1221     $install .= "\t\$(NOECHO) \$(ECHO) 'dmake -x MAXLINELENGTH=300000'\n";
1222     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1223     $install .= "\t\$(NOECHO) \$(ECHO) For other post-installation tasks, please consult the README.\n";
1224     $install .= "\t\$(NOECHO) \$(ECHO)\n";
1226     if ($config{'INSTALL_ZEBRA'} eq "yes") {
1227         $install .= _update_zebra_conf_target();
1228     }
1230     return $install;
1233 =head 2 _update_zebra_conf_target
1235 Add an installation target for updating
1236 Zebra's configuration files.
1238 =cut
1240 sub _update_zebra_conf_target {
1242     my $target = "\nupdate_zebra_conf ::\n";
1243     $target   .= "\tumask 022; \$(MOD_INSTALL) \\\n";
1244     $target .= "\t\t\$(KOHA_INST_ZEBRA_CONF_DIR) \$(KOHA_DEST_ZEBRA_CONF_DIR) \n";
1246     return $target;
1249 sub postamble {
1250     # put directory mappings into Makefile
1251     # so that Make will export as environment
1252     # variables -- this is for the use of
1253     # rewrite-confg.PL
1255     # quote '$' in the two password parameters
1256     my %config = %config;
1257     $config{'DB_PASS'} =~ s/\$/\$\$/g;
1258     if ($config{'INSTALL_ZEBRA'} eq "yes") {
1259         $config{'ZEBRA_PASS'} =~ s/\$/\$\$/g;
1260     }
1262         # Hereagain, we must alter syntax per platform...
1263         if ( $^O eq 'MSWin32' ) {
1264                 # NOTE: it is imperative that there be no whitespaces in ENV=value...
1265                 my $env = join("\n", map { "__${_}__=$target_directories->{$_}" } keys %$target_directories); 
1266                 $env .= "\n\n";
1267                 $env .= join("\n", map { "__${_}__=$config{$_}" } keys %config);
1268                 return "$env\n";
1269         }
1270     else {
1271                 my $env = join("\n", map { "export __${_}__ := $target_directories->{$_}" } keys %$target_directories); 
1272                 $env .= "\n\n";
1273                 $env .= join("\n", map { "export __${_}__ := $config{$_}" } keys %config);
1274                 return "$env\n";
1275         }
1279 __END__
1282 =head1 SEE ALSO
1284 ExtUtils::MakeMaker(3)
1286 =head1 AUTHORS
1288 MJ Ray mjr at phonecoop.coop
1289 Galen Charlton galen.charlton at liblime.com
1291 =cut
1292 FIXME: deal with .htaccess