source: trunk/gsdl/bin/script/create_distributions.pl@ 2429

Last change on this file since 2429 was 2429, checked in by sjboddie, 23 years ago

* empty log message *

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 25.3 KB
Line 
1#!/usr/bin/perl -w
2
3
4BEGIN {
5 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
6 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
7}
8
9
10# create_distributions.pl creates the following distributions from the gsdl
11# directory pointed to by $GSDLHOME (although it uses the main CVS
12# repository to get the latest source code distribution).
13
14# Windows distribution - gsdl-x.xx-win32.exe
15# Creates directory structure for this - use installshield and
16# packagefortheweb to create self-extracting executable
17
18# Linux distribution - gsdl-x.xx-linux.tgz
19
20# Source distribution - gsdl-x.xx.tgz
21
22# cd-rom distribution = gsdl-x.xx-cdrom.tgz
23# Creates directory structure - use installshield to create media
24# for writing to cd-rom
25
26# all collections in $GSDLHOME/collect (except modelcol and those
27# explicitly ignored by -ignorecol options):
28# pre-built (collname-prebuilt) .tgz .zip
29# unbuilt (collname) .tgz .zip
30
31
32# creates ChangeLog using `cvs2cl.pl -P -F trunk -r -S -l "-d'date<tomorrow'"
33# where date of last distribution is read from the last line of
34# $GSDLHOME/DistDates or from -ChangeLogDate command line option
35# should use something like cvs2cl.pl ... -l "-r'last_tag' -r'this_tag'" but
36# I can't get cvs to ignore files which contain neither last_tag or this_tag
37# so ChangeLog contains lots of ancient stuff
38
39# sets a cvs tag called gsdl-x_xx-distribution (unless -cvs_tag is set
40# in which case it uses that)
41
42# creates a copy of everything in cvs repository in $tmpdir
43
44# edits /tmp/gsdl/etc/VERSION, /tmp/gsdl/src/w32server/fnord.cpp
45# and /tmp/gsdl/cgi-bin/gsdlsite.cfg to use new version number
46# and default GSDLHOME
47
48# temporary working directory
49my $tmpdir = '/tmp/sjboddie';
50
51# docs directory - up-to-date copy of everything to go in the docs directory
52# (including the README.txt) is expected to live here
53my $docdir = '/home/nzdl/gsdl-docs';
54
55# where the windows binaries live (including library.exe and server.exe)
56# this currently relies on being a directory ending in "windows"
57my $winbin = "$ENV{'GSDLHOME'}/bin/windows";
58
59# ditto for linux binaries (don't forget getpw)
60my $linuxbin = "$ENV{'GSDLHOME'}/bin/linux";
61
62my $cvsroot = '/home/nzdl/gsdl-src';
63
64use parsargv;
65use util;
66
67use Cwd;
68
69sub print_usage {
70 print STDERR "\n";
71 print STDERR "create_distributions.pl: Packages up Greenstone distributions.\n\n";
72 print STDERR " usage: $0 [options]\n\n";
73 print STDERR " options:\n";
74 print STDERR " -version_num version number of distribution (x.xx)\n";
75 print STDERR " -cvs_tag cvs tag from which to create distributions\n";
76 print STDERR " - if not set latest versions will be used and\n";
77 print STDERR " a tag will be set\n";
78 print STDERR " -no_cdrom don't create cd-rom version\n";
79 print STDERR " -no_cols don't attempt to create any collection distributions\n";
80 print STDERR " -only_cols create collection distributions only\n";
81 print STDERR " -includecol collection to include (by default all collections in\n";
82 print STDERR " $ENV{'GSDLHOME'}/collect will be included\n";
83 print STDERR " -ignorecol directory in $ENV{'GSDLHOME'}/collect to ignore (i.e.\n";
84 print STDERR " don't include as collection in distribution)\n";
85 print STDERR " -output_dir directory to output distributions to\n";
86 print STDERR " -NoChangeLog don't create ChangeLog\n";
87 print STDERR " -UseExistingLog use $ENV{'GSDLHOME'}/ChangeLog rather than creating one\n";
88 print STDERR " -ChangeLogDate date from which to begin ChangeLog - note that ChangeLog\n";
89 print STDERR " will always run from date to most recent commits, even if\n";
90 print STDERR " cvs_tag is for a previous revision\n\n";
91}
92
93&main ();
94
95sub main {
96 if (!parsargv::parse(\@ARGV,
97 'version_num/\d\.\d\d[a-z]?', \$version_num,
98 'cvs_tag/.*/', \$cvs_tag,
99 'no_cdrom', \$no_cdrom,
100 'no_cols', \$no_cols,
101 'only_cols', \$only_cols,
102 'includecol/.*', \@includecols,
103 'ignorecol/.*', \@ignorecols,
104 'NoChangeLog', \$nochangelog,
105 'UseExistingLog', \$useexistinglog,
106 'ChangeLogDate/.*/', \$changelogdate,
107 'output_dir/.*/', \$output_dir)) {
108 &print_usage();
109 die "\n";
110 }
111
112 $output_dir = "." unless $output_dir =~ /\w/;
113 mkdir ($output_dir, 0777) unless -d $output_dir;
114
115 my $have_tag = 1;
116 if ($cvs_tag !~ /\w/) {
117 $cvs_tag = $version_num;
118 $cvs_tag =~ s/\./\_/g;
119 $cvs_tag = "gsdl-" . $cvs_tag . "-distribution";
120 $have_tag = 0;
121 }
122
123 &create_changelog() unless ($nochangelog || $useexistinglog);
124
125 if (!$only_cols) {
126
127 # tag repository
128 if (!$have_tag) {
129 print STDERR "\ntagging with $cvs_tag\n";
130 chdir ($ENV{'GSDLHOME'});
131 `cvs tag $cvs_tag`;
132 }
133
134 # cvs export gsdl to $tmpdir
135 print STDERR "\nexporting gsdl ($cvs_tag) to $tmpdir\n\n";
136 chdir ($tmpdir);
137 `cvs -d $cvsroot export -r $cvs_tag gsdl`;
138
139 # copy ChangeLog into $tmpdir/gsdl
140 &util::cp (&util::filename_cat($ENV{'GSDLHOME'}, "ChangeLog"),
141 &util::filename_cat($tmpdir, "gsdl")) unless $nochangelog;
142
143 # edit the VERSION and fnord.cpp files
144 &edit_files();
145
146 &create_windows_distribution();
147 &create_linux_distribution();
148 &create_src_distribution();
149 &create_cdrom_distribution() unless $no_cdrom;
150 }
151
152 &create_collection_distributions() unless $no_cols;
153}
154
155sub create_windows_distribution {
156 my $windows_dist_dir = &util::filename_cat ($output_dir, "gsdl-" . $version_num . "-win32");
157 mkdir ($windows_dist_dir, 0777);
158
159 # docs directory and README.TXT
160# &install_docs ($windows_dist_dir, 1); -- no docs for windows web installation
161
162 # gsdl directory
163 &install_gsdl ($windows_dist_dir);
164
165 # src directory
166 &install_src ($windows_dist_dir, "windows");
167
168 # Windows directory
169 &install_windows_specific ($windows_dist_dir, 0);
170}
171
172sub create_linux_distribution {
173 my $linux_dir = "gsdl-" . $version_num . "-linux";
174 my $linux_dist_dir = &util::filename_cat ($output_dir, $linux_dir);
175 mkdir ($linux_dist_dir, 0777);
176
177 # empty "collect" directory
178 mkdir (&util::filename_cat($linux_dist_dir, "collect"), 0777);
179
180 # docs directory, README.TXT, COPYING and Support.htm
181 &install_docs ($linux_dist_dir, 1);
182
183 # gsdl directory
184 &install_gsdl ($linux_dist_dir);
185
186 # src directory
187 &install_src ($linux_dist_dir, "unix");
188
189 # Unix directory
190 &install_unix_specific ($linux_dist_dir);
191
192 # tar and gzip it
193 &zip ($linux_dir, $linux_dir, $output_dir, 2);
194 &util::rm_r ($linux_dist_dir);
195}
196
197sub create_src_distribution {
198 my $src_zip = "gsdl-" . $version_num . "-src";
199 # we want the COPYING file in the source distribution too
200 &util::cp (&util::filename_cat($docdir, "COPYING"),
201 &util::filename_cat($tmpdir, "gsdl"));
202# &edit_gsdlsite("/home/gsdl");
203 &zip ($src_zip, "gsdl", $tmpdir, 2);
204 &util::cp (&util::filename_cat($tmpdir, "$src_zip.tgz"), $output_dir);
205 # remove the COPYING file again to avoid confusion (it's copied to the right
206 # places by install_docs() for other distributions)
207 &util::rm (&util::filename_cat($tmpdir, "COPYING"));
208}
209
210sub create_cdrom_distribution {
211 my $cdrom_dist_dir = &util::filename_cat ($output_dir, "gsdl-" . $version_num . "-cdrom");
212 mkdir ($cdrom_dist_dir, 0777);
213
214 # collect directory (empty for now. we'll add collections manually)
215 mkdir (&util::filename_cat ($cdrom_dist_dir, "collect"), 0777);
216
217 # docs directory and README.TXT
218 &install_docs ($cdrom_dist_dir, 0);
219
220 # gsdl directory
221 &install_gsdl ($cdrom_dist_dir);
222
223 # src directory
224 &install_src ($cdrom_dist_dir, "cdrom");
225
226 # Windows directory
227 &install_windows_specific ($cdrom_dist_dir, 1);
228
229 # Unix directory
230 &install_unix_specific ($cdrom_dist_dir);
231}
232
233# isweb is 1 if it's one of the web distributions (i.e. if we don't
234# want to install the manual) - this shouldn't be called at all for
235# windows web installation as it doesn't use docs at all (not much
236# point for self-extracting exe).
237sub install_docs {
238 my ($install_dir, $isweb) = @_;
239
240 # docs directory, README.TXT, COPYING and Support.htm
241 &util::cp_r (&util::filename_cat($docdir, "docs"), $install_dir);
242 &util::cp (&util::filename_cat($docdir, "README.TXT"), $install_dir);
243 &util::cp (&util::filename_cat($docdir, "COPYING"), $install_dir);
244 &util::cp (&util::filename_cat($docdir, "Support.htm"), $install_dir);
245 # don't want manual for web distributions
246 if ($isweb) {
247 my $manfile = &util::filename_cat ($install_dir, "docs", "Manual.pdf");
248 &util::rm ($manfile) if -e $manfile;
249 }
250}
251
252sub install_gsdl {
253 my ($install_dir) = @_;
254
255 my $gsdldir = &util::filename_cat ($install_dir, "gsdl");
256 my $gsdlbindir = &util::filename_cat ($gsdldir, "bin");
257 mkdir ($gsdldir, 0777);
258 mkdir ($gsdlbindir, 0777);
259 &util::cp_r (&util::filename_cat ($tmpdir, "gsdl", "bin", "script"), $gsdlbindir);
260 &util::cp_r (&util::filename_cat ($tmpdir, "gsdl", "cgi-bin"), $gsdldir);
261 &util::cp_r (&util::filename_cat ($tmpdir, "gsdl", "collect"), $gsdldir);
262 &util::cp_r (&util::filename_cat ($tmpdir, "gsdl", "etc"), $gsdldir);
263 &util::cp_r (&util::filename_cat ($tmpdir, "gsdl", "images"), $gsdldir);
264 &util::cp_r (&util::filename_cat ($tmpdir, "gsdl", "macros"), $gsdldir);
265 &util::cp_r (&util::filename_cat ($tmpdir, "gsdl", "perllib"), $gsdldir);
266 &util::cp_r (&util::filename_cat ($tmpdir, "gsdl", "mappings"), $gsdldir);
267
268 # untar Ping.tgz
269 my $wd = cwd;
270 chdir (&util::filename_cat($gsdldir, "perllib", "cpan"));
271 `tar xvzf Ping.tgz`;
272 unlink ("Ping.tgz");
273 chdir ($wd);
274
275 # make sure that modelcol collection contains all the right
276 # empty directories
277 my $modelindex = &util::filename_cat ($tmpdir, "gsdl", "collect", "modelcol", "index");
278 &util::mk_all_dir ($modelindex) unless -d $modelindex;
279 my $modelbuilding = &util::filename_cat ($tmpdir, "gsdl", "collect", "modelcol", "building");
280 &util::mk_all_dir ($modelbuilding) unless -d $modelbuilding;
281 my $modelarchives = &util::filename_cat ($tmpdir, "gsdl", "collect", "modelcol", "archives");
282 &util::mk_all_dir ($modelarchives) unless -d $modelarchives;
283 my $modelimport = &util::filename_cat ($tmpdir, "gsdl", "collect", "modelcol", "import");
284 &util::mk_all_dir ($modelimport) unless -d $modelimport;
285
286
287 # demo collection needs to be pre-built
288 my $collectdir = &util::filename_cat ($gsdldir, "collect");
289 &util::rm_r (&util::filename_cat($collectdir, "demo"));
290 if (!&get_built_collection ("demo", $collectdir)) {
291 die "Couldn't get built version of demo collection\n";
292 }
293}
294
295sub install_src {
296 my ($install_dir, $type) = @_;
297
298 my $srcdir = &util::filename_cat ($install_dir, "src");
299 my $srcwindir = &util::filename_cat ($srcdir, "Windows");
300 my $srcunixdir = &util::filename_cat ($srcdir, "Unix");
301 mkdir ($srcdir, 0777);
302 &util::cp_r (&util::filename_cat ($tmpdir, "gsdl", "lib"), $srcdir);
303 &util::cp_r (&util::filename_cat ($tmpdir, "gsdl", "packages"), $srcdir);
304 &util::cp_r (&util::filename_cat ($tmpdir, "gsdl", "src"), $srcdir);
305
306 if ($type ne "unix") {
307 mkdir ($srcwindir, 0777);
308 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "setup.bat"), $srcwindir);
309 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "win32.mak"), $srcwindir);
310 }
311
312 if ($type ne "windows") {
313 mkdir ($srcunixdir, 0777);
314 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "Makefile.in"), $srcunixdir);
315 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "acconfig.h"), $srcunixdir);
316 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "aclocal.m4"), $srcunixdir);
317 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "config.h.in"), $srcunixdir);
318 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "configtest.pl"), $srcunixdir);
319 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "configure"), $srcunixdir);
320 # make sure configure script is executable
321 my $configure_script = &util::filename_cat ($srcunixdir , "configure");
322 `chmod a+x $configure_script`;
323 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "configure.in"), $srcunixdir);
324 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "install-sh"), $srcunixdir);
325 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "setup.bash"), $srcunixdir);
326 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "setup.csh"), $srcunixdir);
327 }
328}
329
330# if $cd_rom is not true then we don't want to include the net16, net32,
331# Win32s or netscape directories in the bin/windows directory (note that
332# this currently means exportcol.pl will fail for all but cd-rom installed
333# distributions)
334sub install_windows_specific {
335 my ($install_dir, $cd_rom) = @_;
336
337 my $windir = &util::filename_cat ($install_dir, "Windows");
338 my $winbindir = &util::filename_cat ($windir, "bin");
339 mkdir ($windir, 0777);
340 mkdir ($winbindir, 0777);
341 &util::cp_r ($winbin, $winbindir);
342
343 if (!$cd_rom) {
344 &util::rm_r (&util::filename_cat ($winbindir, "windows", "net16"));
345 &util::rm_r (&util::filename_cat ($winbindir, "windows", "net32"));
346 &util::rm_r (&util::filename_cat ($winbindir, "windows", "Win32s"));
347 &util::rm_r (&util::filename_cat ($winbindir, "windows", "netscape"));
348 }
349
350 # make sure there aren't any CVS directories laying around
351 &remove_cvs_dirs ($windir);
352}
353
354sub install_unix_specific {
355 my ($install_dir) = @_;
356
357 my $unixdir = &util::filename_cat ($install_dir, "Unix");
358 my $unixbindir = &util::filename_cat ($unixdir, "bin");
359 mkdir ($unixdir, 0777);
360 mkdir ($unixbindir, 0777);
361 &util::cp (&util::filename_cat($tmpdir, "gsdl", "Install.sh"), $unixdir);
362
363 # make sure Install.sh is executable
364 my $install_sh = &util::filename_cat ($unixdir, "Install.sh");
365 `chmod a+x $install_sh`;
366 &util::cp_r ($linuxbin, $unixbindir);
367
368 # make sure there aren't any CVS directories laying around
369 &remove_cvs_dirs ($unixdir);
370}
371
372sub create_collection_distributions {
373
374 # work out which collections we want
375 my @cols = ();
376 if (scalar @includecols) {
377 @cols = @includecols;
378 } else {
379 my $collectdir = &util::filename_cat($ENV{'GSDLHOME'}, "collect");
380
381 opendir (COLLECTDIR, $collectdir) || die;
382 my @cdirs = readdir COLLECTDIR;
383 closedir COLLECTDIR;
384 my %ignore = ();
385 map { $ignore{$_} = ""; } @ignorecols;
386 foreach $d (@cdirs) {
387 if ((-d &util::filename_cat($collectdir, $d)) && ($d ne ".") && ($d ne "..") &&
388 ($d ne "modelcol") && ($d ne "CVS") && (!defined $ignore{$d})) {
389 push (@cols, $d);
390 }
391 }
392 }
393
394 return unless scalar @cols;
395
396 # create distributions
397 foreach $collection (@cols) {
398 if (&get_built_collection ($collection, $tmpdir)) {
399 &zip ("$collection-prebuilt", $collection, $tmpdir, 0);
400 &util::cp (&util::filename_cat($tmpdir, "$collection-prebuilt.tgz"), $output_dir);
401 &util::cp (&util::filename_cat($tmpdir, "$collection-prebuilt.zip"), $output_dir);
402 } else {
403 print STDERR "ERROR: Couldn't create pre-built $collection collection\n";
404 }
405 &util::rm_r (&util::filename_cat ($tmpdir, $collection))
406 if -d &util::filename_cat ($tmpdir, $collection);
407
408 if (&get_unbuilt_collection ($collection, $tmpdir)) {
409 &zip ($collection, $collection, $tmpdir, 0);
410 &util::cp (&util::filename_cat($tmpdir, "$collection.tgz"), $output_dir);
411 &util::cp (&util::filename_cat($tmpdir, "$collection.zip"), $output_dir);
412 } else {
413 print STDERR "ERROR: Couldn't create unbuilt $collection collection\n";
414 }
415 &util::rm_r (&util::filename_cat ($tmpdir, $collection))
416 if -d &util::filename_cat ($tmpdir, $collection);
417 }
418}
419
420# gets all the right bits of a built collection from
421# $GSDLHOME/collect and copies them to $collect_dir
422# returns 1 if successful, 0 if not
423sub get_built_collection {
424 my ($colname, $collect_dir) = @_;
425
426 my $from_dir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $colname);
427 if (!-d $from_dir) {
428 print STDERR "\nERROR: No collection at $from_dir\n";
429 return 0;
430 }
431
432 my $to_dir = &util::filename_cat ($collect_dir, $colname);
433 mkdir ($to_dir, 0777) unless -d $to_dir;
434
435 # get the built indexes
436 my $index_dir = &util::filename_cat ($from_dir, "index");
437 if (-d $index_dir) {
438 # if build.cfg exists we'll assume collection is built ok
439 if (-e &util::filename_cat ($index_dir, "build.cfg")) {
440 &util::cp_r ($index_dir, $to_dir);
441 } else {
442 print STDERR "\nERROR: no build.cfg at $index_dir (collection not built?)\n";
443 rmdir ($to_dir);
444 return 0;
445 }
446 } else {
447 print STDERR "\nERROR: collection at $from_dir appears unbuilt (no index directory)\n";
448 return 0;
449 }
450 &util::cp_r ($index_dir, $to_dir);
451
452 # get the collect.cfg file
453 mkdir (&util::filename_cat($to_dir, "etc"), 0777);
454 &util::cp (&util::filename_cat($from_dir, "etc", "collect.cfg"),
455 &util::filename_cat($to_dir, "etc"));
456
457 # get the images directory
458 my $from_images = &util::filename_cat ($from_dir, "images");
459 &util::cp_r ($from_images, $to_dir) if -d $from_images;
460
461 # make sure there aren't any CVS directories laying around
462 &remove_cvs_dirs ($to_dir);
463
464 &edit_collect_cfg (&util::filename_cat($to_dir, "etc", "collect.cfg"), $colname);
465 &create_version_file (&util::filename_cat($to_dir, "etc", "VERSION"), 0);
466
467 return 1;
468}
469
470# gets all the right bits of an unbuilt collection from
471# $GSDLHOME/collect and copies them to $collect_dir
472# returns 1 if successful, 0 if not
473sub get_unbuilt_collection {
474 my ($colname, $collect_dir) = @_;
475
476 my $from_dir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $colname);
477 if (!-d $from_dir) {
478 print STDERR "\nERROR: No collection at $from_dir\n";
479 return 0;
480 }
481
482 my $to_dir = &util::filename_cat ($collect_dir, $colname);
483 mkdir ($to_dir, 0777) unless -d $to_dir;
484
485 # get the unbuilt data (either import or archives)
486 my $have_import = 0;
487 my $import_dir = &util::filename_cat ($from_dir, "import");
488 if (-d $import_dir && opendir (IMPORTDIR, $import_dir)) {
489 my @importfiles = readdir IMPORTDIR;
490 closedir IMPORTDIR;
491 # if the import directory isn't empty we'll assume everything's ok
492 if (scalar @importfiles) {
493 $have_import = 1;
494 &util::cp_r ($import_dir, $to_dir);
495 mkdir (&util::filename_cat ($to_dir, "archives"), 0777);
496 }
497 }
498 if (!$have_import) {
499 # see if we've got archives then (check for archives.inf)
500 if (-e &util::filename_cat ($from_dir, "archives", "archives.inf")) {
501 &util::cp_r (&util::filename_cat($from_dir, "archives"), $to_dir);
502 } else {
503
504 print STDERR "$collection collection appears to have no valid\n";
505 print STDERR "import or archives data\n";
506 &util::rm_r ($to_dir);
507 return 0;
508 }
509 }
510
511 # get the etc directory
512 &util::cp_r (&util::filename_cat ($from_dir, "etc"), $to_dir);
513
514 # get the perllib directory
515 &util::cp_r (&util::filename_cat ($from_dir, "perllib"), $to_dir);
516
517 # get the images
518 &util::cp_r (&util::filename_cat ($from_dir, "images"), $to_dir);
519
520 mkdir (&util::filename_cat ($to_dir, "building"), 0777);
521 mkdir (&util::filename_cat ($to_dir, "index"), 0777);
522
523 # make sure there aren't any CVS directories laying around
524 &remove_cvs_dirs ($to_dir);
525
526 &edit_collect_cfg (&util::filename_cat($to_dir, "etc", "collect.cfg"), $colname);
527 my $preimported = 0;
528 $preimported = 1 unless $have_import;
529 &create_version_file (&util::filename_cat($to_dir, "etc", "VERSION"), $preimported);
530
531 return 1;
532}
533
534sub create_changelog {
535
536 my ($tag, $date, $file);
537
538 my $datefile = &util::filename_cat ($ENV{'GSDLHOME'}, "DistDates");
539 if ($changelogdate !~ /\w/) {
540 # get date from $GSDLHOME/DistDates (and update DistDates)
541 open (DATES, $datefile) || die "can't open $datefile\n";
542 my $line = "";
543 while (defined ($line = <DATES>)) {
544 if ($line =~ /\w/) {
545 ($tag, $date) = $line =~ /^(\S+)\t(.*)$/;
546 $changelogdate = $date unless ($tag eq $cvs_tag);
547 }
548 $file .= $line;
549 }
550 close DATES;
551 }
552
553 if ((!defined $tag) || ($tag ne $cvs_tag)) {
554 open (DATES, ">$datefile") || die;
555 print DATES $file if defined $file;
556 print DATES "$cvs_tag\t" . `date`;
557 close DATES;
558 }
559
560 print STDERR "Creating ChangeLog from $changelogdate to most recent\n";
561
562 chdir($ENV{'GSDLHOME'});
563 my $cmd = "cvs2cl.pl -P -F trunk -r -S -l \"-d'$changelogdate<tomorrow'\"";
564 system ($cmd);
565}
566
567# edits the gsdlsite.cfg file to set GSDLHOME
568# makes a copy of the initial version of gsdlsite.cfg in
569# /tmp (if it doesn't exist already).
570sub edit_gsdlsite {
571 my ($gsdlhome) = @_;
572
573 my $gsdlsite_file = &util::filename_cat ($tmpdir, "gsdl", "cgi-bin", "gsdlsite.cfg");
574 my $tmp_gsdlsite_file = &util::filename_cat ($tmpdir, "gsdlsite.cfg");
575
576 if (-e $tmp_gsdlsite_file) {
577 &util::cp ($tmp_gsdlsite_file, $gsdlsite_file);
578 } else {
579 &util::cp ($gsdlsite_file, $tmp_gsdlsite_file);
580 }
581
582 open (GSDLSITE, $gsdlsite_file) || die;
583 my $line = ""; my $file = ""; my $found = 0;
584 while (defined ($line = <GSDLSITE>)) {
585 if ($line =~ s/\*\*GSDLHOME\*\*/$gsdlhome/g) {
586 $found = 1;
587 }
588 $file .= $line;
589 }
590 close GSDLSITE;
591
592 if (!$found) {
593 die "ERROR: $gsdlsite_file contains no **GSDLHOME** string\n";
594 }
595
596 open (GSDLSITE, ">$gsdlsite_file") || die;
597 print GSDLSITE $file;
598 close GSDLSITE;
599}
600
601# currently just checks that iconcollection fields are correct and that
602# creator and maintainer fields are set to [email protected]
603sub edit_collect_cfg {
604 my ($collect_cfg_file, $collname) = @_;
605
606 open (FILE, $collect_cfg_file) || die "couldn't open $collect_cfg_file\n";
607 my $line = ""; my $file = "";
608 while (defined ($line = <FILE>)) {
609 $line =~ s/^((?:creator|maintainer)\s+\"?)\w+@\w+(\"?)/$1greenstone\@cs.waikato.ac.nz$2/ix;
610 $line =~ s/^(collectionmeta\s+\"?iconcollection(?:small)?\"?\s+\"?).*?($collname\/images\/)/$1_httpprefix_\/collect\/$2/ix;
611 $file .= $line;
612 }
613 close FILE;
614
615 open (FILE, ">$collect_cfg_file") || die;
616 print FILE $file;
617 close FILE;
618}
619
620# the "collection release" is the version of the content - it should only change if the
621# collections content is changed in some way
622# the "build version" is the build version of Greenstone when the collection distribution
623# was created
624
625# recent build version changes were:
626# 2.0 - 2.1: plugins were altered to take input_encoding (and other) options. GB plugins
627# were removed. numwords and numsections statistics were added.
628# All build version 2.0 collections other than those that suddenly required
629# the input_encoding option (i.e. Arabic and Chinese) may still be built and
630# viewed using build verion 2.1 software (numwords and numsections won't be
631# available though).
632
633sub create_version_file {
634 my ($version_file, $preimported) = @_;
635
636 open (FILE, ">$version_file") || die;
637
638 print FILE "collection release: 1.1\n";
639 print FILE "build version: 2.1\n";
640 print FILE "pre-imported\n" if $preimported;
641
642 close FILE;
643}
644
645# simply recurses directory structure beginning at $dir
646# and deletes any CVS administrative directories it comes
647# across
648sub remove_cvs_dirs {
649 my ($dir) = @_;
650
651 if (!-d $dir) {return;}
652
653 opendir (DIR, $dir) || die;
654 my @files = readdir DIR;
655 closedir DIR;
656
657 foreach $file (@files) {
658 next if $file =~ /^\.\.?$/;
659 my $fullpath = &util::filename_cat ($dir, $file);
660 if (-d $fullpath) {
661 if ($file eq "CVS") {
662 &util::rm_r ($fullpath);
663 } else {
664 &remove_cvs_dirs ($fullpath);
665 }
666 }
667 }
668}
669
670# mode is 0 to create .zip and .tgz, 1 to create .zip only, and 2 to create
671# .tgz only
672sub zip {
673 my ($zip_to, $zip_from, $dir, $mode) = @_;
674
675 chdir ($dir);
676
677 if ($mode != 2) {
678 my $to = $zip_to . ".zip";
679 unlink ($to) if -e $to;
680 print STDERR "zipping up $to\n";
681 `zip -r $to $zip_from`;
682 }
683 if ($mode != 1) {
684 my $to = $zip_to . ".tgz";
685 unlink ($to) if -e $to;
686 print STDERR "tarring and gzipping $to\n";
687 print STDERR "tar cvzf $to $zip_from\n";
688 system ("tar cvzf $to $zip_from");
689 }
690}
691
692sub edit_files {
693 # edit VERSION file
694 my $version_file = &util::filename_cat ($tmpdir, "gsdl", "etc" , "VERSION");
695 open (VERSION, $version_file) || die "failed to open $version_file\n";
696 my $found = 0; my $line = ""; my $file = "";
697 while (defined ($line = <VERSION>)) {
698 if ($line =~ s/(gsdl version: )x\.xx/$1$version_num/) {
699 $found ++;
700 } elsif ($line =~ s/(cvs tag: )gsdl-x_xx-distribution/$1$cvs_tag/) {
701 $found ++;
702 }
703 $file .= $line;
704 }
705 close VERSION;
706 if ($found != 2) {
707 die "error while editing $version_file\n";
708 }
709
710 open (VERSION, ">$version_file") || die;
711 print VERSION $file;
712 close VERSION;
713
714 # edit fnord.cpp
715 my $fnord_file = &util::filename_cat ($tmpdir, "gsdl", "src", "w32server", "fnord.cpp");
716 open (FNORD, $fnord_file) || die;
717 $found = 0; $line = ""; $file = "";
718 while (defined ($line = <FNORD>)) {
719 if ($line =~ s/(\#define VERSIONSTRING \"version )x\.xx(\")/$1$version_num$2/) {
720 $found ++;
721 }
722 $file .= $line;
723 }
724 close FNORD;
725 if (!$found) {
726 die "error while editing $fnord_file\n";
727 }
728
729 open (FNORD, ">$fnord_file") || die;
730 print FNORD $file;
731 close FNORD;
732}
733
734END {
735 # remove any temporary files we created
736 print STDERR "\ndeleting temporary files\n";
737 my $tmp_gsdlsite_file = &util::filename_cat ($tmpdir, "gsdlsite.cfg");
738 if (-e $tmp_gsdlsite_file) {
739 print STDERR "$tmp_gsdlsite_file\n";
740 unlink($tmp_gsdlsite_file);
741 }
742 my $tmp_gsdlhome = &util::filename_cat ($tmpdir, "gsdl");
743 if (-d $tmp_gsdlhome) {
744 print STDERR "$tmp_gsdlhome\n";
745 &util::rm_r ($tmp_gsdlhome);
746 }
747}
Note: See TracBrowser for help on using the repository browser.