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
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
24 use ExtUtils::MakeMaker;
30 die "perl 5.6.1 or later required" unless ($] >= 5.006001);
32 # Hash up directory structure & files beginning with the directory we were called from (should be the base of koha)...
34 my $dirtree = hashdir('.');
39 Makefile.PL - Koha packager and installer
43 =head2 BASIC INSTALLATION
49 =head2 PACKAGING RELEASE TARBALLS
60 This is a packager and installer that uses
61 ExtUtils::MakeMaker, which is fairly common
63 As well as building tar or zip files
64 and installing with the above commands,
65 it allows us to check pre-requisites
66 and generate configuration files.
70 =head2 NAME, VERSION_FROM, ABSTRACT, AUTHOR
72 Basic metadata about this software.
76 Suppress generation of META.yml file.
80 Hash of perl modules and versions required.
88 This is a hash of PL scripts to run after installation and
89 the files to ask them to generate.
90 Maybe use the values from CONFIGURE
91 to generate initial configuration files in future.
97 This is a hash mapping directories and files in the
98 source tree to installation target directories. The rules
103 =item If a directory or file is specified, it and its
104 contents will be copied to the installation target directory.
106 =item If a subdirectory of a mapped directory is specified,
107 its target overrides the parent's target for that subdirectory.
109 =item The value of each map entry may either be a scalar containing
110 one target or a reference to a hash containing 'target' and 'trimdir'
113 =item Any files at the top level of the source tree that are
114 not included in the map will not be installed.
116 =item Any directories at the top level of the source tree
117 that are not included in the map will be installed in
118 INTRANET_CGI_DIR. This is a sensible default given the
119 current organization of the source tree, but (FIXME) it
120 would be better to reorganize the source tree to better
121 match the installation system, to allow adding new directories
122 without having to adjust Makefile.PL each time. The idea
123 is to make the C<$target_map> hash as minimal as possible.
127 The permitted installation targets are:
131 =item INTRANET_CGI_DIR
133 CGI scripts for intranet (staff) interface.
135 =item INTRANET_TMPL_DIR
137 HTML templates for the intranet interface.
139 =item INTRANET_WWW_DIR
141 HTML files, images, etc. for DocumentRoot for the intranet interface.
145 CGI scripts for OPAC (public) interface.
149 HTML templates for the OPAC interface.
153 HTML files, images, etc. for DocumentRoot for the OPAC interface.
155 =item PERL_MODULE_DIR
157 Perl modules (at present just the C4 modules) that are intimately
158 tied to Koha. Depending on the installation options, these
159 may or may not be installed one of the standard directories
160 in Perl's default @LIB.
164 Directory for Koha configuration files.
168 Directory for Zebra configuration files.
172 Directory for Zebra's lock files.
176 Directory for Zebra's data files.
180 Directory for Zebra's UNIX-domain sockets.
184 Directory for for miscellaenous scripts, among other
185 things the translation toolkit and RSS feed tools.
189 Directory for command-line scripts and daemons.
193 Directory for man pages created from POD -- will mostly
194 contain information of interest to Koha developers.
198 Directory for Koha documentation accessed from the
199 command-line, e.g., READMEs.
203 Directory for Apache and Zebra logs produced by Koha.
207 This is a dummy target used to explicitly state
208 that a given file or directory is not to be installed.
209 This is used either for parts of the installer itself
210 or for development tools that are not applicable to a
211 production installation.
218 './about.pl' => 'INTRANET_CGI_DIR',
219 './acqui' => 'INTRANET_CGI_DIR',
220 './admin' => 'INTRANET_CGI_DIR',
221 './authorities' => 'INTRANET_CGI_DIR',
222 './C4' => 'PERL_MODULE_DIR',
223 './C4/SIP/t' => 'NONE',
224 './C4/SIP/koha_test' => 'NONE',
225 './C4/tests' => 'NONE',
226 './catalogue' => 'INTRANET_CGI_DIR',
227 './cataloguing' => 'INTRANET_CGI_DIR',
228 './changelanguage.pl' => 'INTRANET_CGI_DIR',
229 './check_sysprefs.pl' => 'NONE',
230 './circ' => 'INTRANET_CGI_DIR',
231 './edithelp.pl' => 'INTRANET_CGI_DIR',
232 './etc' => { target => 'KOHA_CONF_DIR', trimdir => -1 },
233 './etc/zebradb' => { target => 'ZEBRA_CONF_DIR', trimdir => -1 },
234 './help.pl' => 'INTRANET_CGI_DIR',
235 './installer-CPAN.pl' => 'NONE',
236 './installer' => 'INTRANET_CGI_DIR',
237 './koha-tmpl/errors' => {target => 'INTRANET_CGI_DIR', trimdir => 2},
238 './koha-tmpl/intranet-tmpl' => {target => 'INTRANET_TMPL_DIR', trimdir => -1},
239 './koha-tmpl/opac-tmpl' => {target => 'OPAC_TMPL_DIR', trimdir => -1},
240 './kohaversion.pl' => 'INTRANET_CGI_DIR',
241 './labels' => 'INTRANET_CGI_DIR',
242 './mainpage.pl' => 'INTRANET_CGI_DIR',
243 './Makefile.PL' => 'NONE',
244 './MANIFEST.SKIP' => 'NONE',
245 './members' => 'INTRANET_CGI_DIR',
246 './misc' => { target => 'SCRIPT_DIR', trimdir => -1 },
247 './misc/info' => { target => 'DOC_DIR', trimdir => 2 },
248 './misc/release notes' => { target => 'DOC_DIR', trimdir => 2 },
249 './misc/translator' => { target => 'MISC_DIR', trimdir => 2 },
250 './misc/installer_devel_notes' => 'NONE',
251 './opac' => 'OPAC_CGI_DIR',
252 './README.txt' => 'NONE',
253 './reports' => 'INTRANET_CGI_DIR',
254 './reserve' => 'INTRANET_CGI_DIR',
255 './reviews' => 'INTRANET_CGI_DIR',
256 './rewrite-config.PL' => 'NONE',
257 './reviews' => 'INTRANET_CGI_DIR',
258 './rss' => 'MISC_DIR',
259 './serials' => 'INTRANET_CGI_DIR',
261 './skel/var/log/koha' => { target => 'LOG_DIR', trimdir => -1 },
262 './skel/var/run/koha/zebradb' => { target => 'ZEBRA_RUN_DIR', trimdir => -1 },
263 './skel/var/lock/koha/zebradb/authorities' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
264 './skel/var/lib/koha/zebradb/authorities/key' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
265 './skel/var/lib/koha/zebradb/authorities/register' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
266 './skel/var/lib/koha/zebradb/authorities/shadow' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
267 './skel/var/lib/koha/zebradb/authorities/tmp' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
268 './skel/var/lock/koha/zebradb/biblios' => { target => 'ZEBRA_LOCK_DIR', trimdir => 6 },
269 './skel/var/lib/koha/zebradb/biblios/key' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
270 './skel/var/lib/koha/zebradb/biblios/register' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
271 './skel/var/lib/koha/zebradb/biblios/shadow' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
272 './skel/var/lib/koha/zebradb/biblios/tmp' => { target => 'ZEBRA_DATA_DIR', trimdir => 6 },
273 './sms' => 'INTRANET_CGI_DIR',
274 './suggestion' => 'INTRANET_CGI_DIR',
275 './svc' => 'INTRANET_CGI_DIR',
277 './tmp' => 'NONE', # FIXME need to determine whether
278 # Koha generates any persistent temp files
279 # that should go in /var/tmp/koha
280 './tools' => 'INTRANET_CGI_DIR',
281 './virtualshelves' => 'INTRANET_CGI_DIR',
282 # ignore files and directories created by the install itself
283 './pm_to_blib' => 'NONE',
287 =head1 CONFIGURATION OPTIONS
289 The following configuration options are used by the installer.
295 Specifies whether installation will be FHS-compliant (default,
296 assumes user has root), put everything under
297 a single directory (for users installing on a web host
298 that allows CGI scripts and a MySQL database but not root
299 access), or development (for a developer who wants to run
300 Koha from a git clone with no fuss).
304 Directory under which most components will go. Default
305 value will vary depending on INSTALL_MODE.
309 Type of DBMS (e.g., mysql or Pg).
317 Port that DBMS server is listening on.
321 Name of the DBMS database for Koha.
325 Name of DBMS user account for Koha's database.
329 Pasword of DMBS user account for Koha's database.
333 Whether to install Zebra configuration files and data
336 =item ZEBRA_MARC_FORMAT
338 Specifies format of MARC records to be indexed by Zebra.
342 Specifies primary language of records that will be
347 Internal Zebra user account for the index.
351 Internal Zebra user account's password.
355 System user account that will own Koha's files.
359 System group that will own Koha's files.
365 # default configuration options
366 my %config_defaults = (
367 'DB_TYPE' => 'mysql',
368 'DB_HOST' => 'localhost',
370 'DB_USER' => 'kohaadmin',
371 'DB_PASS' => 'katikoan',
372 'INSTALL_ZEBRA' => 'yes',
373 'ZEBRA_MARC_FORMAT' => 'marc21',
374 'ZEBRA_LANGUAGE' => 'en',
375 'ZEBRA_USER' => 'kohauser',
376 'ZEBRA_PASS' => 'zebrastripes',
377 'KOHA_USER' => 'koha',
378 'KOHA_GROUP' => 'koha',
381 # set some default configuratio options based on OS
382 # more conditions need to be added for other OS's
383 # this should probably also incorporate usage of Win32::GetOSName() and/or Win32::GetOSVersion()
384 # to allow for more granular decisions based on which Win32 platform
386 warn "Your platform appears to be $^O.\n" if $DEBUG;
388 if ( $^O eq 'MSWin32' ) {
389 # Most Unix2Win32 ports seem to poke everything into the Program Files directory
390 # this could be changed to put some files (ie. libraries) into system32, etc.
391 $config_defaults{'INSTALL_MODE'} = 'single';
392 $config_defaults{'INSTALL_BASE'} = 'c:/progra~1/koha'; # Use 8.3 names to be safe...
394 elsif ( $^O eq 'cygwin' ) {
395 # Most Unix2Win32 ports seem to poke everything into the Program Files directory
396 # this could be changed to put some files (ie. libraries) into system32, etc.
397 $config_defaults{'INSTALL_MODE'} = 'single';
398 $config_defaults{'INSTALL_BASE'} = 'c:/progra~1/koha'; # Use 8.3 names to be safe...
401 $config_defaults{'INSTALL_MODE'} = 'standard';
402 $config_defaults{'INSTALL_BASE'} = '/usr/share/koha';
405 # valid values for certain configuration options
406 my %valid_config_values = (
407 'INSTALL_MODE' => { 'standard' => 1, 'single' => 1, 'dev' => 1 },
408 'DB_TYPE' => { 'mysql' => 1, 'Pg' => 1 },
409 'INSTALL_ZEBRA' => { 'yes' => 1, 'no' => 1 },
410 'ZEBRA_MARC_FORMAT' => { 'marc21' => 1, 'unimarc' => 1 }, # FIXME should generate from contents of distributation
411 'ZEBRA_LANGUAGE' => { 'en' => 1, 'fr' => 1 }, # FIXME should generate from contents of distribution
414 my %config = get_configuration(\%config_defaults, \%valid_config_values);
415 my ($target_directories, $skip_directories) = get_target_directories(\%config);
416 display_configuration(\%config, $target_directories);
418 get_file_map($target_map, $dirtree, $file_map, $config{'INSTALL_ZEBRA'} eq "yes" ? 1: 0);
421 'rewrite-config.PL' => [
422 'blib/KOHA_CONF_DIR/koha-conf.xml',
423 'blib/KOHA_CONF_DIR/koha-httpd.conf',
427 if ($config{'INSTALL_ZEBRA'} eq "yes") {
428 push @{ $pl_files->{'rewrite-config.PL'} }, (
429 'blib/ZEBRA_CONF_DIR/etc/passwd',
430 'blib/ZEBRA_CONF_DIR/zebra-biblios.cfg',
431 'blib/ZEBRA_CONF_DIR/zebra-authorities.cfg'
435 if ($config{'INSTALL_MODE'} ne "dev") {
436 push @{ $pl_files->{'rewrite-config.PL'} }, (
437 'blib/PERL_MODULE_DIR/C4/Context.pm',
438 'blib/SCRIPT_DIR/kohalib.pl'
444 #VERSION => strftime('2.9.%Y%m%d%H',gmtime),
445 VERSION_FROM => 'kohaversion.pl',
446 ABSTRACT => 'Award-winning integrated library system (ILS) and Web OPAC',
447 AUTHOR => 'Koha Developers <koha-devel@nongnu.org>',
450 'Algorithm::CheckDigits' => 0.48,
451 'Biblio::EndnoteStyle' => 0.05,
454 'CGI::Session' => '4.10',
455 'Class::Factory::Util' => 1.7,
456 'Class::Accessor' => 0.30,
457 'DBD::mysql' => 3.0008,
459 'Data::ICal' => 0.13,
460 'Data::Dumper' => 2.121_08,
462 'Date::ICal' => 1.72,
463 'Date::Manip' => 5.44,
464 'Digest::MD5' => 2.36,
465 'File::Temp' => 0.16,
466 'GD::Barcode::UPCE' => 1.1,
467 'Getopt::Long' => 2.35,
468 'Getopt::Std' => 1.05,
469 'HTML::Template::Pro' => 0.65,
470 'HTTP::Cookies' => 1.39,
471 'HTTP::Request::Common' => 1.26,
472 'LWP::Simple' => 1.41,
473 'LWP::UserAgent' => 2.033,
474 'Lingua::Stem' => 0.82,
475 'List::Util' => 1.18,
476 'List::MoreUtils' => 0.22,
477 'Locale::Language' => 2.07,
478 'MARC::Charset' => 0.98,
479 'MARC::Crosswalk::DublinCore' => 0.02,
480 'MARC::File::XML' => 0.88,
481 'MARC::Record' => 2.00,
482 'MIME::Base64' => 3.07,
483 'MIME::QuotedPrint' => 3.07,
484 'Mail::Sendmail' => 0.79,
486 'Net::LDAP::Filter' => 0.34,
487 'Net::Z3950::ZOOM' => 1.16,
488 'PDF::API2' => 2.000,
489 'PDF::API2::Page' => 2.000,
490 'PDF::API2::Util' => 2.000,
491 'PDF::Reuse' => 0.33,
492 'PDF::Reuse::Barcode' => 0.05,
495 'Schedule::At' => 1.06,
496 'Term::ANSIColor' => 1.10,
498 'Test::Harness' => 2.56,
499 'Test::More' => 0.62,
501 'Text::CSV_XS' => 0.32,
502 'Text::Wrap' => 2005.082401,
503 'Time::HiRes' => 1.86,
504 'Time::localtime' => 1.02,
505 'Unicode::Normalize' => 0.32,
506 'XML::Dumper' => 0.81,
507 'XML::LibXML' => 1.59,
508 'XML::LibXSLT' => 1.63,
509 'XML::SAX::ParserFactory' => 1.01,
510 'XML::Simple' => 2.14,
517 # Man pages generated from POD
518 INSTALLMAN1DIR => File::Spec->catdir($target_directories->{'MAN_DIR'}, 'man1'),
519 INSTALLMAN3DIR => File::Spec->catdir($target_directories->{'MAN_DIR'}, 'man3'),
521 PL_FILES => $pl_files,
529 This function recurses through the directory structure and builds
530 a hash of hashes containing the structure with arrays holding filenames.
531 This directory hashing routine was taken from BrowserUK @ http://www.perlmonks.org/?node_id=219919
537 opendir my $dh, $dir or die $!;
538 my $tree = {}->{$dir} = {};
539 while( my $file = readdir($dh) ) {
540 next if $file =~ m/^\.{1,2}/ and $file !~ /^\.htaccess/; # .htaccess is a special case
541 my $path = $dir .'/' . $file;
542 $tree->{$file} = hashdir($path), next if -d $path;
543 push @{$tree->{'.'}}, $file;
550 This function combines the target_map and file hash to
551 map each source file to its destination relative to
552 the set of installation targets.
554 Output will be a hash mapping from each source file
555 to its destination value, like this:
557 'mainpage.pl' => '$(INTRANET_CGI_DIR)/mainpage.pl'
562 my $target_map = shift;
564 my $file_map = shift;
565 my $install_zebra = shift;
566 my $curr_path = @_ ? shift : ['.'];
568 # Traverse the directory tree.
569 # For each file or directory, identify the
570 # most specific match in the target_map
571 foreach my $dir (sort keys %{ $dirtree }) {
573 # deal with files in directory
574 foreach my $file (sort @{ $dirtree->{$dir} }) {
575 my $targetdir = undef;
576 my $matchlevel = undef;
577 # first, see if there is a match on this specific
578 # file in the target map
579 my $filepath = join("/", @$curr_path, $file);
580 if (exists $target_map->{$filepath}) {
581 $targetdir = $target_map->{$filepath};
582 $matchlevel = scalar(@$curr_path) + 1;
584 # no match on the specific file; look for
586 for (my $i = scalar(@$curr_path) - 1; $i >= 0; $i--) {
587 my $dirpath = join("/", @$curr_path[0..$i]);
588 if (exists $target_map->{$dirpath}) {
589 $targetdir = $target_map->{$dirpath};
590 $matchlevel = $i + 1;
595 if (defined $targetdir) {
596 _add_to_file_map($file_map, $targetdir, $curr_path, $file, $matchlevel, $install_zebra);
598 my $path = join("/", @$curr_path);
599 print "failed to map: $path/$file\n" if $DEBUG;
603 # dealing with subdirectory
604 push @$curr_path, $dir;
605 get_file_map($target_map, $dirtree->{$dir}, $file_map, $install_zebra, $curr_path);
611 sub _add_to_file_map {
612 my $file_map = shift;
613 my $targetdir = shift;
614 my $curr_path = shift;
616 my $matchlevel = shift;
617 my $install_zebra = shift;
618 my $dest_path = @_ ? shift : $curr_path;
620 # The target can be one of the following:
621 # 1. scalar representing target symbol
622 # 2. hash ref containing target and trimdir keys
624 # Consequently, this routine traverses this structure,
625 # calling itself recursively, until it deals with
626 # all of the scalar target symbols.
627 if (ref $targetdir eq 'HASH') {
628 my $subtarget = $targetdir->{target};
629 if (exists $targetdir->{trimdir}) {
630 # if we get here, we've specified that
631 # rather than installing the file to
632 # $(TARGET)/matching/dirs/subdirs/file,
633 # we want to install it to
634 # $(TARGET)/subdirs/file
636 # Note that this the only place where
637 # $matchlevel is used.
638 my @new_dest_path = @$dest_path;
639 if ($targetdir->{trimdir} == -1) {
640 splice @new_dest_path, 0, $matchlevel;
642 splice @new_dest_path, 0, $targetdir->{trimdir};
644 _add_to_file_map($file_map, $subtarget, $curr_path, $file, $matchlevel, $install_zebra, \@new_dest_path);
646 # actually getting here means that the
647 # target was unnecessarily listed
648 # as a hash, but we'll forgive that
649 _add_to_file_map($file_map, $subtarget, $curr_path, $file, $matchlevel, $install_zebra);
651 } elsif ($targetdir ne 'NONE' and $targetdir ne '') {
652 my $source = File::Spec->catfile(@$curr_path, $file);
653 my $destination = File::Spec->catfile('blib', $targetdir, @$dest_path, $file);
654 #print "$source => $destination\n"; # DEBUG
655 # quote spaces in file names
656 # FIXME: this is of questionable portability and
657 # probably depends on user's make recognizing this
658 # quoting syntax -- probably better to remove
659 # spaces and shell metacharacters from all file names
660 $source =~ s/ /\\ /g;
661 $destination =~ s/ /\\ /g;
663 $file_map->{$source} = $destination unless (!$install_zebra and $targetdir =~ /ZEBRA/);
667 =head2 get_configuration_options
669 This prompts the user for various configuration options.
673 sub get_configuration {
674 my $defaults = shift;
675 my $valid_values = shift;
679 By default, Koha can be installed in one of three ways:
681 standard: Install files in conformance with the Filesystem
682 Hierarchy Standard (FHS). This is the default mode
683 and should be used when installing a production
684 Koha system. On Unix systems, root access is
685 needed to complete a standard installation.
687 single: Install files under a single directory. This option
688 is useful for installing Koha without root access, e.g.,
689 on a web host that allows CGI scripts and MySQL databases
690 but requires the user to keep all files under the user's
693 dev: Create a set of symbolic links and configuration files to
694 allow Koha to run directly from the source distribution.
695 This mode is useful for developers who want to run
696 Koha from a git clone.
699 $msg .= _add_valid_values_disp('INSTALL_MODE', $valid_values);
700 $config{'INSTALL_MODE'} = _get_value('INSTALL_MODE', $msg, $defaults->{'INSTALL_MODE'}, $valid_values);
702 # set message and default value for INSTALL_BASE
703 # depending on value of INSTALL_MODE
704 my $install_base_default = $defaults->{'INSTALL_BASE'};
705 if ($config{'INSTALL_MODE'} eq 'dev') {
707 Please specify the directory in which to install Koha's
708 active configuration files and (if applicable) the
709 Zebra database. Koha's CGI scripts and templates will
710 be run from the current directory.
712 Configuration directory:);
713 # FIXME - home directory portability consideration apply
714 $install_base_default = (exists $ENV{'HOME'}) ? "$ENV{'HOME'}/koha-dev" : "$defaults->{'INSTALL_BASE'}-dev";
715 } elsif ($config{'INSTALL_MODE'} eq 'single') {
716 $msg = "\nPlease specify the directory in which to install Koha";
717 # FIXME -- we're assuming under a 'single' mode install
718 # that user will likely want to install under the home
719 # directory. This is OK in and of itself, but we should
720 # use File::HomeDir to locate the home directory portably.
721 # This is deferred for now because File::HomeDir is not yet
723 # --we must also keep this portable to the major OS's -fbcit
724 $install_base_default = (exists $ENV{'HOME'}) ? "$ENV{'HOME'}/koha" : $defaults->{'INSTALL_BASE'};
728 Please specify the directory under which most Koha files
731 Note that if you are planning in installing more than
732 one instance of Koha, you may want to modify the last
733 component of the directory path, which will be used
734 as the package name in the FHS layout.
736 Base installation directory);
738 $config{'INSTALL_BASE'} = _get_value('INSTALL_BASE', $msg, $install_base_default, $valid_values);
740 $config{'INSTALL_BASE'} = File::Spec->rel2abs($config{'INSTALL_BASE'});
741 print "INSTALL_BASE=$config{'INSTALL_BASE'}\r\n" if $DEBUG;
742 if ($config{'INSTALL_MODE'} eq "standard") {
744 Since you are using the 'standard' install
745 mode, you should run 'make install' as root.
746 However, it is recommended that a non-root
747 user (on Unix and Linux platforms) have
748 ownership of Koha's files, including the
749 Zebra indexes if applicable.
751 Please specify a user account. This
752 user account does not need to exist
753 right now, but it needs to exist
754 before you run 'make install'. Please
755 note that for security reasons, this
756 user should not be the same as the user
757 account Apache runs under.
760 $config{'KOHA_USER'} = _get_value('KOHA_USER', $msg, $defaults->{'KOHA_USER'}, $valid_values);
763 Please specify the group that should own
764 Koha's files. As above, this group need
765 not exist right now, but should be created
766 before you run 'make install'.
769 $config{'KOHA_GROUP'} = _get_value('KOHA_GROUP', $msg, $defaults->{'KOHA_GROUP'}, $valid_values);
773 Please specify which database engine you will use
774 to store data in Koha. The choices are MySQL and
775 PostgreSQL; please note that at the moment
776 PostgreSQL support is highly experimental.
779 $msg .= _add_valid_values_disp('DB_TYPE', $valid_values);
780 $config{'DB_TYPE'} = _get_value('DB_TYPE', $msg, $defaults->{'DB_TYPE'}, $valid_values);
783 Please specify the name or address of your
784 database server. Note that the database
785 does not have to exist at this point, it
786 can be created after running 'make install'
787 and before you try using Koha for the first time.
790 $config{'DB_HOST'} = _get_value('DB_HOST', $msg, $defaults->{'DB_HOST'}, $valid_values);
793 Please specify the port used to connect to the
795 my $db_port_default = $config{'DB_TYPE'} eq 'mysql' ? '3306' : '5432';
796 $config{'DB_PORT'} = _get_value('DB_PORT', $msg, $db_port_default, $valid_values);
799 Please specify the name of the database to be
801 $config{'DB_NAME'} = _get_value('DB_NAME', $msg, $defaults->{'DB_NAME'}, $valid_values);
804 Please specify the user that owns the database to be
806 $config{'DB_USER'} = _get_value('DB_USER', $msg, $defaults->{'DB_USER'}, $valid_values);
809 Please specify the password of the user that owns the
810 database to be used by Koha);
811 $config{'DB_PASS'} = _get_value('DB_PASS', $msg, $defaults->{'DB_PASS'}, $valid_values);
814 Koha can use the Zebra search engine for high-performance
815 searching of bibliographic and authority records. If you
816 have installed the Zebra software and would like to use it,
817 please answer 'yes' to the following question. Otherwise,
818 Koha will default to using its internal search engine.
820 Please note that if you choose *NOT* to install Zebra,
821 koha-conf.xml will still contain some references to Zebra
822 settings. Those references will be ignored by Koha.
824 Install the Zebra configuration files?);
825 $msg .= _add_valid_values_disp('INSTALL_ZEBRA', $valid_values);
826 $config{'INSTALL_ZEBRA'} = _get_value('INSTALL_ZEBRA', $msg, $defaults->{'INSTALL_ZEBRA'}, $valid_values);
828 if ($config{'INSTALL_ZEBRA'} eq 'yes') {
830 Since you've chosen to use Zebra with Koha,
831 you must specify the primary MARC format of the
832 records to be indexed by Zebra.
834 Koha provides Zebra configuration files for MARC 21
837 MARC format for Zebra indexing);
838 $msg .= _add_valid_values_disp('ZEBRA_MARC_FORMAT', $valid_values);
839 $config{'ZEBRA_MARC_FORMAT'} = _get_value('ZEBRA_MARC_FORMAT', $msg, $defaults->{'ZEBRA_MARC_FORMAT'}, $valid_values);
841 Koha supplies Zebra configuration files tuned for
842 searching either English (en) or French (fr) MARC
845 Primary language for Zebra indexing);
846 $msg .= _add_valid_values_disp('ZEBRA_LANGUAGE', $valid_values);
847 $config{'ZEBRA_LANGUAGE'} = _get_value('ZEBRA_LANGUAGE', $msg, $defaults->{'ZEBRA_LANGUAGE'}, $valid_values);
850 Please specify Zebra database user);
851 $config{'ZEBRA_USER'} = _get_value('ZEBRA_USER', $msg, $defaults->{'ZEBRA_USER'}, $valid_values);
854 Please specify the Zebra database password);
855 $config{'ZEBRA_PASS'} = _get_value('ZEBRA_PASS', $msg, $defaults->{'ZEBRA_PASS'}, $valid_values);
863 sub _add_valid_values_disp {
865 my $valid_values = shift;
868 if (exists $valid_values->{$key}) {
869 $disp = " (" . join(", ", sort keys %{ $valid_values->{$key} }) . ")";
878 my $valid_values = shift;
880 # override default value from environment
881 if (exists $ENV{$key}) {
882 $default = $ENV{$key};
883 $msg .= " (default from environment)";
886 my $val = prompt($msg, $default);
888 while (exists $valid_values->{$key} and
890 not exists $valid_values->{$key}->{$val}) {
891 my $retry_msg = "Value '$val' is not a valid option.\n";
892 $retry_msg .= "Please enter a value";
893 $retry_msg .= _add_valid_values_disp($key, $valid_values);
894 $val = prompt($retry_msg, $default);
899 =head2 get_target_directories
901 Creates a hash mapping from symbols for installation target
902 directories to actual directory paths.
904 Also returns a hash indicating targets for which
905 files need not be copied -- this is used for the 'dev'
906 mode installation, where some files are installed in place.
910 sub get_target_directories {
913 my $base = $config->{'INSTALL_BASE'};
914 my $mode = $config->{'INSTALL_MODE'};
916 # get last component of install base directory
917 # to treat as package name
918 my ($volume, $directories, $file) = File::Spec->splitpath($base, 1);
920 my @basedir = File::Spec->splitdir($directories);
922 # for Win32 we need to prepend the volume to the directory path
923 if ( $^O eq 'MSWin32' ) { shift @basedir; unshift @basedir, $volume; }
924 elsif ( $^O eq 'cygwin' ) { shift @basedir; unshift @basedir, 'c:'; } # in a cygwin environment, $volume is returned empty
926 my $package = pop @basedir;
931 if ($mode eq 'single') {
932 $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
933 $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs', 'intranet-tmpl');
934 $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs');
935 $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
936 $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl');
937 $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs');
938 $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
939 $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
940 $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
941 $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
942 $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
943 $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
944 $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
945 $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
946 $dirmap{'LOG_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'log');
947 $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
948 $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
949 } elsif ($mode eq 'dev') {
950 my $curdir = File::Spec->rel2abs(File::Spec->curdir());
951 $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir($curdir);
952 $skipdirs{'INTRANET_CGI_DIR'} = 1;
953 $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'intranet-tmpl');
954 $skipdirs{'INTRANET_TMPL_DIR'} = 1;
955 $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl');
956 $skipdirs{'INTRANET_WWW_DIR'} = 1;
957 $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir($curdir, 'opac');
958 $skipdirs{'OPAC_CGI_DIR'} = 1;
959 $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'opac-tmpl');
960 $skipdirs{'OPAC_TMPL_DIR'} = 1;
961 $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl');
962 $skipdirs{'OPAC_WWW_DIR'} = 1;
963 $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir($curdir);
964 $skipdirs{'PERL_MODULE_DIR'} = 1;
965 $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
966 $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
967 $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
968 $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
969 $skipdirs{'SCRIPT_DIR'} = 1;
970 $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
971 $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
972 $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
973 $dirmap{'LOG_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'log');
974 $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
975 $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
977 # mode is standard, i.e., 'fhs'
978 $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
979 $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs', 'intranet-tmpl');
980 $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs');
981 $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
982 $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl');
983 $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs');
984 $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
985 $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package);
986 $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package, 'zebradb');
987 $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
988 $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
989 $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
990 $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
991 $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lock', $package, 'zebradb');
992 $dirmap{'LOG_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'log', $package);
993 $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'zebradb');
994 $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'run', $package, 'zebradb');
997 _get_env_overrides(\%dirmap);
998 _get_argv_overrides(\%dirmap);
1000 return \%dirmap, \%skipdirs;
1003 sub _get_env_overrides {
1006 foreach my $key (keys %$dirmap) {
1007 if (exists $ENV{$key}) {
1008 $dirmap->{$key} = $ENV{$key};
1009 print "Setting $key from environment\n";
1014 sub _get_argv_overrides {
1018 for (my $i = 0; $i <= $#ARGV; $i++) {
1019 if ($ARGV[$i] =~ /^([^=]+)=([^=]+)$/ and exists $dirmap->{$1}) {
1022 push @new_argv, $ARGV[$i];
1028 sub display_configuration {
1031 print "\n\nKoha will be installed with the following configuration parameters:\n\n";
1032 foreach my $key (sort keys %$config) {
1033 print sprintf("%-25.25s%s\n", $key, $config->{$key});
1036 print "\nand in the following directories:\n\n";
1037 foreach my $key (sort keys %$dirmap) {
1038 print sprintf("%-25.25s%s\n", $key, $dirmap->{$key});
1040 print "\n\nTo change any configuration setting, please run\n";
1041 print "perl Makefile.PL again. To override one of the target\n";
1042 print "directories, you can do so on the command line like this:\n";
1043 print "\nperl Makefile.PL PERL_MODULE_DIR=/usr/share/perl/5.8\n\n";
1044 print "You can also set different default values for parameters\n";
1045 print "or override directory locations by using environment variables.\n";
1046 print "\nFor example:\n\n";
1047 print "export DB_USER=my_koha\n";
1048 print "perl Makefile.PL\n";
1050 print "DB_USER=my_koha DOC_DIR=/usr/local/info perl Makefile.PL\n\n";
1055 This sub will recurse through a given directory and its subdirectories checking for the existence of a shebang
1056 line in .pl files and replacing it with the correct line for the current OS if needed. It should be called
1057 in a manner similar to 'fixshebang (getcwd())' but may be supplied with any directory in absolute path form.
1062 # NOTE: this might be dressed up a bit with File::Spec since we're using it here already.
1064 opendir my $dh, $dir or die $!;
1065 while( my $file = readdir($dh) ) {
1066 print "Reading $dir contents.\r\n" if $DEBUG;
1067 print "Current item = $file\r\n" if $DEBUG;
1068 # this may be used to exclude any desired files from the scan
1069 if ( $file =~ /shebang|wixgen/ ) { next; }
1070 # handle files... other extensions could be substituted/added if needed
1071 if ( $file =~ /\.pl$/ ) {
1072 my $pathfile =$dir . '/' . $file;
1073 print "Found a perl script named $pathfile\r\n" if $DEBUG;
1074 open FH, '+<', "$pathfile";
1078 my $line = shift @file;
1079 print "Found shebang line: $line\r\n" if $DEBUG;
1080 # FIXME: these conditionals need to be modified to select shebang line based on OS ($^O)
1081 if ( $line =~ /#!c:\\strawberry-perl\\perl\\bin\\perl -w/ ) {
1082 # FIXME: This can probably be done with less of a hack. -fbcit
1088 elsif ( $line =~ /#!\/usr\/bin\/perl/ ) {
1089 print "Re-writing shebang line for $pathfile\r\n";
1090 print FH "#!c:\\strawberry-perl\\perl\\bin\\perl -w\n";
1095 # FIXME: This can probably be done with less of a hack. -fbcit
1102 # handle directories
1103 elsif ( -d ($dir . '/' . $file) && $file !~ /^\.{1,2}/ ) {
1104 my $pathfile = $dir . '/' . $file;
1105 print "Found a subdir named $pathfile\r\n" if $DEBUG;
1106 &fixshebang ($pathfile);
1107 # closedir $dh; # I'm not really sure if this is necessary
1115 # This will have to be reworked in order to accommodate Win32...
1119 my $test = $self->SUPER::test(@_);
1120 $test =~ s!\$\(INST_LIB\)!blib/PERL_MODULE_DIR!g;
1127 # NOTE: we're *not* doing this: my $install = $self->SUPER::install(@_);
1128 # This means that we're completely overriding EU::MM's default
1129 # installation and uninstallation targets.
1131 # If installation is on Win32, we need to do permissions different from *nix
1132 if ( $^O =~ /linux|cygwin/ ) { # this value needs to be verified for each platform and modified accordingly
1133 foreach my $key (sort keys %$target_directories) {
1135 KOHA_INST_$key = blib/$key
1136 KOHA_DEST_$key = $target_directories->{$key}
1137 ) unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1140 install :: all install_koha set_koha_ownership set_koha_permissions warn_koha_env_vars
1141 \t\$(NOECHO) \$(NOOP)
1143 $install .= "install_koha ::\n";
1144 $install .= "\t\$(NOECHO) umask 022; \$(MOD_INSTALL) \\\n";
1145 foreach my $key (sort keys %$target_directories) {
1146 $install .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
1147 unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1149 $install .= "\t\t\$(INST_MAN1DIR) \$(DESTINSTALLMAN1DIR) \\\n";
1150 $install .= "\t\t\$(INST_MAN3DIR) \$(DESTINSTALLMAN3DIR)\n";
1153 $install .= "set_koha_ownership ::\n";
1154 if ($config{'INSTALL_MODE'} eq 'standard' and $config{'KOHA_USER'} ne "root") {
1155 foreach my $key (sort keys %$target_directories) {
1156 $install .= "\t\$(NOECHO) chown -R $config{'KOHA_USER'}:$config{'KOHA_GROUP'} \$(KOHA_DEST_$key)\n"
1157 unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1160 $install .= "\t\t\$(NOECHO) \$(NOOP)\n\n";
1164 $install .= "set_koha_permissions ::\n";
1165 # This is necessary because EU::MM installs files
1166 # as either 0444 or 0555, and we want the owner
1167 # of Koha's files to have write permission by default.
1168 foreach my $key (sort keys %$target_directories) {
1169 $install .= "\t\$(NOECHO) chmod -R u+w \$(KOHA_DEST_$key)\n"
1170 unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1173 elsif ($^O eq 'MSWin32' ) { # On Win32, the install probably needs to be done under the user account koha will be running as...
1174 # We can attempt some creative things with command line utils such as CACLS which allows permission
1175 # management from Win32 cmd.exe, but permissions really only apply to NTFS.
1176 foreach my $key (sort keys %$target_directories) {
1178 KOHA_INST_$key = blib/$key
1179 KOHA_DEST_$key = $target_directories->{$key}
1180 ) unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1183 install :: all install_koha warn_koha_env_vars
1184 \t\$(NOECHO) \$(NOOP)
1186 $install .= "install_koha ::\n";
1187 $install .= "\t\$(MOD_INSTALL) \\\n";
1188 foreach my $key (sort keys %$target_directories) {
1189 $install .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
1190 unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1193 $install .= "\t\t\$(INST_MAN1DIR) \$(DESTINSTALLMAN1DIR) \\\n";
1194 $install .= "\t\t\$(INST_MAN3DIR) \$(DESTINSTALLMAN3DIR)\n";
1198 $install .= "warn_koha_env_vars ::\n";
1199 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1200 $install .= "\t\$(NOECHO) \$(ECHO) Koha\\'s files have now been installed. \n";
1201 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1202 $install .= "\t\$(NOECHO) \$(ECHO) In order to use Koha\\'s command-line batch jobs,\n";
1203 $install .= "\t\$(NOECHO) \$(ECHO) you should set the following environment variables:\n";
1204 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1205 $install .= "\t\$(NOECHO) \$(ECHO) export KOHA_CONF=\$(KOHA_DEST_KOHA_CONF_DIR)/koha-conf.xml\n";
1206 $install .= "\t\$(NOECHO) \$(ECHO) export PERL5LIB=$target_directories->{'PERL_MODULE_DIR'}\n";
1207 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1208 $install .= "\t\$(NOECHO) \$(ECHO) If installing on a Win32 platform, be sure to use:\n";
1209 $install .= "\t\$(NOECHO) \$(ECHO) 'dmake -x MAXLINELENGTH=300000'\n";
1210 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1211 $install .= "\t\$(NOECHO) \$(ECHO) For other post-installation tasks, please consult the README.\n";
1212 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1218 # put directory mappings into Makefile
1219 # so that Make will export as environment
1220 # variables -- this is for the use of
1223 # quote '$' in the two password parameters
1224 my %config = %config;
1225 $config{'DB_PASS'} =~ s/\$/\$\$/g;
1226 $config{'ZEBRA_PASS'} =~ s/\$/\$\$/g;
1228 # Hereagain, we must alter syntax per platform...
1229 if ( $^O =~ /linux|cygwin/ ) {
1230 my $env = join("\n", map { "export __${_}__ := $target_directories->{$_}" } keys %$target_directories);
1232 $env .= join("\n", map { "export __${_}__ := $config{$_}" } keys %config);
1235 elsif ( $^O eq 'MSWin32' ) {
1236 # NOTE: it is imperative that there be no whitespaces in ENV=value...
1237 my $env = join("\n", map { "__${_}__=$target_directories->{$_}" } keys %$target_directories);
1239 $env .= join("\n", map { "__${_}__=$config{$_}" } keys %config);
1249 ExtUtils::MakeMaker(3)
1253 MJ Ray mjr at phonecoop.coop
1254 Galen Charlton galen.charlton at liblime.com
1257 FIXME: deal with .htaccess