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 ...
|
---|
31 | # Followed by: full-buildcol.pl -removeold ...
|
---|
32 | # (assumming import.pl did not end with an error)
|
---|
33 |
|
---|
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 |
|
---|
45 | sub full_replace
|
---|
46 | {
|
---|
47 | my ($site,$collect_dir,$collect,$build_dir,$index_dir) = @_;
|
---|
48 |
|
---|
49 |
|
---|
50 | if (!defined $build_dir) {
|
---|
51 | if (defined $collect_dir) {
|
---|
52 | $build_dir = &util::filename_cat($collect_dir,$collect, "building");
|
---|
53 | }
|
---|
54 | else {
|
---|
55 | if (defined $site) {
|
---|
56 | $build_dir = &util::filename_cat($ENV{'GSDL3HOME'},"sites",$site,"collect",$collect, "building");
|
---|
57 | }
|
---|
58 | else {
|
---|
59 | $build_dir = &util::filename_cat($ENV{'GSDLHOME'},"collect",$collect, "building");
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | if (!defined $index_dir) {
|
---|
65 | if (defined $collect_dir) {
|
---|
66 | $index_dir = &util::filename_cat($collect_dir,$collect, "index");
|
---|
67 | }
|
---|
68 | else {
|
---|
69 | if (defined $site) {
|
---|
70 | $index_dir = &util::filename_cat($ENV{'GSDL3HOME'},"sites",$site,"collect",$collect, "index");
|
---|
71 | }
|
---|
72 | else {
|
---|
73 | $index_dir = &util::filename_cat($ENV{'GSDLHOME'},"collect",$collect, "index");
|
---|
74 | }
|
---|
75 | }
|
---|
76 | }
|
---|
77 |
|
---|
78 | if (-e $index_dir) {
|
---|
79 | print "\n";
|
---|
80 | print "************************\n";
|
---|
81 | print "* Removing \"index\"\n";
|
---|
82 | print "************************\n";
|
---|
83 |
|
---|
84 | # An improvement would be to check on error status
|
---|
85 | &util::rm_r($index_dir);
|
---|
86 | }
|
---|
87 |
|
---|
88 | print "\n";
|
---|
89 | print "************************\n";
|
---|
90 | print "* Moving \"building\" -> \"index\"\n";
|
---|
91 | print "************************\n";
|
---|
92 |
|
---|
93 | # An improvement would be to check on error status
|
---|
94 | &util::mv($build_dir,$index_dir);
|
---|
95 | }
|
---|
96 |
|
---|
97 | sub main
|
---|
98 | {
|
---|
99 | my ($argc,@argv) = @_;
|
---|
100 |
|
---|
101 | if (($argc==0) || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) {
|
---|
102 | my ($progname) = ($0 =~ m/^.*\/(.*?)$/);
|
---|
103 |
|
---|
104 | print STDERR "\n";
|
---|
105 | print STDERR "This program runs import.pl followed by buildcol.pl (in both cases removing any previously\n";
|
---|
106 | print STDERR " generated files in 'archives' or 'building'), and then replaces the content of collection's\n";
|
---|
107 | print STDERR " 'index' directory with 'building'.";
|
---|
108 | print STDERR "\n";
|
---|
109 | print STDERR "Usage: $progname [option shared between import.pl and buildcol.pl] collection\n";
|
---|
110 | print STDERR "\n";
|
---|
111 |
|
---|
112 | exit(-1);
|
---|
113 | }
|
---|
114 |
|
---|
115 |
|
---|
116 | my $collect = pop @argv;
|
---|
117 |
|
---|
118 |
|
---|
119 | my @import_argv = ();
|
---|
120 | my @buildcol_argv = ();
|
---|
121 |
|
---|
122 | my $site = undef;
|
---|
123 | my $collect_dir = undef;
|
---|
124 | my $build_dir = undef;
|
---|
125 | my $index_dir = undef;
|
---|
126 |
|
---|
127 | while (my $arg = shift @argv) {
|
---|
128 | if ($arg eq "-site") {
|
---|
129 | $site = shift @argv;
|
---|
130 | push(@import_argv,$arg,$site);
|
---|
131 | push(@buildcol_argv,$arg,$site);
|
---|
132 | }
|
---|
133 | elsif ($arg eq "-collectdir") {
|
---|
134 | $collect_dir = shift @argv;
|
---|
135 | push(@import_argv,$arg,$collect_dir);
|
---|
136 | push(@buildcol_argv,$arg,$collect_dir);
|
---|
137 | }
|
---|
138 | elsif ($arg eq "-importdir") {
|
---|
139 | # only makes sense in import.pl
|
---|
140 | my $import_dir = shift @argv;
|
---|
141 | push(@import_argv,$arg,$import_dir);
|
---|
142 | }
|
---|
143 | elsif ($arg eq "-builddir") {
|
---|
144 | # only makes sense in buildcol.pl
|
---|
145 | $build_dir = shift @argv;
|
---|
146 | push(@buildcol_argv,$arg,$build_dir);
|
---|
147 | }
|
---|
148 | elsif ($arg eq "-indexdir") {
|
---|
149 | # only makes sense in buildcol.pl
|
---|
150 | $index_dir = shift @argv;
|
---|
151 | push(@buildcol_argv,$arg,$index_dir);
|
---|
152 | }
|
---|
153 | else {
|
---|
154 | push(@import_argv,$arg);
|
---|
155 | push(@buildcol_argv,$arg);
|
---|
156 | }
|
---|
157 | }
|
---|
158 |
|
---|
159 |
|
---|
160 | my $quoted_import_argv = join(" ", map { "\"$_\"" } @import_argv);
|
---|
161 | my $quoted_buildcol_argv = join(" ", map { "\"$_\"" } @buildcol_argv);
|
---|
162 |
|
---|
163 | my $final_status = 0;
|
---|
164 |
|
---|
165 | # need to ensure that the path to perl is quoted (in case there's spaces in it)
|
---|
166 | my $launch_cmd = "\"".&util::get_perl_exec()."\" -S ";
|
---|
167 |
|
---|
168 | print "\n";
|
---|
169 | print "************************\n";
|
---|
170 | print "* Running Import Stage\n";
|
---|
171 | print "************************\n";
|
---|
172 |
|
---|
173 | my $import_cmd = $launch_cmd . "full-import.pl $quoted_import_argv \"$collect\"";
|
---|
174 |
|
---|
175 | my $import_status = system($import_cmd)/256;
|
---|
176 |
|
---|
177 | if ($import_status == 0) {
|
---|
178 | print "\n";
|
---|
179 | print "************************\n";
|
---|
180 | print "* Running Buildcol Stage\n";
|
---|
181 | print "************************\n";
|
---|
182 |
|
---|
183 | my $buildcol_cmd = $launch_cmd . "full-buildcol.pl $quoted_buildcol_argv \"$collect\"";
|
---|
184 | my $buildcol_status = system($buildcol_cmd)/256;
|
---|
185 |
|
---|
186 | if ($buildcol_status == 0) {
|
---|
187 |
|
---|
188 | full_replace($site,$collect_dir,$collect,$build_dir,$index_dir);
|
---|
189 | }
|
---|
190 | else {
|
---|
191 | $final_status = $buildcol_status;
|
---|
192 | }
|
---|
193 | }
|
---|
194 | else {
|
---|
195 | $final_status = $import_status;
|
---|
196 | }
|
---|
197 |
|
---|
198 | exit($final_status);
|
---|
199 | }
|
---|
200 |
|
---|
201 | &main(scalar(@ARGV),@ARGV);
|
---|
202 |
|
---|