root/main/trunk/greenstone2/bin/script/full-rebuild.pl @ 24192

Revision 24192, 4.6 KB (checked in by ak19, 8 years ago)

Sam discovered that using dollar-Config{perlpath} in place of dollar-hat-X is the better way to obtain the path to the perl that is being used. We hope this will not be a relative path on the Mac as dollar-hat-x was on Professor Witten's Mac when we tried it there today.

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