+sub get_file_map {
+ my $target_map = shift;
+ my $dirtree = shift;
+ my $file_map = shift;
+ my $install_zebra = shift;
+ my $curr_path = @_ ? shift : ['.'];
+
+ # Traverse the directory tree.
+ # For each file or directory, identify the
+ # most specific match in the target_map
+ foreach my $dir (sort keys %{ $dirtree }) {
+ if ($dir eq '.') {
+ # deal with files in directory
+ foreach my $file (sort @{ $dirtree->{$dir} }) {
+ my $targetdir = undef;
+ my $matchlevel = undef;
+ # first, see if there is a match on this specific
+ # file in the target map
+ my $filepath = join("/", @$curr_path, $file);
+ if (exists $target_map->{$filepath}) {
+ $targetdir = $target_map->{$filepath};
+ $matchlevel = scalar(@$curr_path) + 1;
+ } else {
+ # no match on the specific file; look for
+ # a directory match
+ for (my $i = scalar(@$curr_path) - 1; $i >= 0; $i--) {
+ my $dirpath = join("/", @$curr_path[0..$i]);
+ if (exists $target_map->{$dirpath}) {
+ $targetdir = $target_map->{$dirpath};
+ $matchlevel = $i + 1;
+ last;
+ }
+ }
+ }
+ if (defined $targetdir) {
+ _add_to_file_map($file_map, $targetdir, $curr_path, $file, $matchlevel, $install_zebra);
+ } else {
+ my $path = join("/", @$curr_path);
+ print "failed to map: $path/$file\n" if $DEBUG;
+ }
+ }
+ } else {
+ # dealing with subdirectory
+ push @$curr_path, $dir;
+ get_file_map($target_map, $dirtree->{$dir}, $file_map, $install_zebra, $curr_path);
+ pop @$curr_path;
+ }
+ }
+}
+
+sub _add_to_file_map {
+ my $file_map = shift;
+ my $targetdir = shift;
+ my $curr_path = shift;
+ my $file = shift;
+ my $matchlevel = shift;
+ my $install_zebra = shift;
+ my $dest_path = @_ ? shift : $curr_path;
+
+ # The target can be one of the following:
+ # 1. scalar representing target symbol
+ # 2. hash ref containing target and trimdir keys
+ #
+ # Consequently, this routine traverses this structure,
+ # calling itself recursively, until it deals with
+ # all of the scalar target symbols.
+ if (ref $targetdir eq 'HASH') {
+ my $subtarget = $targetdir->{target};
+ if (exists $targetdir->{trimdir}) {
+ # if we get here, we've specified that
+ # rather than installing the file to
+ # $(TARGET)/matching/dirs/subdirs/file,
+ # we want to install it to
+ # $(TARGET)/subdirs/file
+ #
+ # Note that this the only place where
+ # $matchlevel is used.
+ my @new_dest_path = @$dest_path;
+ if ($targetdir->{trimdir} == -1) {
+ splice @new_dest_path, 0, $matchlevel;
+ } else {
+ splice @new_dest_path, 0, $targetdir->{trimdir};
+ }
+ _add_to_file_map($file_map, $subtarget, $curr_path, $file, $matchlevel, $install_zebra, \@new_dest_path);
+ } else {
+ # actually getting here means that the
+ # target was unnecessarily listed
+ # as a hash, but we'll forgive that
+ _add_to_file_map($file_map, $subtarget, $curr_path, $file, $matchlevel, $install_zebra);
+ }
+ } elsif ($targetdir ne 'NONE' and $targetdir ne '') {
+ my $source = File::Spec->catfile(@$curr_path, $file);
+ my $destination = File::Spec->catfile('blib', $targetdir, @$dest_path, $file);
+ #print "$source => $destination\n"; # DEBUG
+ # quote spaces in file names
+ # FIXME: this is of questionable portability and
+ # probably depends on user's make recognizing this
+ # quoting syntax -- probably better to remove
+ # spaces and shell metacharacters from all file names
+ $source =~ s/ /\\ /g;
+ $destination =~ s/ /\\ /g;
+
+ $file_map->{$source} = $destination unless (!$install_zebra and $targetdir =~ /ZEBRA/);
+ }
+}
+
+=head2 get_install_log_values
+
+Reads value from the Koha install log specified by
+--prev-install-log
+
+=cut
+
+sub get_install_log_values {
+ my $install_log = shift;
+ my $values = shift;
+
+ open LOG, "<$install_log" or die "Cannot open install log $install_log: $!\n";
+ while (<LOG>) {
+ chomp;
+ next if /^#/ or /^\s*$/;
+ next if /^=/;
+ next unless m/=/;
+ s/\s+$//g;
+ my ($key, $value) = split /=/, $_, 2;
+ $values->{$key} = $value;
+ }
+ close LOG;
+
+ print <<_EXPLAIN_INSTALL_LOG_;
+Reading values from install log $install_log. You
+will be prompted only for settings that have been
+added since the last time you installed Koha. To
+be prompted for all settings, run 'perl Makefile.PL'
+without the --prev-install-log option.
+_EXPLAIN_INSTALL_LOG_
+}
+
+=head2 get_configuration
+
+This prompts the user for various configuration options.
+
+=cut
+
+sub get_configuration {
+ my $defaults = shift;
+ my $valid_values = shift;
+ my $install_log_values = shift;
+ my %config = ();
+
+ my $msg = q(
+By default, Koha can be installed in one of three ways:
+
+standard: Install files in conformance with the Filesystem
+ Hierarchy Standard (FHS). This is the default mode
+ and should be used when installing a production
+ Koha system. On Unix systems, root access is
+ needed to complete a standard installation.
+
+single: Install files under a single directory. This option
+ is useful for installing Koha without root access, e.g.,
+ on a web host that allows CGI scripts and MySQL databases
+ but requires the user to keep all files under the user's
+ HOME directory.
+
+dev: Create a set of symbolic links and configuration files to
+ allow Koha to run directly from the source distribution.
+ This mode is useful for developers who want to run
+ Koha from a git clone.
+
+Installation mode);
+ $msg .= _add_valid_values_disp('INSTALL_MODE', $valid_values);
+ $config{'INSTALL_MODE'} = _get_value('INSTALL_MODE', $msg, $defaults->{'INSTALL_MODE'}, $valid_values, $install_log_values);
+
+ # set message and default value for INSTALL_BASE
+ # depending on value of INSTALL_MODE
+ my $install_base_default = $defaults->{'INSTALL_BASE'};
+ if ($config{'INSTALL_MODE'} eq 'dev') {
+ $msg = q(
+Please specify the directory in which to install Koha's
+active configuration files and (if applicable) the
+Zebra database. Koha's CGI scripts and templates will
+be run from the current directory.
+
+Configuration directory:);
+ # FIXME - home directory portability consideration apply
+ $install_base_default = (exists $ENV{'HOME'}) ? "$ENV{'HOME'}/koha-dev" : "$defaults->{'INSTALL_BASE'}-dev";
+ } elsif ($config{'INSTALL_MODE'} eq 'single') {
+ $msg = "\nPlease specify the directory in which to install Koha";
+ # FIXME -- we're assuming under a 'single' mode install
+ # that user will likely want to install under the home
+ # directory. This is OK in and of itself, but we should
+ # use File::HomeDir to locate the home directory portably.
+ # This is deferred for now because File::HomeDir is not yet
+ # core.
+ # --we must also keep this portable to the major OS's -fbcit
+ $install_base_default = (exists $ENV{'HOME'}) ? "$ENV{'HOME'}/koha" : $defaults->{'INSTALL_BASE'};
+ } else {
+ # must be standard
+ $msg = q(
+Please specify the directory under which most Koha files
+will be installed.
+
+Note that if you are planning in installing more than
+one instance of Koha, you may want to modify the last
+component of the directory path, which will be used
+as the package name in the FHS layout.
+
+Base installation directory);
+ }
+ $config{'INSTALL_BASE'} = _get_value('INSTALL_BASE', $msg, $install_base_default, $valid_values, $install_log_values);
+
+ $config{'INSTALL_BASE'} = File::Spec->rel2abs($config{'INSTALL_BASE'});
+ print "INSTALL_BASE=$config{'INSTALL_BASE'}\r\n" if $DEBUG;
+ if ($config{'INSTALL_MODE'} eq "standard") {
+ $msg = q(
+Since you are using the 'standard' install
+mode, you should run 'make install' as root.
+However, it is recommended that a non-root
+user (on Unix and Linux platforms) have
+ownership of Koha's files, including the
+Zebra indexes if applicable.
+
+Please specify a user account. This
+user account does not need to exist
+right now, but it needs to exist
+before you run 'make install'. Please
+note that for security reasons, this
+user should not be the same as the user
+account Apache runs under.
+
+User account);
+ $config{'KOHA_USER'} = _get_value('KOHA_USER', $msg, $defaults->{'KOHA_USER'}, $valid_values, $install_log_values);
+
+ $msg = q(
+Please specify the group that should own
+Koha's files. As above, this group need
+not exist right now, but should be created
+before you run 'make install'.
+
+Group);
+ $config{'KOHA_GROUP'} = _get_value('KOHA_GROUP', $msg, $defaults->{'KOHA_GROUP'}, $valid_values, $install_log_values);
+ }
+
+ $msg = q(
+Please specify which database engine you will use
+to store data in Koha. The choices are MySQL and
+PostgreSQL; please note that at the moment
+PostgreSQL support is highly experimental.
+
+DBMS to use);
+ $msg .= _add_valid_values_disp('DB_TYPE', $valid_values);
+ $config{'DB_TYPE'} = _get_value('DB_TYPE', $msg, $defaults->{'DB_TYPE'}, $valid_values, $install_log_values);
+
+ $msg = q(
+Please specify the name or address of your
+database server. Note that the database
+does not have to exist at this point, it
+can be created after running 'make install'
+and before you try using Koha for the first time.
+
+Database server);
+ $config{'DB_HOST'} = _get_value('DB_HOST', $msg, $defaults->{'DB_HOST'}, $valid_values, $install_log_values);
+
+ $msg = q(
+Please specify the port used to connect to the
+DMBS);
+ my $db_port_default = $config{'DB_TYPE'} eq 'mysql' ? '3306' : '5432';
+ $config{'DB_PORT'} = _get_value('DB_PORT', $msg, $db_port_default, $valid_values, $install_log_values);
+
+ $msg = q(
+Please specify the name of the database to be
+used by Koha);
+ $config{'DB_NAME'} = _get_value('DB_NAME', $msg, $defaults->{'DB_NAME'}, $valid_values, $install_log_values);
+
+ $msg = q(
+Please specify the user that owns the database to be
+used by Koha);
+ $config{'DB_USER'} = _get_value('DB_USER', $msg, $defaults->{'DB_USER'}, $valid_values, $install_log_values);
+
+ $msg = q(
+Please specify the password of the user that owns the
+database to be used by Koha);
+ $config{'DB_PASS'} = _get_value('DB_PASS', $msg, $defaults->{'DB_PASS'}, $valid_values, $install_log_values);
+
+ $msg = q(
+Koha can use the Zebra search engine for high-performance
+searching of bibliographic and authority records. If you
+have installed the Zebra software and would like to use it,
+please answer 'yes' to the following question. Otherwise,
+Koha will default to using its internal search engine.
+
+Please note that if you choose *NOT* to install Zebra,
+koha-conf.xml will still contain some references to Zebra
+settings. Those references will be ignored by Koha.
+
+Install the Zebra configuration files?);
+ $msg .= _add_valid_values_disp('INSTALL_ZEBRA', $valid_values);
+ $config{'INSTALL_ZEBRA'} = _get_value('INSTALL_ZEBRA', $msg, $defaults->{'INSTALL_ZEBRA'}, $valid_values, $install_log_values);
+
+ if ($config{'INSTALL_ZEBRA'} eq 'yes') {
+
+ if (defined(my $zebra_path = find_zebra())) {
+ $config{'PATH_TO_ZEBRA'} = $zebra_path;
+ print qq(
+Found 'zebrasrv' and 'zebraidx' in $zebra_path.
+);
+ } else {
+ print q(
+Unable to find the Zebra programs 'zebrasrv' and 'zebraidx'
+in your PATH or in some of the usual places. If you haven't
+installed Zebra yet, please do so and run Makefile.PL again.
+
+);
+ }
+
+ $msg = q(
+Since you've chosen to use Zebra with Koha,
+you must specify the primary MARC format of the
+records to be indexed by Zebra.
+
+Koha provides Zebra configuration files for MARC 21
+and UNIMARC.
+
+MARC format for Zebra indexing);
+ $msg .= _add_valid_values_disp('ZEBRA_MARC_FORMAT', $valid_values);
+ $config{'ZEBRA_MARC_FORMAT'} = _get_value('ZEBRA_MARC_FORMAT', $msg, $defaults->{'ZEBRA_MARC_FORMAT'}, $valid_values, $install_log_values);
+ $msg = q(
+Koha supplies Zebra configuration files tuned for
+searching either English (en) or French (fr) MARC
+records.
+
+Primary language for Zebra indexing);
+ $msg .= _add_valid_values_disp('ZEBRA_LANGUAGE', $valid_values);
+ $config{'ZEBRA_LANGUAGE'} = _get_value('ZEBRA_LANGUAGE', $msg, $defaults->{'ZEBRA_LANGUAGE'}, $valid_values, $install_log_values);
+
+ $msg = q(
+Koha can use one of two different indexing modes
+for the MARC authorities records:
+
+grs1 - uses the Zebra GRS-1 filter, available
+ for legacy support
+dom - uses the DOM XML filter; offers improved
+ functionality.
+
+Authorities indexing mode);
+ $msg .= _add_valid_values_disp('AUTH_INDEX_MODE', $valid_values);
+ $config{'AUTH_INDEX_MODE'} = _get_value('AUTH_INDEX_MODE', $msg, $defaults->{'AUTH_INDEX_MODE'}, $valid_values, $install_log_values);
+
+ $msg = q(
+Please specify Zebra database user);
+ $config{'ZEBRA_USER'} = _get_value('ZEBRA_USER', $msg, $defaults->{'ZEBRA_USER'}, $valid_values, $install_log_values);
+
+ $msg = q(
+Please specify the Zebra database password);
+ $config{'ZEBRA_PASS'} = _get_value('ZEBRA_PASS', $msg, $defaults->{'ZEBRA_PASS'}, $valid_values, $install_log_values);
+
+ $msg = q(
+Since you've chosen to use Zebra, you can enable the SRU/
+Z39.50 Server if you so choose, but you must specify a
+few configuration options for it.
+
+Please note that if you choose *NOT* to configure SRU,
+koha-conf.xml will still contain some references to SRU
+settings. Those references will be ignored by Koha.
+
+Install the SRU configuration files?);
+ $msg .= _add_valid_values_disp('INSTALL_SRU', $valid_values);
+ $config{'INSTALL_SRU'} = _get_value('INSTALL_SRU', $msg, $defaults->{'INSTALL_SRU'}, $valid_values, $install_log_values);
+
+ if ($config{'INSTALL_SRU'} eq 'yes') {
+ $msg = q(
+Since you've chosen to configure SRU, you must
+specify the host and port(s) that the SRU
+Servers (bibliographic and authority) should run on.
+);
+ $msg = q(
+SRU Database host?);
+ $config{'ZEBRA_SRU_HOST'} = _get_value('ZEBRA_SRU_HOST', $msg, $defaults->{'ZEBRA_SRU_HOST'}, $valid_values, $install_log_values);
+
+ $msg = q(
+SRU port for bibliographic data?);
+ $config{'ZEBRA_SRU_BIBLIOS_PORT'} = _get_value('ZEBRA_SRU_BIBLIOS_PORT', $msg, $defaults->{'ZEBRA_SRU_BIBLIOS_PORT'}, $valid_values, $install_log_values);
+
+ $msg = q(
+SRU port for authority data?);
+ $config{'ZEBRA_SRU_AUTHORITIES_PORT'} = _get_value('ZEBRA_SRU_AUTHORITIES_PORT', $msg, $defaults->{'ZEBRA_SRU_AUTHORITIES_PORT'}, $valid_values, $install_log_values);
+
+ }
+
+ $msg = q(
+Since you've chosen to use Zebra, you can also choose to
+install PazPar2, which is a metasearch tool. With PazPar2,
+Koha can perform on-the-fly merging of bibliographic
+records during searching, allowing for FRBRization of
+the results list.
+
+Install the PazPar2 configuration files?);
+ $msg .= _add_valid_values_disp('INSTALL_PAZPAR2', $valid_values);
+ $config{'INSTALL_PAZPAR2'} = _get_value('INSTALL_PAZPAR2', $msg, $defaults->{'INSTALL_PAZPAR2'}, $valid_values, $install_log_values);
+
+ if ($config{'INSTALL_PAZPAR2'} eq 'yes') {
+ $msg = q(
+Since you've chosen to configure PazPar2, you must
+specify the host and port(s) that PazPar2
+uses:
+);
+ $msg = q(
+Zebra bibliographic server host?);
+ $config{'MERGE_SERVER_HOST'} = _get_value('MERGE_SERVER_HOST', $msg, $defaults->{'MERGE_SERVER_HOST'}, $valid_values, $install_log_values);
+
+ $msg = q(
+Zebra bibliographic port for PazPar2 to use?);
+ $config{'MERGE_SERVER_PORT'} = _get_value('MERGE_SERVER_PORT', $msg, $defaults->{'MERGE_SERVER_PORT'}, $valid_values, $install_log_values);
+
+ $msg = q(
+PazPar2 host?);
+ $config{'PAZPAR2_HOST'} = _get_value('PAZPAR2_HOST', $msg, $defaults->{'PAZPAR2_HOST'}, $valid_values, $install_log_values);
+
+ $msg = q(
+PazPar2 port?);
+ $config{'PAZPAR2_PORT'} = _get_value('PAZPAR2_PORT', $msg, $defaults->{'PAZPAR2_PORT'}, $valid_values, $install_log_values);