source: tags/gsdl-2_37-distribution/gsdl/bin/script/create_distributions.pl@ 2843

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