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;
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('.');
38 Makefile.PL - Koha packager and installer
42 =head2 BASIC INSTALLATION
48 =head2 PACKAGING RELEASE TARBALLS
59 This is a packager and installer that uses
60 ExtUtils::MakeMaker, which is fairly common
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.
69 =head2 NAME, VERSION_FROM, ABSTRACT, AUTHOR
71 Basic metadata about this software.
75 Suppress generation of META.yml file.
79 Hash of perl modules and versions required.
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.
96 This is a hash mapping directories and files in the
97 source tree to installation target directories. The rules
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'
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.
126 The permitted installation targets are:
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.
144 CGI scripts for OPAC (public) interface.
148 HTML templates for the OPAC interface.
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.
163 Directory for Koha configuration files.
167 Directory for Zebra configuration files.
171 Directory for Zebra's lock files.
175 Directory for Zebra's data files.
179 Directory for Zebra's UNIX-domain sockets.
183 Directory for for miscellaenous scripts, among other
184 things the translation toolkit and RSS feed tools.
188 Directory for command-line scripts and daemons.
192 Directory for man pages created from POD -- will mostly
193 contain information of interest to Koha developers.
197 Directory for Koha documentation accessed from the
198 command-line, e.g., READMEs.
202 Directory for Apache and Zebra logs produced by Koha.
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.
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/info' => { target => 'DOC_DIR', trimdir => 2 },
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',
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',
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',
286 =head1 CONFIGURATION OPTIONS
288 The following configuration options are used by the installer.
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).
303 Directory under which most components will go. Default
304 value will vary depending on INSTALL_MODE.
308 Type of DBMS (e.g., mysql or Pg).
316 Port that DBMS server is listening on.
320 Name of the DBMS database for Koha.
324 Name of DBMS user account for Koha's database.
328 Pasword of DMBS user account for Koha's database.
332 Whether to install Zebra configuration files and data
335 =item ZEBRA_MARC_FORMAT
337 Specifies format of MARC records to be indexed by Zebra.
341 Specifies primary language of records that will be
346 Internal Zebra user account for the index.
350 Internal Zebra user account's password.
354 System user account that will own Koha's files.
358 System group that will own Koha's files.
364 # default configuration options
365 my %config_defaults = (
366 'DB_TYPE' => 'mysql',
367 'DB_HOST' => 'localhost',
369 'DB_USER' => 'kohaadmin',
370 'DB_PASS' => 'katikoan',
371 'INSTALL_ZEBRA' => 'yes',
372 'ZEBRA_MARC_FORMAT' => 'marc21',
373 'ZEBRA_LANGUAGE' => 'en',
374 'ZEBRA_USER' => 'kohauser',
375 'ZEBRA_PASS' => 'zebrastripes',
376 'KOHA_USER' => 'koha',
377 'KOHA_GROUP' => 'koha',
380 # set some default configuratio options based on OS
381 # more conditions need to be added for other OS's
382 # this should probably also incorporate usage of Win32::GetOSName() and/or Win32::GetOSVersion()
383 # to allow for more granular decisions based on which Win32 platform
385 warn "Your platform appears to be $^O.\n" if $DEBUG;
387 if ( $^O eq 'MSWin32' ) {
388 # Most Unix2Win32 ports seem to poke everything into the Program Files directory
389 # this could be changed to put some files (ie. libraries) into system32, etc.
390 $config_defaults{'INSTALL_MODE'} = 'single';
391 $config_defaults{'INSTALL_BASE'} = 'c:/progra~1/koha'; # Use 8.3 names to be safe...
393 elsif ( $^O eq 'cygwin' ) {
394 # Most Unix2Win32 ports seem to poke everything into the Program Files directory
395 # this could be changed to put some files (ie. libraries) into system32, etc.
396 $config_defaults{'INSTALL_MODE'} = 'single';
397 $config_defaults{'INSTALL_BASE'} = 'c:/progra~1/koha'; # Use 8.3 names to be safe...
400 $config_defaults{'INSTALL_MODE'} = 'standard';
401 $config_defaults{'INSTALL_BASE'} = '/usr/share/koha';
404 # valid values for certain configuration options
405 my %valid_config_values = (
406 'INSTALL_MODE' => { 'standard' => 1, 'single' => 1, 'dev' => 1 },
407 'DB_TYPE' => { 'mysql' => 1, 'Pg' => 1 },
408 'INSTALL_ZEBRA' => { 'yes' => 1, 'no' => 1 },
409 'ZEBRA_MARC_FORMAT' => { 'marc21' => 1, 'unimarc' => 1 }, # FIXME should generate from contents of distributation
410 'ZEBRA_LANGUAGE' => { 'en' => 1, 'fr' => 1 }, # FIXME should generate from contents of distribution
413 my %config = get_configuration(\%config_defaults, \%valid_config_values);
414 my ($target_directories, $skip_directories) = get_target_directories(\%config);
415 display_configuration(\%config, $target_directories);
417 get_file_map($target_map, $dirtree, $file_map, $config{'INSTALL_ZEBRA'} eq "yes" ? 1: 0);
420 'rewrite-config.PL' => [
421 'blib/KOHA_CONF_DIR/koha-conf.xml',
422 'blib/KOHA_CONF_DIR/koha-httpd.conf'
424 'fix-perl-path.PL' => [ # this script ensures the correct shebang line for the platform installed on...
429 if ($config{'INSTALL_ZEBRA'} eq "yes") {
430 push @{ $pl_files->{'rewrite-config.PL'} }, (
431 'blib/ZEBRA_CONF_DIR/etc/passwd',
432 'blib/ZEBRA_CONF_DIR/zebra-biblios.cfg',
433 'blib/ZEBRA_CONF_DIR/zebra-authorities.cfg'
437 if ($config{'INSTALL_MODE'} ne "dev") {
438 push @{ $pl_files->{'rewrite-config.PL'} }, (
439 'blib/PERL_MODULE_DIR/C4/Context.pm',
440 'blib/SCRIPT_DIR/kohalib.pl'
446 #VERSION => strftime('2.9.%Y%m%d%H',gmtime),
447 VERSION_FROM => 'kohaversion.pl',
448 ABSTRACT => 'Award-winning integrated library system (ILS) and Web OPAC',
449 AUTHOR => 'Koha Developers <koha-devel@nongnu.org>',
452 'Algorithm::CheckDigits' => 0.48,
453 'Algorithm::CheckDigits::M43_001' => 0.48,
454 'Biblio::EndnoteStyle' => 0.05,
457 'CGI::Session' => '4.10',
458 'Class::Factory::Util' => 1.7,
459 'Class::Accessor' => 0.30,
460 'DBD::mysql' => 3.0008,
462 'Data::ICal' => 0.13,
463 'Data::Dumper' => 2.121_08,
465 'Date::ICal' => 1.72,
466 'Date::Manip' => 5.44,
467 'Digest::MD5' => 2.36,
468 'File::Temp' => 0.16,
469 'GD::Barcode::UPCE' => 1.1,
470 'Getopt::Long' => 2.35,
471 'Getopt::Std' => 1.05,
472 'HTML::Template::Pro' => 0.65,
473 'HTTP::Cookies' => 1.39,
474 'HTTP::Request::Common' => 1.26,
475 'LWP::Simple' => 1.41,
476 'LWP::UserAgent' => 2.033,
477 'Lingua::Stem' => 0.82,
478 'List::Util' => 1.18,
479 'List::MoreUtils' => 0.22,
480 'Locale::Language' => 2.07,
481 'MARC::Charset' => 0.98,
482 'MARC::Crosswalk::DublinCore' => 0.02,
483 'MARC::File::XML' => 0.88,
484 'MARC::Record' => 2.00,
485 'MIME::Base64' => 3.07,
486 'MIME::QuotedPrint' => 3.07,
487 'Mail::Sendmail' => 0.79,
489 'Net::LDAP::Filter' => 0.34,
490 'Net::Z3950::ZOOM' => 1.16,
491 'PDF::API2' => 2.000,
492 'PDF::API2::Page' => 2.000,
493 'PDF::API2::Util' => 2.000,
494 'PDF::Reuse' => 0.33,
495 'PDF::Reuse::Barcode' => 0.05,
498 'Schedule::At' => 1.06,
499 'Term::ANSIColor' => 1.10,
501 'Test::Harness' => 2.56,
502 'Test::More' => 0.62,
504 'Text::CSV_XS' => 0.32,
505 'Text::Wrap' => 2005.082401,
506 'Time::HiRes' => 1.86,
507 'Time::localtime' => 1.02,
508 'Unicode::Normalize' => 0.32,
509 'XML::Dumper' => 0.81,
510 'XML::LibXML' => 1.59,
511 'XML::LibXSLT' => 1.63,
512 'XML::SAX::ParserFactory' => 1.01,
513 'XML::Simple' => 2.14,
520 # Man pages generated from POD
521 INSTALLMAN1DIR => File::Spec->catdir($target_directories->{'MAN_DIR'}, 'man1'),
522 INSTALLMAN3DIR => File::Spec->catdir($target_directories->{'MAN_DIR'}, 'man3'),
524 PL_FILES => $pl_files,
532 This function recurses through the directory structure and builds
533 a hash of hashes containing the structure with arrays holding filenames.
534 This directory hashing routine was taken from BrowserUK @ http://www.perlmonks.org/?node_id=219919
540 opendir my $dh, $dir or die $!;
541 my $tree = {}->{$dir} = {};
542 while( my $file = readdir($dh) ) {
543 next if $file =~ m/^\.{1,2}/ and $file !~ /^\.htaccess/; # .htaccess is a special case
544 my $path = $dir .'/' . $file;
545 $tree->{$file} = hashdir($path), next if -d $path;
546 push @{$tree->{'.'}}, $file;
553 This function combines the target_map and file hash to
554 map each source file to its destination relative to
555 the set of installation targets.
557 Output will be a hash mapping from each source file
558 to its destination value, like this:
560 'mainpage.pl' => '$(INTRANET_CGI_DIR)/mainpage.pl'
565 my $target_map = shift;
567 my $file_map = shift;
568 my $install_zebra = shift;
569 my $curr_path = @_ ? shift : ['.'];
571 # Traverse the directory tree.
572 # For each file or directory, identify the
573 # most specific match in the target_map
574 foreach my $dir (sort keys %{ $dirtree }) {
576 # deal with files in directory
577 foreach my $file (sort @{ $dirtree->{$dir} }) {
578 my $targetdir = undef;
579 my $matchlevel = undef;
580 # first, see if there is a match on this specific
581 # file in the target map
582 my $filepath = join("/", @$curr_path, $file);
583 if (exists $target_map->{$filepath}) {
584 $targetdir = $target_map->{$filepath};
585 $matchlevel = scalar(@$curr_path) + 1;
587 # no match on the specific file; look for
589 for (my $i = scalar(@$curr_path) - 1; $i >= 0; $i--) {
590 my $dirpath = join("/", @$curr_path[0..$i]);
591 if (exists $target_map->{$dirpath}) {
592 $targetdir = $target_map->{$dirpath};
593 $matchlevel = $i + 1;
598 if (defined $targetdir) {
599 _add_to_file_map($file_map, $targetdir, $curr_path, $file, $matchlevel, $install_zebra);
601 my $path = join("/", @$curr_path);
602 print "failed to map: $path/$file\n" if $DEBUG;
606 # dealing with subdirectory
607 push @$curr_path, $dir;
608 get_file_map($target_map, $dirtree->{$dir}, $file_map, $install_zebra, $curr_path);
614 sub _add_to_file_map {
615 my $file_map = shift;
616 my $targetdir = shift;
617 my $curr_path = shift;
619 my $matchlevel = shift;
620 my $install_zebra = shift;
621 my $dest_path = @_ ? shift : $curr_path;
623 # The target can be one of the following:
624 # 1. scalar representing target symbol
625 # 2. hash ref containing target and trimdir keys
627 # Consequently, this routine traverses this structure,
628 # calling itself recursively, until it deals with
629 # all of the scalar target symbols.
630 if (ref $targetdir eq 'HASH') {
631 my $subtarget = $targetdir->{target};
632 if (exists $targetdir->{trimdir}) {
633 # if we get here, we've specified that
634 # rather than installing the file to
635 # $(TARGET)/matching/dirs/subdirs/file,
636 # we want to install it to
637 # $(TARGET)/subdirs/file
639 # Note that this the only place where
640 # $matchlevel is used.
641 my @new_dest_path = @$dest_path;
642 if ($targetdir->{trimdir} == -1) {
643 splice @new_dest_path, 0, $matchlevel;
645 splice @new_dest_path, 0, $targetdir->{trimdir};
647 _add_to_file_map($file_map, $subtarget, $curr_path, $file, $matchlevel, $install_zebra, \@new_dest_path);
649 # actually getting here means that the
650 # target was unnecessarily listed
651 # as a hash, but we'll forgive that
652 _add_to_file_map($file_map, $subtarget, $curr_path, $file, $matchlevel, $install_zebra);
654 } elsif ($targetdir ne 'NONE' and $targetdir ne '') {
655 my $source = File::Spec->catfile(@$curr_path, $file);
656 my $destination = File::Spec->catfile('blib', $targetdir, @$dest_path, $file);
657 #print "$source => $destination\n"; # DEBUG
658 # quote spaces in file names
659 # FIXME: this is of questionable portability and
660 # probably depends on user's make recognizing this
661 # quoting syntax -- probably better to remove
662 # spaces and shell metacharacters from all file names
663 $source =~ s/ /\\ /g;
664 $destination =~ s/ /\\ /g;
666 $file_map->{$source} = $destination unless (!$install_zebra and $targetdir =~ /ZEBRA/);
670 =head2 get_configuration_options
672 This prompts the user for various configuration options.
676 sub get_configuration {
677 my $defaults = shift;
678 my $valid_values = shift;
682 By default, Koha can be installed in one of three ways:
684 standard: Install files in conformance with the Filesystem
685 Hierarchy Standard (FHS). This is the default mode
686 and should be used when installing a production
687 Koha system. On Unix systems, root access is
688 needed to complete a standard installation.
690 single: Install files under a single directory. This option
691 is useful for installing Koha without root access, e.g.,
692 on a web host that allows CGI scripts and MySQL databases
693 but requires the user to keep all files under the user's
696 dev: Create a set of symbolic links and configuration files to
697 allow Koha to run directly from the source distribution.
698 This mode is useful for developers who want to run
699 Koha from a git clone.
702 $msg .= _add_valid_values_disp('INSTALL_MODE', $valid_values);
703 $config{'INSTALL_MODE'} = _get_value('INSTALL_MODE', $msg, $defaults->{'INSTALL_MODE'}, $valid_values);
705 # set message and default value for INSTALL_BASE
706 # depending on value of INSTALL_MODE
707 my $install_base_default = $defaults->{'INSTALL_BASE'};
708 if ($config{'INSTALL_MODE'} eq 'dev') {
710 Please specify the directory in which to install Koha's
711 active configuration files and (if applicable) the
712 Zebra database. Koha's CGI scripts and templates will
713 be run from the current directory.
715 Configuration directory:);
716 # FIXME - home directory portability consideration apply
717 $install_base_default = (exists $ENV{'HOME'}) ? "$ENV{'HOME'}/koha-dev" : "$defaults->{'INSTALL_BASE'}-dev";
718 } elsif ($config{'INSTALL_MODE'} eq 'single') {
719 $msg = "\nPlease specify the directory in which to install Koha";
720 # FIXME -- we're assuming under a 'single' mode install
721 # that user will likely want to install under the home
722 # directory. This is OK in and of itself, but we should
723 # use File::HomeDir to locate the home directory portably.
724 # This is deferred for now because File::HomeDir is not yet
726 # --we must also keep this portable to the major OS's -fbcit
727 $install_base_default = (exists $ENV{'HOME'}) ? "$ENV{'HOME'}/koha" : $defaults->{'INSTALL_BASE'};
731 Please specify the directory under which most Koha files
734 Note that if you are planning in installing more than
735 one instance of Koha, you may want to modify the last
736 component of the directory path, which will be used
737 as the package name in the FHS layout.
739 Base installation directory);
741 $config{'INSTALL_BASE'} = _get_value('INSTALL_BASE', $msg, $install_base_default, $valid_values);
743 $config{'INSTALL_BASE'} = File::Spec->rel2abs($config{'INSTALL_BASE'});
744 print "INSTALL_BASE=$config{'INSTALL_BASE'}\r\n" if $DEBUG;
745 if ($config{'INSTALL_MODE'} eq "standard") {
747 Since you are using the 'standard' install
748 mode, you should run 'make install' as root.
749 However, it is recommended that a non-root
750 user (on Unix and Linux platforms) have
751 ownership of Koha's files, including the
752 Zebra indexes if applicable.
754 Please specify a user account. This
755 user account does not need to exist
756 right now, but it needs to exist
757 before you run 'make install'. Please
758 note that for security reasons, this
759 user should not be the same as the user
760 account Apache runs under.
763 $config{'KOHA_USER'} = _get_value('KOHA_USER', $msg, $defaults->{'KOHA_USER'}, $valid_values);
766 Please specify the group that should own
767 Koha's files. As above, this group need
768 not exist right now, but should be created
769 before you run 'make install'.
772 $config{'KOHA_GROUP'} = _get_value('KOHA_GROUP', $msg, $defaults->{'KOHA_GROUP'}, $valid_values);
776 Please specify which database engine you will use
777 to store data in Koha. The choices are MySQL and
778 PostgreSQL; please note that at the moment
779 PostgreSQL support is highly experimental.
782 $msg .= _add_valid_values_disp('DB_TYPE', $valid_values);
783 $config{'DB_TYPE'} = _get_value('DB_TYPE', $msg, $defaults->{'DB_TYPE'}, $valid_values);
786 Please specify the name or address of your
787 database server. Note that the database
788 does not have to exist at this point, it
789 can be created after running 'make install'
790 and before you try using Koha for the first time.
793 $config{'DB_HOST'} = _get_value('DB_HOST', $msg, $defaults->{'DB_HOST'}, $valid_values);
796 Please specify the port used to connect to the
798 my $db_port_default = $config{'DB_TYPE'} eq 'mysql' ? '3306' : '5432';
799 $config{'DB_PORT'} = _get_value('DB_PORT', $msg, $db_port_default, $valid_values);
802 Please specify the name of the database to be
804 $config{'DB_NAME'} = _get_value('DB_NAME', $msg, $defaults->{'DB_NAME'}, $valid_values);
807 Please specify the user that owns the database to be
809 $config{'DB_USER'} = _get_value('DB_USER', $msg, $defaults->{'DB_USER'}, $valid_values);
812 Please specify the password of the user that owns the
813 database to be used by Koha);
814 $config{'DB_PASS'} = _get_value('DB_PASS', $msg, $defaults->{'DB_PASS'}, $valid_values);
817 Koha can use the Zebra search engine for high-performance
818 searching of bibliographic and authority records. If you
819 have installed the Zebra software and would like to use it,
820 please answer 'yes' to the following question. Otherwise,
821 Koha will default to using its internal search engine.
823 Please note that if you choose *NOT* to install Zebra,
824 koha-conf.xml will still contain some references to Zebra
825 settings. Those references will be ignored by Koha.
827 Install the Zebra configuration files?);
828 $msg .= _add_valid_values_disp('INSTALL_ZEBRA', $valid_values);
829 $config{'INSTALL_ZEBRA'} = _get_value('INSTALL_ZEBRA', $msg, $defaults->{'INSTALL_ZEBRA'}, $valid_values);
831 if ($config{'INSTALL_ZEBRA'} eq 'yes') {
833 Since you've chosen to use Zebra with Koha,
834 you must specify the primary MARC format of the
835 records to be indexed by Zebra.
837 Koha provides Zebra configuration files for MARC 21
840 MARC format for Zebra indexing);
841 $msg .= _add_valid_values_disp('ZEBRA_MARC_FORMAT', $valid_values);
842 $config{'ZEBRA_MARC_FORMAT'} = _get_value('ZEBRA_MARC_FORMAT', $msg, $defaults->{'ZEBRA_MARC_FORMAT'}, $valid_values);
844 Koha supplies Zebra configuration files tuned for
845 searching either English (en) or French (fr) MARC
848 Primary language for Zebra indexing);
849 $msg .= _add_valid_values_disp('ZEBRA_LANGUAGE', $valid_values);
850 $config{'ZEBRA_LANGUAGE'} = _get_value('ZEBRA_LANGUAGE', $msg, $defaults->{'ZEBRA_LANGUAGE'}, $valid_values);
853 Please specify Zebra database user);
854 $config{'ZEBRA_USER'} = _get_value('ZEBRA_USER', $msg, $defaults->{'ZEBRA_USER'}, $valid_values);
857 Please specify the Zebra database password);
858 $config{'ZEBRA_PASS'} = _get_value('ZEBRA_PASS', $msg, $defaults->{'ZEBRA_PASS'}, $valid_values);
866 sub _add_valid_values_disp {
868 my $valid_values = shift;
871 if (exists $valid_values->{$key}) {
872 $disp = " (" . join(", ", sort keys %{ $valid_values->{$key} }) . ")";
881 my $valid_values = shift;
883 # override default value from environment
884 if (exists $ENV{$key}) {
885 $default = $ENV{$key};
886 $msg .= " (default from environment)";
889 my $val = prompt($msg, $default);
891 while (exists $valid_values->{$key} and
893 not exists $valid_values->{$key}->{$val}) {
894 my $retry_msg = "Value '$val' is not a valid option.\n";
895 $retry_msg .= "Please enter a value";
896 $retry_msg .= _add_valid_values_disp($key, $valid_values);
897 $val = prompt($retry_msg, $default);
902 =head2 get_target_directories
904 Creates a hash mapping from symbols for installation target
905 directories to actual directory paths.
907 Also returns a hash indicating targets for which
908 files need not be copied -- this is used for the 'dev'
909 mode installation, where some files are installed in place.
913 sub get_target_directories {
916 my $base = $config->{'INSTALL_BASE'};
917 my $mode = $config->{'INSTALL_MODE'};
919 # get last component of install base directory
920 # to treat as package name
921 my ($volume, $directories, $file) = File::Spec->splitpath($base, 1);
923 my @basedir = File::Spec->splitdir($directories);
925 # for Win32 we need to prepend the volume to the directory path
926 if ( $^O eq 'MSWin32' ) { shift @basedir; unshift @basedir, $volume; }
927 elsif ( $^O eq 'cygwin' ) { shift @basedir; unshift @basedir, 'c:'; } # in a cygwin environment, $volume is returned empty
929 my $package = pop @basedir;
934 if ($mode eq 'single') {
935 $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
936 $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs', 'intranet-tmpl');
937 $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs');
938 $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
939 $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl');
940 $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs');
941 $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
942 $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
943 $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
944 $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
945 $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
946 $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
947 $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
948 $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
949 $dirmap{'LOG_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'log');
950 $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
951 $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
952 } elsif ($mode eq 'dev') {
953 my $curdir = File::Spec->rel2abs(File::Spec->curdir());
954 $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir($curdir);
955 $skipdirs{'INTRANET_CGI_DIR'} = 1;
956 $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'intranet-tmpl');
957 $skipdirs{'INTRANET_TMPL_DIR'} = 1;
958 $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl');
959 $skipdirs{'INTRANET_WWW_DIR'} = 1;
960 $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir($curdir);
961 $skipdirs{'OPAC_CGI_DIR'} = 1;
962 $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl', 'opac-tmpl');
963 $skipdirs{'OPAC_TMPL_DIR'} = 1;
964 $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir($curdir, 'koha-tmpl');
965 $skipdirs{'OPAC_WWW_DIR'} = 1;
966 $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir($curdir);
967 $skipdirs{'PERL_MODULE_DIR'} = 1;
968 $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc');
969 $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(@basedir, $package, 'etc', 'zebradb');
970 $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
971 $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
972 $skipdirs{'SCRIPT_DIR'} = 1;
973 $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
974 $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
975 $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lock', 'zebradb');
976 $dirmap{'LOG_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'log');
977 $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'lib', 'zebradb');
978 $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(@basedir, $package, 'var', 'run', 'zebradb');
980 # mode is standard, i.e., 'fhs'
981 $dirmap{'INTRANET_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'cgi-bin');
982 $dirmap{'INTRANET_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs', 'intranet-tmpl');
983 $dirmap{'INTRANET_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'intranet', 'htdocs');
984 $dirmap{'OPAC_CGI_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'cgi-bin');
985 $dirmap{'OPAC_TMPL_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs', 'opac-tmpl');
986 $dirmap{'OPAC_WWW_DIR'} = File::Spec->catdir(@basedir, $package, 'opac', 'htdocs');
987 $dirmap{'PERL_MODULE_DIR'} = File::Spec->catdir(@basedir, $package, 'lib');
988 $dirmap{'KOHA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package);
989 $dirmap{'ZEBRA_CONF_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'etc', $package, 'zebradb');
990 $dirmap{'MISC_DIR'} = File::Spec->catdir(@basedir, $package, 'misc');
991 $dirmap{'SCRIPT_DIR'} = File::Spec->catdir(@basedir, $package, 'bin');
992 $dirmap{'MAN_DIR'} = File::Spec->catdir(@basedir, $package, 'man');
993 $dirmap{'DOC_DIR'} = File::Spec->catdir(@basedir, $package, 'doc');
994 $dirmap{'ZEBRA_LOCK_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lock', $package, 'zebradb');
995 $dirmap{'LOG_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'log', $package);
996 $dirmap{'ZEBRA_DATA_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'lib', $package, 'zebradb');
997 $dirmap{'ZEBRA_RUN_DIR'} = File::Spec->catdir(File::Spec->rootdir(), 'var', 'run', $package, 'zebradb');
1000 _get_env_overrides(\%dirmap);
1001 _get_argv_overrides(\%dirmap);
1003 return \%dirmap, \%skipdirs;
1006 sub _get_env_overrides {
1009 foreach my $key (keys %$dirmap) {
1010 if (exists $ENV{$key}) {
1011 $dirmap->{$key} = $ENV{$key};
1012 print "Setting $key from environment\n";
1017 sub _get_argv_overrides {
1021 for (my $i = 0; $i <= $#ARGV; $i++) {
1022 if ($ARGV[$i] =~ /^([^=]+)=([^=]+)$/ and exists $dirmap->{$1}) {
1025 push @new_argv, $ARGV[$i];
1031 sub display_configuration {
1034 print "\n\nKoha will be installed with the following configuration parameters:\n\n";
1035 foreach my $key (sort keys %$config) {
1036 print sprintf("%-25.25s%s\n", $key, $config->{$key});
1039 print "\nand in the following directories:\n\n";
1040 foreach my $key (sort keys %$dirmap) {
1041 print sprintf("%-25.25s%s\n", $key, $dirmap->{$key});
1043 print "\n\nTo change any configuration setting, please run\n";
1044 print "perl Makefile.PL again. To override one of the target\n";
1045 print "directories, you can do so on the command line like this:\n";
1046 print "\nperl Makefile.PL PERL_MODULE_DIR=/usr/share/perl/5.8\n\n";
1047 print "You can also set different default values for parameters\n";
1048 print "or override directory locations by using environment variables.\n";
1049 print "\nFor example:\n\n";
1050 print "export DB_USER=my_koha\n";
1051 print "perl Makefile.PL\n";
1053 print "DB_USER=my_koha DOC_DIR=/usr/local/info perl Makefile.PL\n\n";
1058 # This will have to be reworked in order to accommodate Win32...
1062 my $test = $self->SUPER::test(@_);
1063 $test =~ s!\$\(INST_LIB\)!blib/PERL_MODULE_DIR!g;
1070 # NOTE: we're *not* doing this: my $install = $self->SUPER::install(@_);
1071 # This means that we're completely overriding EU::MM's default
1072 # installation and uninstallation targets.
1074 # If installation is on Win32, we need to do permissions different from *nix
1075 if ( $^O =~ /darwin|linux|cygwin/ ) { # this value needs to be verified for each platform and modified accordingly
1076 foreach my $key (sort keys %$target_directories) {
1078 KOHA_INST_$key = blib/$key
1079 KOHA_DEST_$key = $target_directories->{$key}
1080 ) unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1083 install :: all install_koha set_koha_ownership set_koha_permissions warn_koha_env_vars
1084 \t\$(NOECHO) \$(NOOP)
1086 $install .= "install_koha ::\n";
1087 $install .= "\t\$(NOECHO) umask 022; \$(MOD_INSTALL) \\\n";
1088 foreach my $key (sort keys %$target_directories) {
1089 $install .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
1090 unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1092 $install .= "\t\t\$(INST_MAN1DIR) \$(DESTINSTALLMAN1DIR) \\\n";
1093 $install .= "\t\t\$(INST_MAN3DIR) \$(DESTINSTALLMAN3DIR)\n";
1096 $install .= "set_koha_ownership ::\n";
1097 if ($config{'INSTALL_MODE'} eq 'standard' and $config{'KOHA_USER'} ne "root") {
1098 foreach my $key (sort keys %$target_directories) {
1099 $install .= "\t\$(NOECHO) chown -R $config{'KOHA_USER'}:$config{'KOHA_GROUP'} \$(KOHA_DEST_$key)\n"
1100 unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1103 $install .= "\t\t\$(NOECHO) \$(NOOP)\n\n";
1107 $install .= "set_koha_permissions ::\n";
1108 # This is necessary because EU::MM installs files
1109 # as either 0444 or 0555, and we want the owner
1110 # of Koha's files to have write permission by default.
1111 foreach my $key (sort keys %$target_directories) {
1112 $install .= "\t\$(NOECHO) chmod -R u+w \$(KOHA_DEST_$key)\n"
1113 unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1116 elsif ($^O eq 'MSWin32' ) { # On Win32, the install probably needs to be done under the user account koha will be running as...
1117 # We can attempt some creative things with command line utils such as CACLS which allows permission
1118 # management from Win32 cmd.exe, but permissions really only apply to NTFS.
1119 foreach my $key (sort keys %$target_directories) {
1121 KOHA_INST_$key = blib/$key
1122 KOHA_DEST_$key = $target_directories->{$key}
1123 ) unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1126 install :: all install_koha warn_koha_env_vars
1127 \t\$(NOECHO) \$(NOOP)
1129 $install .= "install_koha ::\n";
1130 $install .= "\t\$(MOD_INSTALL) \\\n";
1131 foreach my $key (sort keys %$target_directories) {
1132 $install .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
1133 unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
1138 $install .= "warn_koha_env_vars ::\n";
1139 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1140 $install .= "\t\$(NOECHO) \$(ECHO) Koha\\'s files have now been installed. \n";
1141 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1142 $install .= "\t\$(NOECHO) \$(ECHO) In order to use Koha\\'s command-line batch jobs,\n";
1143 $install .= "\t\$(NOECHO) \$(ECHO) you should set the following environment variables:\n";
1144 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1145 $install .= "\t\$(NOECHO) \$(ECHO) export KOHA_CONF=\$(KOHA_DEST_KOHA_CONF_DIR)/koha-conf.xml\n";
1146 $install .= "\t\$(NOECHO) \$(ECHO) export PERL5LIB=$target_directories->{'PERL_MODULE_DIR'}\n";
1147 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1148 $install .= "\t\$(NOECHO) \$(ECHO) If installing on a Win32 platform, be sure to use:\n";
1149 $install .= "\t\$(NOECHO) \$(ECHO) 'dmake -x MAXLINELENGTH=300000'\n";
1150 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1151 $install .= "\t\$(NOECHO) \$(ECHO) For other post-installation tasks, please consult the README.\n";
1152 $install .= "\t\$(NOECHO) \$(ECHO)\n";
1158 # put directory mappings into Makefile
1159 # so that Make will export as environment
1160 # variables -- this is for the use of
1163 # quote '$' in the two password parameters
1164 my %config = %config;
1165 $config{'DB_PASS'} =~ s/\$/\$\$/g;
1166 if ($config{'INSTALL_ZEBRA'} eq "yes") {
1167 $config{'ZEBRA_PASS'} =~ s/\$/\$\$/g;
1170 # Hereagain, we must alter syntax per platform...
1171 if ( $^O eq 'MSWin32' ) {
1172 # NOTE: it is imperative that there be no whitespaces in ENV=value...
1173 my $env = join("\n", map { "__${_}__=$target_directories->{$_}" } keys %$target_directories);
1175 $env .= join("\n", map { "__${_}__=$config{$_}" } keys %config);
1179 my $env = join("\n", map { "export __${_}__ := $target_directories->{$_}" } keys %$target_directories);
1181 $env .= join("\n", map { "export __${_}__ := $config{$_}" } keys %config);
1192 ExtUtils::MakeMaker(3)
1196 MJ Ray mjr at phonecoop.coop
1197 Galen Charlton galen.charlton at liblime.com
1200 FIXME: deal with .htaccess