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

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

Sam and I fixed all calls to perl specifying a perlpath that was not embedded in quotes so that the perlpath is now nested in quotes (so that we don't have problems launching perl from within another perl script when there are spaces in the filepath).

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