root/gsdl/trunk/bin/script/build @ 14925

Revision 14925, 24.1 KB (checked in by dmn, 12 years ago)

davidbs changes to update for gs3 building

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