1 | #!/usr/bin/perl -w
|
---|
2 |
|
---|
3 | ###########################################################################
|
---|
4 | #
|
---|
5 | # incremental-buildcol.pl -- runs buildcol.pl with -incremental on
|
---|
6 | # A component of the Greenstone digital library software
|
---|
7 | # from the New Zealand Digital Library Project at the
|
---|
8 | # University of Waikato, New Zealand.
|
---|
9 | #
|
---|
10 | # Copyright (C) 2009 New Zealand Digital Library Project
|
---|
11 | #
|
---|
12 | # This program is free software; you can redistribute it and/or modify
|
---|
13 | # it under the terms of the GNU General Public License as published by
|
---|
14 | # the Free Software Foundation; either version 2 of the License, or
|
---|
15 | # (at your option) any later version.
|
---|
16 | #
|
---|
17 | # This program is distributed in the hope that it will be useful,
|
---|
18 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | # GNU General Public License for more details.
|
---|
21 | #
|
---|
22 | # You should have received a copy of the GNU General Public License
|
---|
23 | # along with this program; if not, write to the Free Software
|
---|
24 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
25 | #
|
---|
26 | ###########################################################################
|
---|
27 |
|
---|
28 |
|
---|
29 | # This program is designed to support incremental building of Greenstone
|
---|
30 | # Runs: buildcol.pl -incremental -builddir GSDLHOME/collect/$collect/index ...
|
---|
31 |
|
---|
32 |
|
---|
33 | BEGIN {
|
---|
34 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
35 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
36 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
37 | }
|
---|
38 |
|
---|
39 |
|
---|
40 | use strict;
|
---|
41 | no strict 'refs'; # allow filehandles to be variables and vice versa
|
---|
42 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
43 |
|
---|
44 | use util;
|
---|
45 | use colcfg;
|
---|
46 |
|
---|
47 | sub main
|
---|
48 | {
|
---|
49 | my ($argc,@argv) = @_;
|
---|
50 |
|
---|
51 | if (($argc==0) || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) {
|
---|
52 | my ($progname) = ($0 =~ m/^.*[\/|\\](.*?)$/);
|
---|
53 |
|
---|
54 |
|
---|
55 | print STDERR "\n";
|
---|
56 | print STDERR "Usage: $progname [buildcol.pl options] collection\n";
|
---|
57 | print STDERR "\n";
|
---|
58 |
|
---|
59 | exit(-1);
|
---|
60 | }
|
---|
61 |
|
---|
62 |
|
---|
63 | my $collection = pop @argv;
|
---|
64 |
|
---|
65 | my @filtered_argv = ();
|
---|
66 |
|
---|
67 | my $collect_dir = undef;
|
---|
68 | my $build_dir = undef;
|
---|
69 | my $site = undef;
|
---|
70 |
|
---|
71 | while (my $arg = shift @argv) {
|
---|
72 | if ($arg eq "-collectdir") {
|
---|
73 | $collect_dir = shift @argv;
|
---|
74 | push(@filtered_argv,$arg,$collect_dir);
|
---|
75 | }
|
---|
76 | elsif ($arg eq "-builddir") {
|
---|
77 | $build_dir = shift @argv;
|
---|
78 | push(@filtered_argv,$arg,$build_dir);
|
---|
79 | }
|
---|
80 | elsif ($arg eq "-site") {
|
---|
81 | $site = shift @argv;
|
---|
82 | push(@filtered_argv,$arg,$site);
|
---|
83 | }
|
---|
84 | else {
|
---|
85 | push(@filtered_argv,$arg);
|
---|
86 | }
|
---|
87 | }
|
---|
88 |
|
---|
89 | # get and check the collection name
|
---|
90 | if ((&colcfg::use_collection($site, $collection, $collect_dir)) eq "") {
|
---|
91 | print STDERR "Unable to use collection \"$collection\" within \"$collect_dir\"\n";
|
---|
92 | exit -1;
|
---|
93 | }
|
---|
94 |
|
---|
95 | if (!defined $build_dir) {
|
---|
96 | # Yes this is intentional that 'build_dir' points to "index"
|
---|
97 | $build_dir = &util::filename_cat ($ENV{'GSDLCOLLECTDIR'},"index");
|
---|
98 | push(@filtered_argv,"-builddir",$build_dir);
|
---|
99 | }
|
---|
100 |
|
---|
101 | my $quoted_argv = join(" ", map { "\"$_\"" } @filtered_argv);
|
---|
102 |
|
---|
103 | my $buildcol_cmd = "\"".&util::get_perl_exec()."\" -S buildcol.pl";
|
---|
104 |
|
---|
105 | # Read in the collection configuration file.
|
---|
106 | my ($collect_cfg_filename, $gs_mode) = &colcfg::get_collect_cfg_name(STDERR);
|
---|
107 |
|
---|
108 | my $collectcfg = &colcfg::read_collection_cfg ($collect_cfg_filename,$gs_mode);
|
---|
109 |
|
---|
110 | # look for build.cfg/buildConfig.xml
|
---|
111 | my $build_cfg_filename ="";
|
---|
112 |
|
---|
113 | if ($gs_mode eq "gs2") {
|
---|
114 | $build_cfg_filename = &util::filename_cat($build_dir,"build.cfg");
|
---|
115 | } else {
|
---|
116 | $build_cfg_filename = &util::filename_cat($build_dir, "buildConfig.xml");
|
---|
117 | }
|
---|
118 |
|
---|
119 | if (-e $build_cfg_filename) {
|
---|
120 |
|
---|
121 | # figure out if there has been a change of indexer
|
---|
122 | # (e.g. collect.cfg now says lucene, but build.cfg says mgpp)
|
---|
123 |
|
---|
124 | my $buildcfg = &colcfg::read_building_cfg ($build_cfg_filename, $gs_mode);
|
---|
125 | if ($buildcfg->{'buildtype'} ne $collectcfg->{'buildtype'}) {
|
---|
126 | print STDERR "*****\n";
|
---|
127 | print STDERR "* Change of indexer detected. Switching to full buildcol.pl.\n";
|
---|
128 | print STDERR "*****\n";
|
---|
129 | $buildcol_cmd .= " -removeold";
|
---|
130 | }
|
---|
131 | else {
|
---|
132 |
|
---|
133 | $buildcol_cmd .= " -incremental";
|
---|
134 | }
|
---|
135 | }
|
---|
136 | else {
|
---|
137 | # build.cfg doesn't exit
|
---|
138 | print STDERR "*****\n";
|
---|
139 | print STDERR "* First time built. Switching to full buildcol.pl.\n";
|
---|
140 | print STDERR "*****\n";
|
---|
141 | $buildcol_cmd .= " -removeold";
|
---|
142 | }
|
---|
143 |
|
---|
144 |
|
---|
145 | $buildcol_cmd .= " $quoted_argv \"$collection\"";
|
---|
146 |
|
---|
147 | my $buildcol_status = system($buildcol_cmd)/256;
|
---|
148 |
|
---|
149 | if ($buildcol_status != 0) {
|
---|
150 | print STDERR "Error: Failed to run: $buildcol_cmd\n";
|
---|
151 | print STDERR " $!\n" if ($! ne "");
|
---|
152 | exit(-1);
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | &main(scalar(@ARGV),@ARGV);
|
---|
157 |
|
---|
158 |
|
---|
159 |
|
---|
160 |
|
---|