[18470] | 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 |
|
---|
[24192] | 44 |
|
---|
[18470] | 45 | sub 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 |
|
---|
[18510] | 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) {
|
---|
[18470] | 89 | print STDERR "Error: $collect_dir does not exist\n";
|
---|
| 90 | exit(-1);
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 |
|
---|
[18510] | 94 | if (!defined $build_dir) {
|
---|
| 95 | $build_dir = &util::filename_cat($this_collect_dir,"building");
|
---|
| 96 | push(@filtered_argv,"-builddir",$build_dir);
|
---|
| 97 | }
|
---|
| 98 |
|
---|
[18470] | 99 |
|
---|
| 100 | my $quoted_argv = join(" ", map { "\"$_\"" } @argv);
|
---|
| 101 |
|
---|
| 102 | my $final_status = 0;
|
---|
[19409] | 103 |
|
---|
[20925] | 104 | # need to ensure that the path to perl is quoted (in case there's spaces in it)
|
---|
[24362] | 105 | my $launch_cmd = "\"".&util::get_perl_exec()."\" -S ";
|
---|
[18470] | 106 |
|
---|
| 107 | print "\n";
|
---|
| 108 | print "************************\n";
|
---|
| 109 | print "* Running Import Stage\n";
|
---|
| 110 | print "************************\n";
|
---|
[19409] | 111 |
|
---|
| 112 | my $import_cmd = $launch_cmd . "full-import.pl $quoted_argv \"$collect\"";
|
---|
| 113 |
|
---|
[18470] | 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 |
|
---|
[19409] | 122 | my $buildcol_cmd = $launch_cmd . "full-buildcol.pl $quoted_argv \"$collect\"";
|
---|
[18470] | 123 | my $buildcol_status = system($buildcol_cmd)/256;
|
---|
| 124 | if ($buildcol_status == 0) {
|
---|
[18529] | 125 | my $index_dir = &util::filename_cat($this_collect_dir,"index");
|
---|
[18527] | 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 | }
|
---|
[18470] | 135 |
|
---|
| 136 | print "\n";
|
---|
| 137 | print "************************\n";
|
---|
| 138 | print "* Moving \"building\" -> \"index\"\n";
|
---|
| 139 | print "************************\n";
|
---|
| 140 |
|
---|
[18510] | 141 | &util::mv($build_dir,$index_dir);
|
---|
[18470] | 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 |
|
---|