source: gsdl/trunk/bin/script/build@ 17253

Last change on this file since 17253 was 17253, checked in by kjdon, 16 years ago

added use strict; check whether site is non-empty not just defined to test for gs3

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 24.5 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# build --
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) 2000 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# This perl script may be called directly or by running build.bat on
29# windows (build.bat is in bin\windows)
30
31# Note that this script has grown over time and now has many options for
32# use when called from within the collector. If it appears to
33# over-complicate things a little, that's why.
34
35package build;
36
37use strict;
38no strict 'refs';
39
40use FileHandle;
41use File::Copy;
42
43BEGIN {
44
45 die "GSDLHOME not set - did you remember to source setup.bash (unix) or " .
46 "run setup.bat (windows)?\n" unless defined $ENV{'GSDLHOME'};
47 die "GSDLOS not set - did you remember to source setup.bash (unix) or " .
48 "run setup.bat (windows)?\n" unless defined $ENV{'GSDLOS'};
49 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
50
51 STDOUT->autoflush(1);
52 STDERR->autoflush(1);
53}
54
55use lib qq($ENV{'GSDLHOME'}/perllib/cpan);
56use Mail::Sendmail;
57use parsargv;
58use util;
59use cfgread;
60
61# set up path - this allows for paths not to be supplied to system calls
62# and overcomes problems when GSDLHOME contains spaces (double quoting
63# the call doesn't work on win2k and probably other variants of winnt)
64my $path_separator = ":";
65$path_separator = ";" if $ENV{'GSDLOS'} =~ /^windows$/;
66$ENV{'PATH'} = &util::filename_cat($ENV{'GSDLHOME'}, "bin", $ENV{'GSDLOS'}) .
67 $path_separator . &util::filename_cat($ENV{'GSDLHOME'}, "bin", "script") .
68 $path_separator . $ENV{'PATH'};
69
70# all the input option variables
71my ($optionfile, $indextype, $append, $manifest, $remove_archives, $remove_import, $buildtype, $maxdocs, @download, $collectdir, $site, $dontinstall, $save_archives, $out, $make_writable, $log_events, $event_log_file, $email_events, $mail_server, $statsfile, $event_header);
72
73&parse_args (\@ARGV);
74
75my ($collection) = @ARGV;
76
77if (!defined $collection || $collection !~ /\w/) {
78 print STDERR "You must specify a collection to build\n";
79 &print_usage();
80 die "\n";
81}
82
83if ($optionfile =~ /\w/) {
84 open (OPTIONS, $optionfile) || die "Couldn't open $optionfile\n";
85 my $line = [];
86 my $options = [];
87 while (defined ($line = &cfgread::read_cfg_line ('build::OPTIONS'))) {
88 push (@$options, @$line);
89 }
90 close OPTIONS;
91 &parse_args ($options);
92}
93
94if ($maxdocs == -1) {
95 $maxdocs = "";
96} else {
97 $maxdocs = "-maxdocs $maxdocs";
98}
99
100my $cdir = $collectdir;
101if (defined $site && $site =~ /\w/)
102{
103 die "GSDL3HOME not set." unless $ENV{'GSDL3HOME'};
104 $cdir = &util::filename_cat ($ENV{'GSDL3HOME'}, "sites", $site, "collect") unless $collectdir =~ /\w/;
105}
106else
107{
108 $cdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect") unless $collectdir =~ /\w/;
109}
110
111my $importdir = &util::filename_cat ($cdir, $collection, "import");
112my $archivedir = &util::filename_cat ($cdir, $collection, "archives");
113my $buildingdir = &util::filename_cat ($cdir, $collection, "building");
114my $indexdir = &util::filename_cat ($cdir, $collection, "index");
115my $bindir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin");
116
117my $use_out = 0;
118my $outfile = $out;
119if ($out !~ /^(STDERR|STDOUT)$/i) {
120 open (OUT, ">$out") || die "Couldn't open output file $out\n";
121 $out = "OUT";
122
123 # delete any existing .final file
124 &util::rm ("$outfile.final") if -e "$outfile.final";
125
126 $use_out = 1;
127}
128$out->autoflush(1);
129
130# delete any .kill file left laying around from a previously aborted build
131if (-e &util::filename_cat ($cdir, $collection, ".kill")) {
132 &util::rm (&util::filename_cat ($cdir, $collection, ".kill"));
133}
134
135# get maintainer email address from main.cfg
136my $maintainer = "NULL";
137my $main_cfg = &util::filename_cat ($ENV{'GSDLHOME'}, "etc", "main.cfg");
138my $cfgdata = &cfgread::read_cfg_file ($main_cfg, "maintainer");
139if (defined $cfgdata->{'maintainer'} && $cfgdata->{'maintainer'} =~ /\w/) {
140 $maintainer = $cfgdata->{'maintainer'};
141}
142# if maintainer is "NULL" email_events should be disabled
143if ($maintainer =~ /^NULL$/i) {
144 $email_events = "";
145}
146
147&main();
148
149if ($use_out) {
150 close OUT;
151
152 # if we've created a build log we'll copy it to the collection's etc
153 # directory
154 my ($etcdir);
155 if ($dontinstall) {
156 $etcdir = &util::filename_cat($collectdir, "etc", "build.log");
157 } else {
158 $etcdir = &util::filename_cat($ENV{'GSDLHOME'}, "collect", $collection, "etc", "build.log");
159 }
160
161 &util::cp($outfile, $etcdir);
162}
163
164sub print_usage {
165 print STDOUT "\n";
166 print STDOUT "build: Builds a Greenstone collection (i.e. runs import.pl and buildcol.pl\n";
167 print STDOUT " then copies the resulting indexes to the correct place).\n\n";
168 print STDOUT " usage: $0 [options] collection-name\n\n";
169 print STDOUT " options:\n";
170 print STDOUT " -optionfile file Get options from file, useful on systems where\n";
171 print STDOUT " long command lines may cause problems\n";
172 print STDOUT " -indextype mg|mgpp|lucene \n";
173 print STDERR " Specify the type of indexer used in this collection\n";
174 print STDERR " If -append is used then -indextype is needed to \n";
175 print STDERR " determine how to run buildcol.pl as well as update\n";
176 print STDERR " 'building' and 'index' according.\n";
177 print STDOUT " -append Add new files to existing collection\n";
178 print STDOUT " -manifest Use manifest.xml file to determine which files to process.\n";
179 print STDOUT " -remove_archives Remove archives directory after successfully\n";
180 print STDOUT " building the collection.\n";
181 print STDOUT " -remove_import Remove import directory after successfully\n";
182 print STDOUT " importing the collection.\n";
183 print STDOUT " -buildtype build|import If 'build' attempt to build directly\n";
184 print STDOUT " from archives directory (bypassing import\n";
185 print STDOUT " stage). Defaults to 'import'\n";
186 print STDOUT " -maxdocs number Maximum number of documents to build\n";
187 print STDOUT " -download directory Directory (or file) to get import documents from.\n";
188 print STDOUT " There may be multiple download directories and they\n";
189 print STDOUT " may be of type http://, ftp://, or file://\n";
190 print STDOUT " Note that any existing import directory will be\n";
191 print STDOUT " deleted to make way for the downloaded data if\n";
192 print STDOUT " a -download option is supplied\n";
193 print STDOUT " -collectdir directory Collection directory (defaults to " .
194 &util::filename_cat($ENV{'GSDLHOME'}). "collect for Greenstone2;\n";
195 print STDOUT" for Greenstone3 use -site option and then collectdir default will be\n";
196 print STDOUT " set to the collect folder within that site.)\n";
197 print STDOUT " -site Specify the site within a Greenstone3 installation to use.\n";
198 print STDOUT " -dontinstall Only applicable if -collectdir is set to something\n";
199 print STDOUT " other than the default. -dontinstall will suppress\n";
200 print STDOUT " the default behaviour which is to install the\n";
201 print STDOUT " collection to the gsdl/collect directory once it has\n";
202 print STDOUT " been built.\n";
203 print STDOUT " -save_archives Create a copy of the existing archives directory\n";
204 print STDOUT " called archives.org\n";
205 print STDOUT " -out Filename or handle to print output status to.\n";
206 print STDOUT " The default is STDERR\n";
207 print STDOUT " -statsfile name Filename or handle to print import statistics to.\n";
208 print STDOUT " The default is STDERR\n";
209 print STDOUT " -make_writable If set build will make the collection and any\n";
210 print STDOUT " temporary files it created globally writable after\n";
211 print STDOUT " it finishes\n";
212 print STDOUT " -log_events Log important events (collection built successfully\n";
213 print STDOUT " etc.) to event_log_file\n";
214 print STDOUT " -event_log_file file File to append important events to (defaults to\n";
215 print STDOUT " " . &util::filename_cat ($ENV{'GSDLHOME'}, "etc", "events.txt") . "\n";
216 print STDOUT " -email_events addr Comma separated list of email addresses to mail\n";
217 print STDOUT " details of important collection building events\n";
218 print STDOUT " -mail_server server The outgoing (SMTP) mail server to be used by\n";
219 print STDOUT " email_events. email_events will be disabled if\n";
220 print STDOUT " mail_server isn't set\n";
221 print STDOUT " -event_header file File containing a header to go on any event\n";
222 print STDOUT " messages. If not specified build will create a\n";
223 print STDOUT " generic header\n\n";
224 print STDOUT " [Type \"build | more\" if this help text scrolled off your screen]";
225 print STDOUT "\n" unless $ENV{'GSDLOS'} =~ /^windows$/i;
226}
227
228sub main {
229
230 if ($save_archives && -d $archivedir) {
231 print $out "caching original archives to ${archivedir}.org\n";
232 &util::cp_r ($archivedir, "${archivedir}.org");
233 }
234
235 # do the download thing if we have any -download options
236 if (scalar (@download)) {
237 # remove any existing import data
238 if (&has_content ($importdir)) {
239 print $out "build: WARNING: removing contents of $importdir\n";
240 &util::rm_r ($importdir);
241 }
242
243 foreach my $download_dir (@download) {
244
245 # remove any leading or trailing whitespace from filenames (just in case)
246 $download_dir =~ s/^\s+//;
247 $download_dir =~ s/\s+$//;
248
249 if ($download_dir =~ /^(http|ftp):\/\//) {
250 # use wget to mirror http or ftp urls
251 # options used are:
252 # -P = the directory to download documents to
253 # -np = don't ascend to parent directories. this means that only documents
254 # that live in the same directory or below on the same server as
255 # the given url will be downloaded
256 # -nv = not too verbose
257 # -r = recursively mirror
258 # -N = use time-stamping to see if an up-to-date local copy of each
259 # file already exists. this may be useful if wget fails and
260 # is restarted
261 # -l inf = infinite recursion depth
262 # -R "*\?*" = don't download cgi based urls
263 # -o = the output file to write download status to (only used if the -out
264 # option was given to build)
265
266 my $download_cmd = "perl -S gsWget.pl -P \"$importdir\" -np -nv";
267 $download_cmd .= " -r -N -l inf -R \"*\\?*\"";
268 $download_cmd .= " -o \"$outfile.download\"" if $use_out;
269 $download_cmd .= " \"$download_dir\"";
270 system ($download_cmd);
271
272 # note that wget obeys the robot rules. this means that it will have
273 # downloaded a robots.txt file if one was present. since it's unlikely
274 # anyone really wants to include it in a collection we'll delete it.
275 # robots.txt shouldn't be more than two directories deep (I think it will
276 # always be exactly two deep but will look for it in the top directory too)
277 # so that's as far as we'll go looking for it.
278 if (opendir (DIR, $importdir)) {
279 my @files = readdir DIR;
280 closedir DIR;
281 foreach my $file (@files) {
282 next if $file =~ /^\.\.?$/;
283 if ($file =~ /^robots.txt$/i) {
284 &util::rm (&util::filename_cat ($importdir, $file));
285 last;
286 } else {
287 $file = &util::filename_cat ($importdir, $file);
288 if (-d $file) {
289 if (opendir (DIR, $file)) {
290 my @files2 = readdir DIR;
291 closedir DIR;
292 foreach my $file2 (@files2) {
293 if ($file2 =~ /^robots.txt$/i) {
294 &util::rm (&util::filename_cat ($file, $file2));
295 last;
296 }
297 }
298 }
299 }
300 }
301 }
302 }
303
304 # if using output directory append the file download output to it
305 &append_file ($out, "$outfile.download");
306
307 } else {
308 # we assume anything not beginning with http:// or ftp://
309 # is a file or directory on the local file system.
310 $download_dir =~ s/^file:(\/\/)?//;
311 $download_dir =~ s/^\s+//; # may be whitespace between "file://" and the rest
312
313 if (-e $download_dir) {
314 # copy download_dir and all it contains to the import directory
315 my $download_cmd = "perl -S filecopy.pl";
316 $download_cmd .= " -collectdir \"$collectdir\"" if $collectdir =~ /\w/;
317 $download_cmd .= " -site \"$site\"" if $site =~ /\w/;
318 $download_cmd .= " -out \"$outfile.download\"" if $use_out;
319 $download_cmd .= " \"" . $download_dir . "\" " . $collection;
320
321 my $download_status = system ($download_cmd);
322 if ($download_status > 0)
323 {
324 die "Failed to execute: $download_cmd\n";
325 }
326
327
328 # if using output directory append the file download output to it
329 &append_file ($out, "$outfile.download");
330 } else {
331 print $out "WARNING: '$download_dir' does not exist\n";
332 }
333 }
334 }
335 }
336
337 `echo $importdir ; ls $importdir `;
338
339 if (-e &util::filename_cat ($archivedir, "archives.inf")) {
340 if (&has_content ($importdir)) {
341 if ($buildtype eq "build") {
342 &gsdl_build();
343 } else {
344 &gsdl_import();
345 &gsdl_build();
346 }
347 } else {
348 # there are archives but no import, build directly from archives
349 print $out "build: no import material was found, building directly\n";
350 print $out " from archives\n";
351 &gsdl_build();
352 }
353 } else {
354 if (&has_content ($importdir)) {
355 if ($buildtype eq "build") {
356 print $out "build: can't build directly from archives as no\n";
357 print $out " imported archives exist (did you forget to\n";
358 print $out " move the contents of $collection/import to\n";
359 print $out " collection/archives?)\n";
360 }
361 &gsdl_import();
362 if (&has_content ($archivedir, "^archives.inf\$")) {
363 &gsdl_build();
364 } else {
365 my $msg = "build: ERROR: The collection could not be built as no\n";
366 $msg .= " valid data was imported. Are at least some of\n";
367 $msg .= " the files you imported in a format that can be\n";
368 $msg .= " processed by the specified Greenstone plugins?\n";
369 print $out $msg;
370 &log_event ($msg);
371 &final_out (6) if $use_out;
372 die "\n";
373 }
374 } else {
375 # no import or archives
376 my $msg = "build: ERROR: The collection could not be built as it contains no data.\n";
377 print $out $msg;
378 &log_event ($msg);
379 &final_out (1) if $use_out;
380 die "\n";
381 }
382 }
383
384 if ($collectdir ne "" && !$dontinstall) {
385
386 my $install_collectdir;
387 if (defined $ENV{'GSDL3HOME'})
388 {
389
390 if ((defined $site) && ($site ne ""))
391 {
392 $install_collectdir = &util::filename_cat ($ENV{'GSDL3HOME'}, "sites", $site, "collect");
393 }
394 else
395 {
396 my $msg = "build: ERROR: Need to specify the site within the Greenstone3 installation.";
397 print $out $msg;
398 &log_event ($msg);
399 &final_out (6) if $use_out;
400 die "\n";
401 }
402 }
403 else
404 {
405 $install_collectdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect");
406 }
407
408 if (!&util::filenames_equal ($collectdir, $install_collectdir)) {
409
410 # install collection to gsdl/collect
411 print $out "installing the $collection collection\n";
412 my $newdir = &util::filename_cat ($install_collectdir, $collection);
413 my $olddir = &util::filename_cat ($collectdir, $collection);
414 if (-d $newdir) {
415 my $msg = "build: Could not install collection as $newdir\n" .
416 " already exists. Collection will remain at\n$olddir\n";
417
418 print $out $msg;
419 &log_event ($msg);
420 &final_out (4) if $use_out;
421 die "\n";
422 }
423 if (!&File::Copy::move ($olddir, $newdir)) {
424 my $msg = "build: Failed to install collection to $newdir\n" .
425 " Collection will remain at $olddir\n";
426 print $out $msg;
427 &log_event ($msg);
428 &final_out (5) if $use_out;
429 die "\n";
430 }
431 }
432 }
433
434 &log_event ("The $collection collection was built successfully\n");
435 &final_out (0) if $use_out;
436}
437
438sub gsdl_import {
439
440 print $out "importing the $collection collection\n\n";
441
442 my $import_cmd = "perl -S import.pl";
443 $import_cmd .= " -out \"$outfile.import\"" if $use_out;
444 if ($append) {
445 $import_cmd .= " -keepold";
446 if (not $manifest) {
447 # if we are appending, with no manifest, assume incremental
448 $import_cmd .= " -incremental";
449 }
450 } else {
451 $import_cmd .= " -removeold";
452 }
453
454 $import_cmd .= " -manifest manifest.xml" if ($manifest);
455 $import_cmd .= " -site \"$site\"" if $site =~ /\w/;
456 $import_cmd .= " -collectdir \"$collectdir\"" if $collectdir =~ /\w/;
457 $import_cmd .= " -statsfile \"$statsfile\"" if $statsfile =~ /\w/;
458 $import_cmd .= " $maxdocs $collection";
459
460 system ($import_cmd);
461 # if using output directory append the import output to it
462 &append_file ($out, "$outfile.import");
463
464 if (-e &util::filename_cat ($archivedir, "archives.inf")) {
465 print $out "$collection collection imported successfully\n\n";
466 if ($remove_import) {
467 print $out "removing import directory ($importdir)\n";
468 &util::rm_r ($importdir);
469 }
470 } else {
471 my $msg = "build: ERROR: import.pl failed\n";
472 print $out "\n$msg";
473 &log_event ($msg);
474 &final_out (2) if $use_out;
475 die "\n";
476 }
477}
478
479sub gsdl_build {
480
481 print $out "building the $collection collection\n\n";
482
483 my $build_cmd = "perl -S buildcol.pl";
484
485 my $removeold = 1;
486 if ($append) {
487 if ($indextype eq "lucene") {
488 $build_cmd .= " -keepold -incremental -builddir $indexdir";
489 $removeold = 0;
490 }
491 else {
492 $build_cmd .= " -removeold";
493 }
494 }
495 else {
496 $build_cmd .= " -removeold";
497 }
498
499 $build_cmd .= " -out \"$outfile.build\"" if $use_out;
500 $build_cmd .= " -site \"$site\"" if $site =~ /\w/;
501 $build_cmd .= " -collectdir \"$collectdir\"" if $collectdir =~ /\w/;
502 $build_cmd .= " $maxdocs $collection";
503 system ($build_cmd);
504 # if using output directory append the buildcol output to it
505 &append_file ($out, "$outfile.build");
506
507 if (($removeold && (-e &util::filename_cat ($buildingdir, "text", "$collection.ldb") || -e &util::filename_cat ($buildingdir, "text", "$collection.bdb"))) ||
508 ($removeold == 0 && (-e &util::filename_cat ($indexdir, "text", "$collection.ldb") || -e &util::filename_cat ($indexdir, "text", "$collection.bdb")))) {
509 print $out "$collection collection built successfully\n\n";
510 if ($remove_archives) {
511 print $out "removing archives directory ($archivedir)\n";
512 &util::rm_r ($archivedir);
513 }
514 } else {
515 my $msg = "build: ERROR: buildcol.pl failed\n";
516 print $out "\n$msg";
517 &log_event ($msg);
518 &final_out (3) if $use_out;
519 die "\n";
520 }
521
522 if ($removeold) {
523 # replace old indexes with new ones
524 if (&has_content ($indexdir)) {
525 print $out "removing old indexes\n";
526 &util::rm_r ($indexdir);
527 }
528 rmdir ($indexdir) if -d $indexdir;
529 &File::Copy::move ($buildingdir, $indexdir);
530 }
531 else {
532 # Do nothing. We have built into index dir rather than building dir
533 }
534
535 # remove the cached archives
536 if ($save_archives && -d "${archivedir}.org") {
537 &util::rm_r ("${archivedir}.org");
538 }
539}
540
541# return 1 if $dir directory contains any files or sub-directories (other
542# than those specified in the $ignore regular expression)
543sub has_content {
544 my ($dir, $ignore) = @_;
545
546 if (!-d $dir) {return 0;}
547
548 opendir (DIR, $dir) || return 0;
549 my @files = readdir DIR;
550 closedir DIR;
551
552 foreach my $file (@files) {
553 if ($file !~ /^\.{1,2}$/) {
554 return 1 unless (defined $ignore && $file =~ /$ignore/);
555 }
556 }
557
558 return 0;
559}
560
561sub append_file {
562 my ($handle, $file) = @_;
563
564 open (FILE, $file) || return;
565 undef $/;
566 print $handle <FILE>;
567 $/ = "\n";
568 close FILE;
569 &util::rm ($file);
570}
571
572# creates a file called $outfile.final and writes an output code to it.
573# An output code of 0 specifies that there was no error
574sub final_out {
575 my ($exit_code) = @_;
576
577 if ($use_out && (!-e "$outfile.final")) {
578
579 if (open (FINAL, ">$outfile.final")) {
580 print FINAL $exit_code;
581 close FINAL;
582 }
583 }
584}
585
586sub log_event {
587 my ($msg) = @_;
588
589 return unless ($log_events || $email_events);
590
591 # get the event header
592 my $eheader = "[Build Event]\n";
593 $eheader .= "Date: " . scalar localtime() . "\n";
594 if ($event_header ne "" && open (HEADER, $event_header)) {
595 undef $/;
596 $eheader .= <HEADER>;
597 $/ = "\n";
598 close HEADER;
599 } else {
600 $eheader .= "Collection: $collection\n";
601 $eheader .= "GSDLHOME: $ENV{'GSDLHOME'}\n";
602 $eheader .= "Build Location: $collectdir\n";
603 }
604
605 if ($log_events) {
606 my $fail = 0;
607 # append the event to the event log file
608 if ($event_log_file eq "" || !open (LOG, ">>$event_log_file")) {
609 # log file defaults to $GSDLHOME/etc/events.txt
610 $event_log_file = &util::filename_cat ($ENV{'GSDLHOME'}, "etc", "events.txt");
611 if (!open (LOG, ">>$event_log_file")) {
612 print $out "build: ERROR: Couldn't open event log file $event_log_file\n";
613 $fail = 1;
614 }
615 }
616 if (!$fail) {
617 print LOG $eheader;
618 print LOG $msg;
619 print LOG "\n";
620 close LOG;
621 }
622 }
623
624 if ($email_events) {
625 # if mail_server isn't set email_events does nothing
626 if ($mail_server eq "") {
627 print $out "build: WARNING: mail_server was not set - email_events option was ignored\n";
628 return;
629 }
630
631 my %mail = ('SMTP' => $mail_server,
632 'To' => $email_events,
633 'From' => $maintainer,
634 'Subject' => 'Greenstone Build Event'
635 );
636 $mail{'Message'} = $eheader . $msg;
637
638 if (!sendmail %mail) {
639 print $out "build: ERROR sending mail to $email_events\n";
640 print $out "'$Mail::Sendmail::error'\n";
641 }
642 }
643}
644
645
646sub parse_args {
647 my ($argref) = @_;
648
649 if (!parsargv::parse($argref,
650 'optionfile/.*/', \$optionfile,
651 'indextype/^(mg|mgpp|lucene)$/mg', \$indextype,
652 'append', \$append,
653 'manifest', \$manifest,
654 'remove_archives', \$remove_archives,
655 'remove_import', \$remove_import,
656 'buildtype/^(build|import)$/import', \$buildtype,
657 'maxdocs/^\-?\d+/-1', \$maxdocs,
658 'download/.+', \@download,
659 'collectdir/.*/', \$collectdir,
660 'site/.*/', \$site,
661 'dontinstall', \$dontinstall,
662 'save_archives', \$save_archives,
663 'out/.*/STDERR', \$out,
664 'make_writable', \$make_writable,
665 'log_events', \$log_events,
666 'event_log_file/.*/', \$event_log_file,
667 'email_events/.*/', \$email_events,
668 'mail_server/.*/', \$mail_server,
669 'statsfile/.*/STDERR', \$statsfile,
670 'event_header/.*/', \$event_header)) {
671
672 &print_usage();
673 die "\n";
674 }
675}
676
677
678END {
679
680 if ($make_writable) {
681 # chmod a+rw new collection
682 my $installed_collection = &util::filename_cat($ENV{'GSDLHOME'}, "collect", $collection);
683 &recursive_chmod($installed_collection);
684
685 # chmod a+rw anything we've left laying about in the tmp directory
686 if (($collectdir ne "") &&
687 (!&util::filenames_equal ($collectdir, &util::filename_cat($ENV{'GSDLHOME'}, "collect")))) {
688 &recursive_chmod($collectdir);
689 }
690 }
691
692 # this will produce a .final file if one doesn't exist yet - that
693 # should only happen if there's been an error somewhere in the perl
694 # code
695 &final_out(7);
696
697 sub recursive_chmod {
698 my ($dir) = @_;
699 return unless -d $dir;
700
701 chmod (0777, $dir);
702
703 opendir (DIR, $dir) || die;
704 my @files = readdir DIR;
705 closedir DIR;
706
707 foreach my $file (@files) {
708 next if $file =~ /^\.\.?$/;
709 $file = &util::filename_cat($dir, $file);
710 if (-d $file) {
711 &recursive_chmod ($file);
712 } else {
713 chmod (0777, $file);
714 }
715 }
716 }
717}
Note: See TracBrowser for help on using the repository browser.