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

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