source: main/trunk/greenstone2/bin/script/full-rebuild.pl@ 25573

Last change on this file since 25573 was 25573, checked in by ak19, 12 years ago

Adding in the new activate.pl script to be called at the end of the build process. It moves building to index after first deactivating the collection on the server (if this is running and a persistent server). After the move operation, it then activates the collection on the server again, if the server is still running and is a persistent server.

  • Property svn:executable set to *
File size: 6.5 KB
Line 
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# The -keepold argument can be passed into this script since this calls activate.pl
35# And activate.pl allows the contents of a src dir to be moved into the dest_dir
36# without destroying other (uniquely-named) contents of dest_dir.
37
38BEGIN {
39 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
40 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
41 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
42}
43
44use strict;
45use util;
46
47
48# This subroutine has been replaced by a call to activate.pl in sub main
49sub full_replace
50{
51 my ($site,$collect_dir,$collect,$build_dir,$index_dir) = @_;
52
53
54 if (!defined $build_dir) {
55 if (defined $collect_dir) {
56 $build_dir = &util::filename_cat($collect_dir,$collect, "building");
57 }
58 else {
59 if (defined $site) {
60 $build_dir = &util::filename_cat($ENV{'GSDL3HOME'},"sites",$site,"collect",$collect, "building");
61 }
62 else {
63 $build_dir = &util::filename_cat($ENV{'GSDLHOME'},"collect",$collect, "building");
64 }
65 }
66 }
67
68 if (!defined $index_dir) {
69 if (defined $collect_dir) {
70 $index_dir = &util::filename_cat($collect_dir,$collect, "index");
71 }
72 else {
73 if (defined $site) {
74 $index_dir = &util::filename_cat($ENV{'GSDL3HOME'},"sites",$site,"collect",$collect, "index");
75 }
76 else {
77 $index_dir = &util::filename_cat($ENV{'GSDLHOME'},"collect",$collect, "index");
78 }
79 }
80 }
81
82 if (-e $index_dir) {
83 print "\n";
84 print "************************\n";
85 print "* Removing \"index\"\n";
86 print "************************\n";
87
88 # An improvement would be to check on error status
89 &util::rm_r($index_dir);
90 }
91
92 print "\n";
93 print "************************\n";
94 print "* Moving \"building\" -> \"index\"\n";
95 print "************************\n";
96
97 # An improvement would be to check on error status
98 &util::mv($build_dir,$index_dir);
99}
100
101sub main
102{
103 my ($argc,@argv) = @_;
104
105 if (($argc==0) || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) {
106 my ($progname) = ($0 =~ m/^.*\/(.*?)$/);
107
108 print STDERR "\n";
109 print STDERR "This program runs import.pl followed by buildcol.pl (in both cases removing any previously\n";
110 print STDERR " generated files in 'archives' or 'building'), and then replaces the content of collection's\n";
111 print STDERR " 'index' directory with 'building'.";
112 print STDERR "\n";
113 print STDERR "Usage: $progname [option shared between import.pl and buildcol.pl] collection\n";
114 print STDERR "\n";
115
116 exit(-1);
117 }
118
119
120 my $collect = pop @argv;
121
122
123 my @import_argv = ();
124 my @buildcol_argv = ();
125 my @activate_argv = ();
126
127 my $site = undef;
128 my $collect_dir = undef;
129 my $build_dir = undef;
130 my $index_dir = undef;
131
132 while (my $arg = shift @argv) {
133 if ($arg eq "-site") {
134 $site = shift @argv;
135 push(@import_argv,$arg,$site);
136 push(@buildcol_argv,$arg,$site);
137 push(@activate_argv,$arg,$site);
138 }
139 elsif ($arg eq "-collectdir") {
140 $collect_dir = shift @argv;
141 push(@import_argv,$arg,$collect_dir);
142 push(@buildcol_argv,$arg,$collect_dir);
143 push(@activate_argv,$arg,$collect_dir);
144 }
145 elsif ($arg eq "-importdir") {
146 # only makes sense in import.pl
147 my $import_dir = shift @argv;
148 push(@import_argv,$arg,$import_dir);
149 }
150 elsif ($arg eq "-builddir") {
151 # only makes sense in buildcol.pl and activate.pl
152 $build_dir = shift @argv;
153 push(@buildcol_argv,$arg,$build_dir);
154 push(@activate_argv,$arg,$build_dir);
155 }
156 elsif ($arg eq "-indexdir") {
157 # only makes sense in buildcol.pl and activate.pl
158 $index_dir = shift @argv;
159 push(@buildcol_argv,$arg,$index_dir);
160 push(@activate_argv,$arg,$index_dir);
161 }
162 else {
163 push(@import_argv,$arg);
164 push(@buildcol_argv,$arg);
165 push(@activate_argv,$arg);
166 }
167 }
168
169
170 my $quoted_import_argv = join(" ", map { "\"$_\"" } @import_argv);
171 my $quoted_buildcol_argv = join(" ", map { "\"$_\"" } @buildcol_argv);
172 my $quoted_activate_argv = join(" ", map { "\"$_\"" } @activate_argv);
173
174 my $final_status = 0;
175
176 # need to ensure that the path to perl is quoted (in case there's spaces in it)
177 my $launch_cmd = "\"".&util::get_perl_exec()."\" -S ";
178
179 print "\n";
180 print "************************\n";
181 print "* Running Import Stage\n";
182 print "************************\n";
183
184 my $import_cmd = $launch_cmd . "full-import.pl $quoted_import_argv \"$collect\"";
185
186 my $import_status = system($import_cmd)/256;
187
188 if ($import_status == 0) {
189 print "\n";
190 print "************************\n";
191 print "* Running Buildcol Stage\n";
192 print "************************\n";
193
194 my $buildcol_cmd = $launch_cmd . "full-buildcol.pl $quoted_buildcol_argv \"$collect\"";
195 my $buildcol_status = system($buildcol_cmd)/256;
196
197 if ($buildcol_status == 0) {
198
199 #full_replace($site,$collect_dir,$collect,$build_dir,$index_dir);
200 my $activatecol_cmd = $launch_cmd . "activate.pl $quoted_activate_argv \"$collect\"";
201 my $activatecol_status = system($activatecol_cmd)/256;
202 }
203 else {
204 $final_status = $buildcol_status;
205 }
206 }
207 else {
208 $final_status = $import_status;
209 }
210
211 exit($final_status);
212}
213
214&main(scalar(@ARGV),@ARGV);
215
Note: See TracBrowser for help on using the repository browser.