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