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

Last change on this file since 24371 was 24362, checked in by ak19, 13 years ago

The method of locating perl has changed once more: util now defines the fuction get_perl_exec which is used by other scripts to obtain the path to the perl executable they should use.

  • Property svn:executable set to *
File size: 4.2 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
35BEGIN {
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
41use strict;
42use util;
43
44
45sub main
46{
47 my ($argc,@argv) = @_;
48
49 if (($argc==0) || (($argc==1) && ($argv[0] =~ m/^--?h(elp)?$/))) {
50 my ($progname) = ($0 =~ m/^.*\/(.*?)$/);
51
52 print STDERR "\n";
53 print STDERR "Usage: $progname [option shared between import.pl and buildcol.pl] collection\n";
54 print STDERR "\n";
55
56 exit(-1);
57 }
58
59
60 my $collect = pop @argv;
61
62
63 my @filtered_argv = ();
64
65 my $collect_dir = undef;
66 my $build_dir = undef;
67
68 while (my $arg = shift @argv) {
69 if ($arg eq "-collectdir") {
70 $collect_dir = shift @argv;
71 push(@filtered_argv,$arg,$collect_dir);
72 }
73 elsif ($arg eq "-builddir") {
74 $build_dir = shift @argv;
75 push(@filtered_argv,$arg,$build_dir);
76 }
77 else {
78 push(@filtered_argv,$arg);
79 }
80 }
81
82
83 if (!defined $collect_dir) {
84 $collect_dir = &util::filename_cat($ENV{'GSDLHOME'},"collect");
85 }
86 my $this_collect_dir = &util::filename_cat($collect_dir,$collect);
87
88 if (!-d $this_collect_dir) {
89 print STDERR "Error: $collect_dir does not exist\n";
90 exit(-1);
91 }
92
93
94 if (!defined $build_dir) {
95 $build_dir = &util::filename_cat($this_collect_dir,"building");
96 push(@filtered_argv,"-builddir",$build_dir);
97 }
98
99
100 my $quoted_argv = join(" ", map { "\"$_\"" } @argv);
101
102 my $final_status = 0;
103
104 # need to ensure that the path to perl is quoted (in case there's spaces in it)
105 my $launch_cmd = "\"".&util::get_perl_exec()."\" -S ";
106
107 print "\n";
108 print "************************\n";
109 print "* Running Import Stage\n";
110 print "************************\n";
111
112 my $import_cmd = $launch_cmd . "full-import.pl $quoted_argv \"$collect\"";
113
114 my $import_status = system($import_cmd)/256;
115
116 if ($import_status == 0) {
117 print "\n";
118 print "************************\n";
119 print "* Running Buildcol Stage\n";
120 print "************************\n";
121
122 my $buildcol_cmd = $launch_cmd . "full-buildcol.pl $quoted_argv \"$collect\"";
123 my $buildcol_status = system($buildcol_cmd)/256;
124 if ($buildcol_status == 0) {
125 my $index_dir = &util::filename_cat($this_collect_dir,"index");
126
127 if (-e $index_dir) {
128 print "\n";
129 print "************************\n";
130 print "* Removing \"index\"\n";
131 print "************************\n";
132
133 &util::rm_r($index_dir);
134 }
135
136 print "\n";
137 print "************************\n";
138 print "* Moving \"building\" -> \"index\"\n";
139 print "************************\n";
140
141 &util::mv($build_dir,$index_dir);
142
143 }
144 else {
145 $final_status = $buildcol_status;
146 }
147 }
148 else {
149 $final_status = $import_status;
150 }
151
152 exit($final_status);
153}
154
155&main(scalar(@ARGV),@ARGV);
156
Note: See TracBrowser for help on using the repository browser.