+sub _get_argv_overrides {
+ my $dirmap = shift;
+
+ my @new_argv = ();
+ for (my $i = 0; $i <= $#ARGV; $i++) {
+ if ($ARGV[$i] =~ /^([^=]+)=([^=]+)$/ and exists $dirmap->{$1}) {
+ $dirmap->{$1} = $2;
+ } else {
+ push @new_argv, $ARGV[$i];
+ }
+ }
+ @ARGV = @new_argv;
+}
+
+sub display_configuration {
+ my $config = shift;
+ my $dirmap = shift;
+ print "\n\nKoha will be installed with the following configuration parameters:\n\n";
+ foreach my $key (sort keys %$config) {
+ print sprintf("%-25.25s%s\n", $key, $config->{$key});
+ }
+
+ print "\nand in the following directories:\n\n";
+ foreach my $key (sort keys %$dirmap) {
+ print sprintf("%-25.25s%s\n", $key, $dirmap->{$key});
+ }
+ print "\n\nTo change any configuration setting, please run\n";
+ print "perl Makefile.PL again. To override one of the target\n";
+ print "directories, you can do so on the command line like this:\n";
+ print "\nperl Makefile.PL PERL_MODULE_DIR=/usr/share/perl/5.8\n\n";
+ print "You can also set different default values for parameters\n";
+ print "or override directory locations by using environment variables.\n";
+ print "\nFor example:\n\n";
+ print "export DB_USER=my_koha\n";
+ print "perl Makefile.PL\n";
+ print "\nor\n\n";
+ print "DB_USER=my_koha DOC_DIR=/usr/local/info perl Makefile.PL\n\n";
+ print "If installing on a Win32 platform, be sure to use:\n";
+ print "'dmake -x MAXLINELENGTH=300000'\n\n";
+}
+
+=head2 find_zebra
+
+Attempt to find Zebra - check user's PATH and
+a few other directories for zebrasrv and zebraidx.
+
+FIXME: doesn't handle Win32
+
+=cut
+
+sub find_zebra {
+ my @search_dirs = map {
+ my $abs = File::Spec->rel2abs($_);
+ my ($toss, $directories);
+ ($toss, $directories, $toss) = File::Spec->splitpath($abs, 1);
+ $directories;
+ } split /:/, $ENV{PATH};
+ push @search_dirs, qw(/usr/local/bin /opt/local/bin /usr/bin);
+ my @zebrasrv_dirs = grep { -x File::Spec->catpath('', $_, 'zebrasrv') } @search_dirs;
+ return unless @zebrasrv_dirs;
+ # verify that directory that contains zebrasrv also contains zebraidx
+ foreach my $dir (@zebrasrv_dirs) {
+ return $dir if -x File::Spec->catpath('', $dir, 'zebraidx');
+ }
+ return;
+}
+
+package MY;
+
+# This will have to be reworked in order to accommodate Win32...
+
+sub test {
+ my $self = shift;
+ my $test = $self->SUPER::test(@_);
+ $test =~ s!\$\(INST_LIB\)!blib/PERL_MODULE_DIR!g;
+
+ # set KOHA_CONF
+ $test =~ s!\$\(FULLPERLRUN\)!KOHA_CONF=blib/KOHA_CONF_DIR/koha-conf.xml \$(FULLPERLRUN)!g;
+ return $test;
+}
+
+sub install {
+ my $self = shift;
+ my $install = "";
+ # NOTE: we're *not* doing this: my $install = $self->SUPER::install(@_);
+ # This means that we're completely overriding EU::MM's default
+ # installation and uninstallation targets.
+
+# If installation is on Win32, we need to do permissions different from *nix
+ if ( $^O =~ /darwin|linux|cygwin|freebsd/ ) { # this value needs to be verified for each platform and modified accordingly
+ foreach my $key (sort keys %$target_directories) {
+ $install .= qq(
+KOHA_INST_$key = blib/$key
+KOHA_DEST_$key = $target_directories->{$key}
+) unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
+ }
+ $install .= qq(
+install :: all install_koha set_koha_ownership set_koha_permissions warn_koha_env_vars
+\t\$(NOECHO) \$(NOOP)
+);
+ $install .= "install_koha ::\n";
+ $install .= "\t\$(NOECHO) umask 022; \$(MOD_INSTALL) \\\n";
+ foreach my $key (sort keys %$target_directories) {
+ $install .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
+ unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
+ }
+ $install .= "\t\t\$(INST_MAN1DIR) \$(DESTINSTALLMAN1DIR) \\\n";
+ $install .= "\t\t\$(INST_MAN3DIR) \$(DESTINSTALLMAN3DIR)\n";
+
+ $install .= "\n";
+ $install .= "set_koha_ownership ::\n";
+ if ($config{'INSTALL_MODE'} eq 'standard' and $config{'KOHA_USER'} ne "root") {
+ foreach my $key (sort keys %$target_directories) {
+ $install .= "\t\$(NOECHO) chown -R $config{'KOHA_USER'}:$config{'KOHA_GROUP'} \$(KOHA_DEST_$key)\n"
+ unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
+ }
+ } else {
+ $install .= "\t\t\$(NOECHO) \$(NOOP)\n\n";
+ }
+
+ $install .= "\n";
+ $install .= "set_koha_permissions ::\n";
+ # This is necessary because EU::MM installs files
+ # as either 0444 or 0555, and we want the owner
+ # of Koha's files to have write permission by default.
+ foreach my $key (sort keys %$target_directories) {
+ $install .= "\t\$(NOECHO) chmod -R u+w \$(KOHA_DEST_$key)\n"
+ unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
+ }
+ }
+ elsif ($^O eq 'MSWin32' ) { # On Win32, the install probably needs to be done under the user account koha will be running as...
+ # We can attempt some creative things with command line utils such as CACLS which allows permission
+ # management from Win32 cmd.exe, but permissions really only apply to NTFS.
+ foreach my $key (sort keys %$target_directories) {
+ $install .= qq(
+KOHA_INST_$key = blib/$key
+KOHA_DEST_$key = $target_directories->{$key}
+) unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
+ }
+ $install .= qq(
+install :: all install_koha warn_koha_env_vars
+\t\$(NOECHO) \$(NOOP)
+);
+ $install .= "install_koha ::\n";
+ $install .= "\t\$(MOD_INSTALL) \\\n";
+ foreach my $key (sort keys %$target_directories) {
+ $install .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
+ unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or exists $skip_directories->{$key};
+ }
+ }
+ $install .= "\n";
+
+ $install .= "warn_koha_env_vars ::\n";
+ $install .= "\t\$(NOECHO) \$(ECHO)\n";
+ $install .= "\t\$(NOECHO) \$(ECHO) Koha\\'s files have now been installed. \n";
+ $install .= "\t\$(NOECHO) \$(ECHO)\n";
+ $install .= "\t\$(NOECHO) \$(ECHO) In order to use Koha\\'s command-line batch jobs,\n";
+ $install .= "\t\$(NOECHO) \$(ECHO) you should set the following environment variables:\n";
+ $install .= "\t\$(NOECHO) \$(ECHO)\n";
+ $install .= "\t\$(NOECHO) \$(ECHO) export KOHA_CONF=\$(KOHA_DEST_KOHA_CONF_DIR)/koha-conf.xml\n";
+ $install .= "\t\$(NOECHO) \$(ECHO) export PERL5LIB=$target_directories->{'PERL_MODULE_DIR'}\n";
+ $install .= "\t\$(NOECHO) \$(ECHO)\n";
+ $install .= "\t\$(NOECHO) \$(ECHO) For other post-installation tasks, please consult the README.\n";
+ $install .= "\t\$(NOECHO) \$(ECHO)\n";
+
+ if ($config{'INSTALL_ZEBRA'} eq "yes") {
+ $install .= _update_zebra_conf_target();
+ }
+
+ $install .= upgrade();
+
+ return $install;
+}
+
+=head2 _update_zebra_conf_target
+
+Add an installation target for updating
+Zebra's configuration files.
+
+=cut
+
+sub _update_zebra_conf_target {
+
+ my $target = "\nupdate_zebra_conf ::\n";
+ $target .= "\tumask 022; \$(MOD_INSTALL) \\\n";
+ $target .= "\t\t\$(KOHA_INST_ZEBRA_CONF_DIR) \$(KOHA_DEST_ZEBRA_CONF_DIR) \n";
+ $target .= "\t\$(NOECHO) chmod -R u+w \$(KOHA_DEST_ZEBRA_CONF_DIR)\n" unless $^O eq "MSWin32";
+ $target .= "\tumask 022; \$(MOD_INSTALL) \\\n";
+ $target .= "\t\t\$(KOHA_INST_PAZPAR2_CONF_DIR) \$(KOHA_DEST_PAZPAR2_CONF_DIR) \n";
+ $target .= "\t\$(NOECHO) chmod -R u+w \$(KOHA_DEST_PAZPAR2_CONF_DIR)\n" unless $^O eq "MSWin32";
+
+ return $target;
+}
+
+sub upgrade {
+ my $upgrade = "";
+
+ my $backup_suffix;
+ if (exists $install_log_values{'KOHA_INSTALLED_VERSION'}) {
+ my $version = $install_log_values{'KOHA_INSTALLED_VERSION'};
+ $version =~ s/\./_/g;
+ $backup_suffix = "_koha_$version";
+ } else {
+ $backup_suffix = "_upgrade_backup";
+ }
+
+ $upgrade .= qq/
+MOD_BACKUP = \$(ABSPERLRUN) -Minstall_misc::UpgradeBackup -e 'backup_changed_files({\@ARGV}, '$backup_suffix', '\''\$(VERBINST)'\'', '\''\$(UNINST)'\'');' --
+
+upgrade :: make_upgrade_backup install
+\t\$(NOECHO) \$(NOOP)
+make_upgrade_backup ::
+\t\$(NOECHO) umask 022; \$(MOD_BACKUP) \\
+/;
+ foreach my $key (qw/KOHA_CONF_DIR INTRANET_TMPL_DIR INTRANET_WWW_DIR OPAC_TMPL_DIR OPAC_WWW_DIR
+ PAZPAR2_CONF_DIR ZEBRA_CONF_DIR/) {
+ $upgrade .= "\t\t\$(KOHA_INST_$key) \$(KOHA_DEST_$key) \\\n"
+ unless ($config{'INSTALL_ZEBRA'} ne "yes" and $key =~ /ZEBRA/) or
+ exists $skip_directories->{$key} or
+ not exists $target_directories->{$key};
+ }
+ $upgrade =~ s/\\\n$/\n/;
+
+ return $upgrade;
+}
+
+sub postamble {
+ # put directory mappings into Makefile
+ # so that Make will export as environment
+ # variables -- this is for the use of
+ # rewrite-confg.PL
+
+ # quote '$' in the two password parameters
+ my %config = %config;
+ $config{'DB_PASS'} =~ s/\$/\$\$/g;
+ if ($config{'INSTALL_ZEBRA'} eq "yes") {
+ $config{'ZEBRA_PASS'} =~ s/\$/\$\$/g;
+ }
+
+ my $env;
+ # Hereagain, we must alter syntax per platform...
+ if ( $^O eq 'MSWin32' ) {
+ # NOTE: it is imperative that there be no whitespaces in ENV=value...
+ $env = join("\n", map { "__${_}__=$target_directories->{$_}" } keys %$target_directories);
+ $env .= "\n\n";
+ $env .= join("\n", map { "__${_}__=$config{$_}" } keys %config);
+ }
+ else {
+ $env = join("\n", map { "export __${_}__ := $target_directories->{$_}" } keys %$target_directories);
+ $env .= "\n\n";
+ $env .= join("\n", map { "export __${_}__ := $config{$_}" } keys %config);
+ }
+
+ if ( $config{'RUN_DATABASE_TESTS'} eq 'yes' ) {
+ if ( open( my $confhandle, '>', 't/test-config.txt' ) ) {
+ print $confhandle "# This configuration file lets the t/Makefile prepare a test koha-conf.xml file.\n";
+ print $confhandle "# It is generated by the top-level Makefile.PL.\n";
+ print $confhandle "# It is separate from the standard koha-conf.xml so that you can edit this by hand and test with different configurations.\n";
+
+ # these directories will be relocated to the 't' directory
+ foreach my $dirname ( keys %$target_directories ) {
+ my $dir = $target_directories->{$dirname};
+ if ( exists $test_suite_override_dirs{$dirname} ) {
+ $dir = main::get_test_dir($dirname);
+ }
+ print $confhandle "$dirname = $dir\n"
+ }
+ print $confhandle "\n";
+
+ print $confhandle join( "\n", map { "$_ = $config{$_}" } keys( %config ) ), "\n";
+ close( $confhandle );
+ } else {
+ warn 'unable to open conf file for database dependent tests: $!';
+ }
+
+ }
+ return "$env\n";
+}
+