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

Last change on this file since 2438 was 2438, 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.6 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 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "Install.txt"), $srcdir);
306
307 if ($type ne "unix") {
308 mkdir ($srcwindir, 0777);
309 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "setup.bat"), $srcwindir);
310 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "win32.mak"), $srcwindir);
311 }
312
313 if ($type ne "windows") {
314 mkdir ($srcunixdir, 0777);
315 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "Makefile.in"), $srcunixdir);
316 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "acconfig.h"), $srcunixdir);
317 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "aclocal.m4"), $srcunixdir);
318 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "config.h.in"), $srcunixdir);
319 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "configtest.pl"), $srcunixdir);
320 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "configure"), $srcunixdir);
321 # make sure configure script is executable
322 my $configure_script = &util::filename_cat ($srcunixdir , "configure");
323 `chmod a+x $configure_script`;
324 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "configure.in"), $srcunixdir);
325 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "install-sh"), $srcunixdir);
326 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "setup.bash"), $srcunixdir);
327 &util::cp (&util::filename_cat ($tmpdir, "gsdl", "setup.csh"), $srcunixdir);
328 }
329}
330
331# if $cd_rom is not true then we don't want to include the net16, net32,
332# Win32s or netscape directories or gssetup.exe and setup.exe executables
333# in the bin/windows directory (note that this currently means exportcol.pl
334# will fail for all but cd-rom installed distributions)
335sub install_windows_specific {
336 my ($install_dir, $cd_rom) = @_;
337
338 my $windir = &util::filename_cat ($install_dir, "Windows");
339 my $winbindir = &util::filename_cat ($windir, "bin");
340 mkdir ($windir, 0777);
341 mkdir ($winbindir, 0777);
342 &util::cp_r ($winbin, $winbindir);
343
344 if (!$cd_rom) {
345 &util::rm_r (&util::filename_cat ($winbindir, "windows", "net16"));
346 &util::rm_r (&util::filename_cat ($winbindir, "windows", "net32"));
347 &util::rm_r (&util::filename_cat ($winbindir, "windows", "Win32s"));
348 &util::rm_r (&util::filename_cat ($winbindir, "windows", "netscape"));
349 &util::rm (&util::filename_cat ($winbindir, "windows", "gssetup.exe"));
350 &util::rm (&util::filename_cat ($winbindir, "windows", "Setup.exe"));
351 }
352
353 # make sure there aren't any CVS directories laying around
354 &remove_cvs_dirs ($windir);
355}
356
357sub install_unix_specific {
358 my ($install_dir) = @_;
359
360 my $unixdir = &util::filename_cat ($install_dir, "Unix");
361 my $unixbindir = &util::filename_cat ($unixdir, "bin");
362 mkdir ($unixdir, 0777);
363 mkdir ($unixbindir, 0777);
364 &util::cp (&util::filename_cat($tmpdir, "gsdl", "Install.sh"), $unixdir);
365
366 # make sure Install.sh is executable
367 my $install_sh = &util::filename_cat ($unixdir, "Install.sh");
368 `chmod a+x $install_sh`;
369 &util::cp_r ($linuxbin, $unixbindir);
370
371 # make sure there aren't any CVS directories laying around
372 &remove_cvs_dirs ($unixdir);
373}
374
375sub create_collection_distributions {
376
377 # work out which collections we want
378 my @cols = ();
379 if (scalar @includecols) {
380 @cols = @includecols;
381 } else {
382 my $collectdir = &util::filename_cat($ENV{'GSDLHOME'}, "collect");
383
384 opendir (COLLECTDIR, $collectdir) || die;
385 my @cdirs = readdir COLLECTDIR;
386 closedir COLLECTDIR;
387 my %ignore = ();
388 map { $ignore{$_} = ""; } @ignorecols;
389 foreach $d (@cdirs) {
390 if ((-d &util::filename_cat($collectdir, $d)) && ($d ne ".") && ($d ne "..") &&
391 ($d ne "modelcol") && ($d ne "CVS") && (!defined $ignore{$d})) {
392 push (@cols, $d);
393 }
394 }
395 }
396
397 return unless scalar @cols;
398
399 # create distributions
400 foreach $collection (@cols) {
401 if (&get_built_collection ($collection, $tmpdir)) {
402 &zip ("$collection-prebuilt", $collection, $tmpdir, 0);
403 &util::cp (&util::filename_cat($tmpdir, "$collection-prebuilt.tgz"), $output_dir);
404 &util::cp (&util::filename_cat($tmpdir, "$collection-prebuilt.zip"), $output_dir);
405 } else {
406 print STDERR "ERROR: Couldn't create pre-built $collection collection\n";
407 }
408 &util::rm_r (&util::filename_cat ($tmpdir, $collection))
409 if -d &util::filename_cat ($tmpdir, $collection);
410
411 if (&get_unbuilt_collection ($collection, $tmpdir)) {
412 &zip ($collection, $collection, $tmpdir, 0);
413 &util::cp (&util::filename_cat($tmpdir, "$collection.tgz"), $output_dir);
414 &util::cp (&util::filename_cat($tmpdir, "$collection.zip"), $output_dir);
415 } else {
416 print STDERR "ERROR: Couldn't create unbuilt $collection collection\n";
417 }
418 &util::rm_r (&util::filename_cat ($tmpdir, $collection))
419 if -d &util::filename_cat ($tmpdir, $collection);
420 }
421}
422
423# gets all the right bits of a built collection from
424# $GSDLHOME/collect and copies them to $collect_dir
425# returns 1 if successful, 0 if not
426sub get_built_collection {
427 my ($colname, $collect_dir) = @_;
428
429 my $from_dir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $colname);
430 if (!-d $from_dir) {
431 print STDERR "\nERROR: No collection at $from_dir\n";
432 return 0;
433 }
434
435 my $to_dir = &util::filename_cat ($collect_dir, $colname);
436 mkdir ($to_dir, 0777) unless -d $to_dir;
437
438 # get the built indexes
439 my $index_dir = &util::filename_cat ($from_dir, "index");
440 if (-d $index_dir) {
441 # if build.cfg exists we'll assume collection is built ok
442 if (-e &util::filename_cat ($index_dir, "build.cfg")) {
443 &util::cp_r ($index_dir, $to_dir);
444 } else {
445 print STDERR "\nERROR: no build.cfg at $index_dir (collection not built?)\n";
446 rmdir ($to_dir);
447 return 0;
448 }
449 } else {
450 print STDERR "\nERROR: collection at $from_dir appears unbuilt (no index directory)\n";
451 return 0;
452 }
453 &util::cp_r ($index_dir, $to_dir);
454
455 # get the collect.cfg file
456 mkdir (&util::filename_cat($to_dir, "etc"), 0777);
457 &util::cp (&util::filename_cat($from_dir, "etc", "collect.cfg"),
458 &util::filename_cat($to_dir, "etc"));
459
460 # get the images directory
461 my $from_images = &util::filename_cat ($from_dir, "images");
462 &util::cp_r ($from_images, $to_dir) if -d $from_images;
463
464 # make sure there aren't any CVS directories laying around
465 &remove_cvs_dirs ($to_dir);
466
467 &edit_collect_cfg (&util::filename_cat($to_dir, "etc", "collect.cfg"), $colname);
468 &create_version_file (&util::filename_cat($to_dir, "etc", "VERSION"), 0);
469
470 return 1;
471}
472
473# gets all the right bits of an unbuilt collection from
474# $GSDLHOME/collect and copies them to $collect_dir
475# returns 1 if successful, 0 if not
476sub get_unbuilt_collection {
477 my ($colname, $collect_dir) = @_;
478
479 my $from_dir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $colname);
480 if (!-d $from_dir) {
481 print STDERR "\nERROR: No collection at $from_dir\n";
482 return 0;
483 }
484
485 my $to_dir = &util::filename_cat ($collect_dir, $colname);
486 mkdir ($to_dir, 0777) unless -d $to_dir;
487
488 # get the unbuilt data (either import or archives)
489 my $have_import = 0;
490 my $import_dir = &util::filename_cat ($from_dir, "import");
491 if (-d $import_dir && opendir (IMPORTDIR, $import_dir)) {
492 my @importfiles = readdir IMPORTDIR;
493 closedir IMPORTDIR;
494 # if the import directory isn't empty we'll assume everything's ok
495 if (scalar @importfiles) {
496 $have_import = 1;
497 &util::cp_r ($import_dir, $to_dir);
498 mkdir (&util::filename_cat ($to_dir, "archives"), 0777);
499 }
500 }
501 if (!$have_import) {
502 # see if we've got archives then (check for archives.inf)
503 if (-e &util::filename_cat ($from_dir, "archives", "archives.inf")) {
504 &util::cp_r (&util::filename_cat($from_dir, "archives"), $to_dir);
505 } else {
506
507 print STDERR "$collection collection appears to have no valid\n";
508 print STDERR "import or archives data\n";
509 &util::rm_r ($to_dir);
510 return 0;
511 }
512 }
513
514 # get the etc directory
515 &util::cp_r (&util::filename_cat ($from_dir, "etc"), $to_dir);
516
517 # get the perllib directory
518 &util::cp_r (&util::filename_cat ($from_dir, "perllib"), $to_dir);
519
520 # get the images
521 &util::cp_r (&util::filename_cat ($from_dir, "images"), $to_dir);
522
523 mkdir (&util::filename_cat ($to_dir, "building"), 0777);
524 mkdir (&util::filename_cat ($to_dir, "index"), 0777);
525
526 # make sure there aren't any CVS directories laying around
527 &remove_cvs_dirs ($to_dir);
528
529 &edit_collect_cfg (&util::filename_cat($to_dir, "etc", "collect.cfg"), $colname);
530 my $preimported = 0;
531 $preimported = 1 unless $have_import;
532 &create_version_file (&util::filename_cat($to_dir, "etc", "VERSION"), $preimported);
533
534 return 1;
535}
536
537sub create_changelog {
538
539 my ($tag, $date, $file);
540
541 my $datefile = &util::filename_cat ($ENV{'GSDLHOME'}, "DistDates");
542 if ($changelogdate !~ /\w/) {
543 # get date from $GSDLHOME/DistDates (and update DistDates)
544 open (DATES, $datefile) || die "can't open $datefile\n";
545 my $line = "";
546 while (defined ($line = <DATES>)) {
547 if ($line =~ /\w/) {
548 ($tag, $date) = $line =~ /^(\S+)\t(.*)$/;
549 $changelogdate = $date unless ($tag eq $cvs_tag);
550 }
551 $file .= $line;
552 }
553 close DATES;
554 }
555
556 if ((!defined $tag) || ($tag ne $cvs_tag)) {
557 open (DATES, ">$datefile") || die;
558 print DATES $file if defined $file;
559 print DATES "$cvs_tag\t" . `date`;
560 close DATES;
561 }
562
563 print STDERR "Creating ChangeLog from $changelogdate to most recent\n";
564
565 chdir($ENV{'GSDLHOME'});
566 my $cmd = "cvs2cl.pl -P -F trunk -r -S -l \"-d'$changelogdate<tomorrow'\"";
567 system ($cmd);
568}
569
570# edits the gsdlsite.cfg file to set GSDLHOME
571# makes a copy of the initial version of gsdlsite.cfg in
572# /tmp (if it doesn't exist already).
573sub edit_gsdlsite {
574 my ($gsdlhome) = @_;
575
576 my $gsdlsite_file = &util::filename_cat ($tmpdir, "gsdl", "cgi-bin", "gsdlsite.cfg");
577 my $tmp_gsdlsite_file = &util::filename_cat ($tmpdir, "gsdlsite.cfg");
578
579 if (-e $tmp_gsdlsite_file) {
580 &util::cp ($tmp_gsdlsite_file, $gsdlsite_file);
581 } else {
582 &util::cp ($gsdlsite_file, $tmp_gsdlsite_file);
583 }
584
585 open (GSDLSITE, $gsdlsite_file) || die;
586 my $line = ""; my $file = ""; my $found = 0;
587 while (defined ($line = <GSDLSITE>)) {
588 if ($line =~ s/\*\*GSDLHOME\*\*/$gsdlhome/g) {
589 $found = 1;
590 }
591 $file .= $line;
592 }
593 close GSDLSITE;
594
595 if (!$found) {
596 die "ERROR: $gsdlsite_file contains no **GSDLHOME** string\n";
597 }
598
599 open (GSDLSITE, ">$gsdlsite_file") || die;
600 print GSDLSITE $file;
601 close GSDLSITE;
602}
603
604# currently just checks that iconcollection fields are correct and that
605# creator and maintainer fields are set to [email protected]
606sub edit_collect_cfg {
607 my ($collect_cfg_file, $collname) = @_;
608
609 open (FILE, $collect_cfg_file) || die "couldn't open $collect_cfg_file\n";
610 my $line = ""; my $file = "";
611 while (defined ($line = <FILE>)) {
612 $line =~ s/^((?:creator|maintainer)\s+\"?)\w+@\w+(\"?)/$1greenstone\@cs.waikato.ac.nz$2/ix;
613 $line =~ s/^(collectionmeta\s+\"?iconcollection(?:small)?\"?\s+\"?).*?($collname\/images\/)/$1_httpprefix_\/collect\/$2/ix;
614 $file .= $line;
615 }
616 close FILE;
617
618 open (FILE, ">$collect_cfg_file") || die;
619 print FILE $file;
620 close FILE;
621}
622
623# the "collection release" is the version of the content - it should only change if the
624# collections content is changed in some way
625# the "build version" is the build version of Greenstone when the collection distribution
626# was created
627
628# recent build version changes were:
629# 2.0 - 2.1: plugins were altered to take input_encoding (and other) options. GB plugins
630# were removed. numwords and numsections statistics were added.
631# All build version 2.0 collections other than those that suddenly required
632# the input_encoding option (i.e. Arabic and Chinese) may still be built and
633# viewed using build verion 2.1 software (numwords and numsections won't be
634# available though).
635
636sub create_version_file {
637 my ($version_file, $preimported) = @_;
638
639 open (FILE, ">$version_file") || die;
640
641 print FILE "collection release: 1.1\n";
642 print FILE "build version: 2.1\n";
643 print FILE "pre-imported\n" if $preimported;
644
645 close FILE;
646}
647
648# simply recurses directory structure beginning at $dir
649# and deletes any CVS administrative directories it comes
650# across
651sub remove_cvs_dirs {
652 my ($dir) = @_;
653
654 if (!-d $dir) {return;}
655
656 opendir (DIR, $dir) || die;
657 my @files = readdir DIR;
658 closedir DIR;
659
660 foreach $file (@files) {
661 next if $file =~ /^\.\.?$/;
662 my $fullpath = &util::filename_cat ($dir, $file);
663 if (-d $fullpath) {
664 if ($file eq "CVS") {
665 &util::rm_r ($fullpath);
666 } else {
667 &remove_cvs_dirs ($fullpath);
668 }
669 }
670 }
671}
672
673# mode is 0 to create .zip and .tgz, 1 to create .zip only, and 2 to create
674# .tgz only
675sub zip {
676 my ($zip_to, $zip_from, $dir, $mode) = @_;
677
678 chdir ($dir);
679
680 if ($mode != 2) {
681 my $to = $zip_to . ".zip";
682 unlink ($to) if -e $to;
683 print STDERR "zipping up $to\n";
684 `zip -r $to $zip_from`;
685 }
686 if ($mode != 1) {
687 my $to = $zip_to . ".tgz";
688 unlink ($to) if -e $to;
689 print STDERR "tarring and gzipping $to\n";
690 print STDERR "tar cvzf $to $zip_from\n";
691 system ("tar cvzf $to $zip_from");
692 }
693}
694
695sub edit_files {
696 # edit VERSION file
697 my $version_file = &util::filename_cat ($tmpdir, "gsdl", "etc" , "VERSION");
698 open (VERSION, $version_file) || die "failed to open $version_file\n";
699 my $found = 0; my $line = ""; my $file = "";
700 while (defined ($line = <VERSION>)) {
701 if ($line =~ s/(gsdl version: )x\.xx/$1$version_num/) {
702 $found ++;
703 } elsif ($line =~ s/(cvs tag: )gsdl-x_xx-distribution/$1$cvs_tag/) {
704 $found ++;
705 }
706 $file .= $line;
707 }
708 close VERSION;
709 if ($found != 2) {
710 die "error while editing $version_file\n";
711 }
712
713 open (VERSION, ">$version_file") || die;
714 print VERSION $file;
715 close VERSION;
716
717 # edit fnord.cpp
718 my $fnord_file = &util::filename_cat ($tmpdir, "gsdl", "src", "w32server", "fnord.cpp");
719 open (FNORD, $fnord_file) || die;
720 $found = 0; $line = ""; $file = "";
721 while (defined ($line = <FNORD>)) {
722 if ($line =~ s/(\#define VERSIONSTRING \"version )x\.xx(\")/$1$version_num$2/) {
723 $found ++;
724 }
725 $file .= $line;
726 }
727 close FNORD;
728 if (!$found) {
729 die "error while editing $fnord_file\n";
730 }
731
732 open (FNORD, ">$fnord_file") || die;
733 print FNORD $file;
734 close FNORD;
735}
736
737END {
738 # remove any temporary files we created
739 print STDERR "\ndeleting temporary files\n";
740 my $tmp_gsdlsite_file = &util::filename_cat ($tmpdir, "gsdlsite.cfg");
741 if (-e $tmp_gsdlsite_file) {
742 print STDERR "$tmp_gsdlsite_file\n";
743 unlink($tmp_gsdlsite_file);
744 }
745 my $tmp_gsdlhome = &util::filename_cat ($tmpdir, "gsdl");
746 if (-d $tmp_gsdlhome) {
747 print STDERR "$tmp_gsdlhome\n";
748 &util::rm_r ($tmp_gsdlhome);
749 }
750}
Note: See TracBrowser for help on using the repository browser.