1 | #!/usr/bin/perl -w
|
---|
2 |
|
---|
3 | ###########################################################################
|
---|
4 | #
|
---|
5 | # full-rebuild.pl --
|
---|
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 will rebuild a collection from scratch
|
---|
30 | # Runs: full-import.pl -removeold [args]
|
---|
31 | # Followed by: full-buildcol.pl -removeold [args]
|
---|
32 | # Followed by: activate.pl -removeold [args]
|
---|
33 | # (assumming import.pl/buildcol.pl did not end with an error)
|
---|
34 |
|
---|
35 | BEGIN {
|
---|
36 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
37 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
38 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
39 | }
|
---|
40 |
|
---|
41 | use strict;
|
---|
42 | use util;
|
---|
43 |
|
---|
44 | sub main
|
---|
45 | {
|
---|
46 | my ($argc,@argv) = @_;
|
---|
47 |
|
---|
48 | if (($argc==0) || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) {
|
---|
49 | my ($progname) = ($0 =~ m/^.*\/(.*?)$/);
|
---|
50 |
|
---|
51 | print STDERR "\n";
|
---|
52 | print STDERR "This program runs full-import.pl, full-buildcol.pl, activate.pl (in each case removing any previously generated files in 'archives', 'building','index')\n";
|
---|
53 | print STDERR "\n";
|
---|
54 | print STDERR "Usage: $progname [options]| collection\n";
|
---|
55 | print STDERR "\n";
|
---|
56 | print STDERR " If a minus option is shared between import.pl and buildcol.pl then it can appear\n";
|
---|
57 | print STDERR " as is, such as -verbosity 5. This value will be passed to both programs.\n";
|
---|
58 | print STDERR " If a minus option is specific to one of the programs in particular, then prefix\n";
|
---|
59 | print STDERR " it with 'import:', 'buildcol:', or 'activate:' respectively, \n";
|
---|
60 | print STDERR " as in '-import:OIDtype hash_on_full_filename'\n";
|
---|
61 | print STDERR " Run '(full-)import.pl -h', '(full-)buildcol.pl -h', 'activate.pl -h' from the \n";
|
---|
62 | print STDERR " command line to see the specific values they take.\n";
|
---|
63 | print STDERR "\n";
|
---|
64 |
|
---|
65 | exit(-1);
|
---|
66 | }
|
---|
67 |
|
---|
68 | my @import_argv = ();
|
---|
69 | my @buildcol_argv = ();
|
---|
70 | my @activate_argv = ();
|
---|
71 |
|
---|
72 | my $site = undef;
|
---|
73 | my $collect_dir = undef;
|
---|
74 | my $build_dir = undef;
|
---|
75 | my $index_dir = undef;
|
---|
76 | my $verbosity = 2; # same as the default in buildcol.pl
|
---|
77 |
|
---|
78 | while (my $arg = shift @argv) {
|
---|
79 | if ($arg eq "-site") {
|
---|
80 | $site = shift @argv;
|
---|
81 | push(@import_argv,$arg,$site);
|
---|
82 | push(@buildcol_argv,$arg,$site);
|
---|
83 | push(@activate_argv,$arg,$site);
|
---|
84 | }
|
---|
85 | elsif ($arg eq "-collectdir") {
|
---|
86 | $collect_dir = shift @argv;
|
---|
87 | push(@import_argv,$arg,$collect_dir);
|
---|
88 | push(@buildcol_argv,$arg,$collect_dir);
|
---|
89 | push(@activate_argv,$arg,$collect_dir);
|
---|
90 | }
|
---|
91 | elsif ($arg eq "-importdir") {
|
---|
92 | # only makes sense in import.pl
|
---|
93 | my $import_dir = shift @argv;
|
---|
94 | push(@import_argv,$arg,$import_dir);
|
---|
95 | }
|
---|
96 | elsif ($arg eq "-builddir") {
|
---|
97 | # only makes sense in buildcol.pl and activate.pl
|
---|
98 | $build_dir = shift @argv;
|
---|
99 | push(@buildcol_argv,$arg,$build_dir);
|
---|
100 | push(@activate_argv,$arg,$build_dir);
|
---|
101 | }
|
---|
102 | elsif ($arg eq "-indexdir") {
|
---|
103 | # only makes sense in buildcol.pl and activate.pl
|
---|
104 | $index_dir = shift @argv;
|
---|
105 | push(@buildcol_argv,$arg,$index_dir);
|
---|
106 | push(@activate_argv,$arg,$index_dir);
|
---|
107 | }
|
---|
108 | elsif ($arg eq "-verbosity") {
|
---|
109 | $verbosity = shift @argv;
|
---|
110 | push(@import_argv,$arg,$verbosity);
|
---|
111 | push(@buildcol_argv,$arg,$verbosity);
|
---|
112 | push(@activate_argv,$arg,$verbosity);
|
---|
113 | }
|
---|
114 | elsif ($arg =~ /-import:(.*)$/) {
|
---|
115 | my $import_arg = "-".$1;
|
---|
116 | my $import_val = shift @argv;
|
---|
117 | push(@import_argv,$import_arg,$import_val);
|
---|
118 | }
|
---|
119 | elsif ($arg =~ /-buildcol:(.*)$/) {
|
---|
120 | my $buildcol_arg = "-".$1;
|
---|
121 | my $buildcol_val = shift @argv;
|
---|
122 | push(@buildcol_argv,$buildcol_arg,$buildcol_val);
|
---|
123 | }
|
---|
124 | elsif ($arg =~ /-activate:(.*)$/) {
|
---|
125 | my $activate_arg = "-".$1;
|
---|
126 | my $activate_val = shift @argv;
|
---|
127 | push(@activate_argv,$activate_arg,$activate_val);
|
---|
128 | }
|
---|
129 | elsif ($arg =~ "-OIDtype") {
|
---|
130 | shift @argv; # skip OIDtype (don't pass OIDtype to buildcol.pl. It's not currently accepted.)
|
---|
131 | # this allows us to run full-rebuild.pl -OIDtype filename for instance
|
---|
132 | }
|
---|
133 | else {
|
---|
134 | push(@import_argv,$arg);
|
---|
135 | push(@buildcol_argv,$arg);
|
---|
136 | push(@activate_argv,$arg);
|
---|
137 | }
|
---|
138 | }
|
---|
139 |
|
---|
140 | my $quoted_import_argv = join(" ", map { "\"$_\"" } @import_argv);
|
---|
141 | my $quoted_buildcol_argv = join(" ", map { "\"$_\"" } @buildcol_argv);
|
---|
142 | my $quoted_activate_argv = join(" ", map { "\"$_\"" } @activate_argv);
|
---|
143 |
|
---|
144 | my $final_status = 0;
|
---|
145 |
|
---|
146 | # need to ensure that the path to perl is quoted (in case there's spaces in it)
|
---|
147 | my $launch_cmd = "\"".&util::get_perl_exec()."\" -S ";
|
---|
148 |
|
---|
149 | print "\n";
|
---|
150 | print "************************\n";
|
---|
151 | print "* Running Import Stage\n";
|
---|
152 | print "************************\n";
|
---|
153 |
|
---|
154 | my $import_cmd = $launch_cmd . "full-import.pl $quoted_import_argv";
|
---|
155 |
|
---|
156 | my $import_status = system($import_cmd)/256;
|
---|
157 |
|
---|
158 | if ($import_status == 0) {
|
---|
159 | print "\n";
|
---|
160 | print "************************\n";
|
---|
161 | print "* Running Buildcol Stage\n";
|
---|
162 | print "************************\n";
|
---|
163 |
|
---|
164 | my $buildcol_cmd = $launch_cmd . "full-buildcol.pl $quoted_buildcol_argv";
|
---|
165 | my $buildcol_status = system($buildcol_cmd)/256;
|
---|
166 |
|
---|
167 | if ($buildcol_status == 0) {
|
---|
168 |
|
---|
169 | # run activate with -removeold, just like full-buildcol.pl called above runs buildcol.pl
|
---|
170 | my $activatecol_cmd = $launch_cmd . "activate.pl -removeold $quoted_activate_argv";
|
---|
171 | my $activatecol_status = system($activatecol_cmd)/256;
|
---|
172 | }
|
---|
173 | else {
|
---|
174 | $final_status = $buildcol_status;
|
---|
175 | }
|
---|
176 | }
|
---|
177 | else {
|
---|
178 | $final_status = $import_status;
|
---|
179 | }
|
---|
180 |
|
---|
181 | exit($final_status);
|
---|
182 | }
|
---|
183 |
|
---|
184 | &main(scalar(@ARGV),@ARGV);
|
---|
185 |
|
---|