#!/usr/bin/perl -w ########################################################################### # # full-import.pl -- runs import.pl with -incremental option on # A component of the Greenstone digital library software # from the New Zealand Digital Library Project at the # University of Waikato, New Zealand. # # Copyright (C) 2009 New Zealand Digital Library Project # # This program 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. # # This program 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 this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # ########################################################################### # This program is designed to support incremental building of Greenstone # Runs: import.pl -incremental ... BEGIN { die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'}; die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'}; unshift (@INC, "$ENV{'GSDLHOME'}/perllib"); } use strict; use util; sub main { my ($argc,@argv) = @_; if (($argc==0) || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) { my ($progname) = ($0 =~ m/^.*\/(.*?)$/); print STDERR "\n"; print STDERR "Usage: $progname [import.pl options] collection\n"; print STDERR "\n"; exit(-1); } my $collect = pop @argv; my @filtered_argv = (); my $collect_dir = undef; my $archive_dir = undef; while (my $arg = shift @argv) { # No actual filtering happens at the moment (@filterd_argv == @argv) # Useful to do it this way if we want incremental-import.pl # to start accepting its own arguments that are different to import.pl if ($arg eq "-collectdir") { $collect_dir = shift @argv; push(@filtered_argv,$arg,$collect_dir); } elsif ($arg eq "-archivedir") { $archive_dir = shift @argv; push(@filtered_argv,$arg,$archive_dir); } else { push(@filtered_argv,$arg); } } if (!defined $collect_dir) { $collect_dir = &util::filename_cat($ENV{'GSDLHOME'},"collect"); } my $this_collect_dir = &util::filename_cat($collect_dir,$collect); if (!-d $this_collect_dir) { print STDERR "Error: $this_collect_dir does not exist\n"; exit(-1); } if (!defined $archive_dir) { $archive_dir = &util::filename_cat($this_collect_dir,"archives"); } my $archiveinf_doc = &util::filename_cat($archive_dir,"archiveinf-doc"); &util::rename_gdbm_file($archiveinf_doc); # ensure gdb $archiveinf_doc .= ".gdb"; my $quoted_argv = join(" ", map { "\"$_\"" } @filtered_argv); my $import_cmd = "import.pl"; if (-e $archiveinf_doc) { $import_cmd .= " -incremental"; } else { ### print STDERR "$archiveinf_doc does not exist.\n"; print STDERR "*****\n"; print STDERR "First time built. Switching to full import.pl.\n"; print STDERR "*****\n"; $import_cmd .= " -removeold"; } $import_cmd .= " $quoted_argv \"$collect\""; my $import_status = system($import_cmd)/256; if ($import_status != 0) { print STDERR "Error: Failed to run: $import_cmd\n"; print STDERR " $!\n" if ($! ne ""); exit(-1); } } &main(scalar(@ARGV),@ARGV);