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

Last change on this file since 12983 was 12003, checked in by davidb, 18 years ago

Scripts upgraded to perform more efficiently with incremental addition.

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