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

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