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