From 25e1b9e49cd9b4d29847f9fdb70e2299daa65680 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Fri, 15 Feb 2008 21:04:35 +1300 Subject: [PATCH] installer: added 'make upgrade' target INTRANET_TMPL_DIR INTRANET_WWW_DIR OPAC_TMPL_DIR OPAC_WWW_DIR KOHA_CONF_DIR OPAC_TMPL_DIR OPAC_WWW_DIR PAZPAR2_CONF_DIR ZEBRA_CONF_DIR For each directory on the list, if an existing file installed file is different from the version coming from the new package, it is copied to a backup file whose name will have the suffix "_koha_" or "_upgrade_backup", depending on whether the --prev-install-log option was used or not during 'perl Makefile.PL'. The directories whose files were backed up were chosen because they contain configuration and HTML files that a non-programmer Koha user is likely to change. Consequently, the backup files produced by 'make upgrade' are not a substitute for doing a complete backup of one's Koha installation before upgrading. Signed-off-by: Chris Cormack Signed-off-by: Joshua Ferraro --- Makefile.PL | 36 ++++++++++++++ install_misc/UpgradeBackup.pm | 88 +++++++++++++++++++++++++++++++++++ misc/koha-install-log | 2 +- 3 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 install_misc/UpgradeBackup.pm diff --git a/Makefile.PL b/Makefile.PL index 3b8db26f54..79c0375eff 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -751,6 +751,7 @@ sub get_install_log_values { next if /^#/ or /^\s*$/; next if /^=/; next unless m/=/; + s/\s+$//g; my ($key, $value) = split /=/, $_, 2; $values->{$key} = $value; } @@ -1355,6 +1356,8 @@ install :: all install_koha warn_koha_env_vars $install .= _update_zebra_conf_target(); } + $install .= upgrade(); + return $install; } @@ -1378,6 +1381,39 @@ sub _update_zebra_conf_target { 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) \\ +\t\t\$(KOHA_INST_KOHA_CONF_DIR) \$(KOHA_DEST_KOHA_CONF_DIR) \\ +\t\t\$(KOHA_INST_INTRANET_TMPL_DIR) \$(KOHA_DEST_INTRANET_TMPL_DIR) \\ +\t\t\$(KOHA_INST_INTRANET_WWW_DIR) \$(KOHA_DEST_INTRANET_WWW_DIR) \\ +\t\t\$(KOHA_INST_OPAC_TMPL_DIR) \$(KOHA_DEST_OPAC_TMPL_DIR) \\ +\t\t\$(KOHA_INST_OPAC_WWW_DIR) \$(KOHA_DEST_OPAC_WWW_DIR) \\ +\t\t\$(KOHA_INST_OPAC_TMPL_DIR) \$(KOHA_DEST_OPAC_TMPL_DIR) \\ +\t\t\$(KOHA_INST_OPAC_WWW_DIR) \$(KOHA_DEST_OPAC_WWW_DIR) \\ +\t\t\$(KOHA_INST_PAZPAR2_CONF_DIR) \$(KOHA_DEST_PAZPAR2_CONF_DIR) \\ +\t\t\$(KOHA_INST_ZEBRA_CONF_DIR) \$(KOHA_DEST_ZEBRA_CONF_DIR) +/; + + return $upgrade; +} + sub postamble { # put directory mappings into Makefile # so that Make will export as environment diff --git a/install_misc/UpgradeBackup.pm b/install_misc/UpgradeBackup.pm new file mode 100644 index 0000000000..869d1e13dc --- /dev/null +++ b/install_misc/UpgradeBackup.pm @@ -0,0 +1,88 @@ +package install_misc::UpgradeBackup; + +# Copyright (C) 2008 LibLime +# +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it under the +# terms of the GNU General Public License as published by the Free Software +# Foundation; either version 2 of the License, or (at your option) any later +# version. +# +# Koha is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR +# A PARTICULAR PURPOSE. See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place, +# Suite 330, Boston, MA 02111-1307 USA + +use strict; +use File::Compare qw(compare); +use Cwd qw(cwd); +use File::Copy; +use File::Find; +use File::Spec; +use Exporter; + +use vars qw(@ISA @EXPORT $VERSION); + +@ISA = ('Exporter'); +@EXPORT = ('backup_changed_files'); +$VERSION = '3.00'; + +=head1 NAME + +install_misc::UpgradeBackup + +=head1 DESCRIPTION + +This is a helper module used during a 'make upgrade' that +creates backups of files updated during an upgrade. + +=cut + +sub backup_changed_files { + my $from_to = shift; + my $suffix = shift; + my $verbose = shift; + my $inc_uninstall = shift; + + my $cwd = cwd(); + foreach my $sourceroot (sort keys %$from_to) { + my $targetroot = $from_to->{$sourceroot}; + my $currdir = File::Spec->catdir($cwd, $sourceroot); + + next unless -d $currdir; + + chdir $currdir or die "could not change to $currdir: $!"; + + # expand path + find(sub { + return unless -f $_; + my $filename = $_; + + my $targetdir = File::Spec->catdir($targetroot, $File::Find::dir); + my $targetfile = File::Spec->catfile($targetdir, $filename); + my $sourcedir = File::Spec->catdir($currdir, $File::Find::dir); + my $sourcefile = File::Spec->catfile($sourcedir, $filename); + + if (-f $targetfile) { + my ($size) = (stat $sourcefile)[7]; + my $backup = $targetfile . $suffix; + unless (-s $targetfile == $size and not compare($sourcefile, $targetfile)) { + print "Backed up $targetfile to $backup\n"; + File::Copy::copy($targetfile, $backup); + } + } + }, "."); + } +} + +=head1 AUTHOR + +Galen Charlton + +=cut + +1; diff --git a/misc/koha-install-log b/misc/koha-install-log index 57677089ea..f2afff7a92 100644 --- a/misc/koha-install-log +++ b/misc/koha-install-log @@ -3,7 +3,7 @@ # It is meant for use during future # upgrades of Koha, and should not # be edited. -KOHA_INSTALLED_VERSION=__KOHA_INSTALLED_VERSION__ +KOHA_INSTALLED_VERSION=__KOHA_INSTALLED_VERSION__ LOG_DIR=__LOG_DIR__ DB_TYPE=__DB_TYPE__ DB_NAME=__DB_NAME__ -- 2.20.1