source: trunk/gsdl/bin/script/exportcol.pl@ 12484

Last change on this file since 12484 was 11944, checked in by kjdon, 18 years ago

tidied up the code a bit, added a new option: noinstall, which makes a cd that runs from the cd and doesn't install anything

  • Property svn:keywords set to Author Date Id Revision
File size: 11.4 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# exportcol.pl --
6# A component of the Greenstone digital library software
7# from the New Zealand Digital Library Project at the
8# University of Waikato, New Zealand.
9#
10# Copyright (C) 1999 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27
28BEGIN {
29 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
30 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
31}
32
33use strict;
34no strict 'refs'; # allow filehandles to be variables and vice versa
35no strict 'subs'; # allow barewords (eg STDERR) as function arguments
36
37use util;
38use parse2;
39use printusage;
40
41my $arguments =
42 [
43 { 'name' => "cdname",
44 'desc' => "{exportcol.cdname}",
45 'type' => "string",
46 'deft' => "Greenstone Collections",
47 'reqd' => "no" },
48 { 'name' => "cddir",
49 'desc' => "{exportcol.cddir}",
50 'type' => "string",
51 'deft' => "exported_collections",
52 'reqd' => "no" },
53 { 'name' => "noinstall",
54 'desc' => "{exportcol.noinstall}",
55 'type' => "flag",
56 'reqd' => "no" },
57 { 'name' => "language",
58 'desc' => "{scripts.language}",
59 'type' => "string",
60 'reqd' => "no" },
61 { 'name' => "out",
62 'desc' => "{exportcol.out}",
63 'type' => "string",
64 'deft' => "STDERR",
65 'reqd' => "no" },
66 { 'name' => "xml",
67 'desc' => "{scripts.xml}",
68 'type' => "flag",
69 'reqd' => "no",
70 'hiddengli' => "yes" },
71 { 'name' => "gli",
72 'desc' => "",
73 'type' => "flag",
74 'reqd' => "no",
75 'hiddengli' => "yes" },
76
77 ];
78
79my $options = { 'name' => "exportcol.pl",
80 'desc' => "{exportcol.desc}",
81 'args' => $arguments };
82
83sub gsprintf
84{
85 return &gsprintf::gsprintf(@_);
86}
87
88
89&main();
90
91sub main {
92 my ($language, $out, $cdname, $cddir);
93
94 my $noinstall = 0;
95 my $xml = 0;
96 my $gli = 0;
97
98 my $hashParsingResult = {};
99 my $blnParseFailed = "false";
100 # parse options
101 my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
102 # don't care how many args are left - can have multiple collection names
103 foreach my $strVariable (keys %$hashParsingResult)
104 {
105 eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
106 }
107
108 # If $language has been specified, load the appropriate resource bundle
109 # (Otherwise, the default resource bundle will be loaded automatically)
110 if ($language && $language =~ /\S/) {
111 &gsprintf::load_language_specific_resource_bundle($language);
112 }
113
114 if ($xml) {
115 &PrintUsage::print_xml_usage($options);
116 print "\n";
117 return;
118 }
119
120 if ($gli) { # the gli wants strings to be in UTF-8
121 &gsprintf::output_strings_in_UTF8;
122 }
123
124 my @coll_list = @ARGV;
125
126 if (not @coll_list) { # empty list
127 &PrintUsage::print_txt_usage($options, "{exportcol.params}");
128 exit(1);
129 }
130
131 my $close_out = 0;
132 if ($out !~ /^(STDERR|STDOUT)$/i) {
133 open (OUT, ">$out") ||
134 (&gsprintf(STDERR, "{common.cannot_open_output_file}\n", $out) && die);
135 $out = 'main::OUT';
136 $close_out = 1;
137 }
138
139 # first we do a quick check to see if the export coll function has been
140 # installed
141 my $gssetupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "gssetup.exe");
142 if (!-e $gssetupexe) {
143 &gsprintf($out, "{exportcol.fail} {exportcol.export_coll_not_installed}\n");
144 die "\n";
145 }
146
147 # check each collection
148 my @valid_coll_list = ();
149 foreach my $c (@coll_list) {
150 my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
151 if (! -d $colldir) {
152 &gsprintf($out, "{exportcol.coll_not_found}\n", $c, $colldir);
153 next;
154 }
155 my $colindexdir = &util::filename_cat ($colldir, "index");
156 my $coletcdir = &util::filename_cat ($colldir, "etc");
157 if ((!-d $colindexdir) || (!-d $coletcdir)) {
158 &gsprintf($out, "{exportcol.coll_dirs_not_found}\n", $c);
159 &gsprintf($out, " $colindexdir\n");
160 &gsprintf($out, " $coletcdir\n");
161 next;
162 }
163 # the collection seems ok, we add it to the valid coll list
164 push @valid_coll_list, $c;
165 }
166
167 if (not @valid_coll_list) {
168 # no valid colls left
169 &gsprintf($out, "{exportcol.fail} {exportcol.no_valid_colls}\n");
170 die "\n";
171 }
172
173 # create exported directory
174 my $topdir = &util::filename_cat ($ENV{'GSDLHOME'}, "tmp", $cddir);
175 &util::mk_all_dir ($topdir);
176 if (!-d $topdir) {
177 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_dir}\n", $topdir);
178 die "\n";
179 }
180
181 # we create either a self installing cd, or one that runs off the cd (and
182 # doesn't install anything
183
184 # create all the directories - we assume that if we created the top dir ok,
185 # then all the other mkdirs will go ok
186 my $gsdldir;
187 if ($noinstall) {
188 $gsdldir = $topdir;
189 }
190 else {
191 $gsdldir = &util::filename_cat ($topdir, "gsdl");
192 &util::mk_all_dir ($gsdldir);
193 }
194
195 my $collectdir = &util::filename_cat ($gsdldir, "collect");
196 &util::mk_all_dir ($collectdir);
197 my $etcdir = &util::filename_cat ($gsdldir, "etc");
198 &util::mk_all_dir ($etcdir);
199 my $binjavadir = &util::filename_cat ($gsdldir, "bin", "java");
200 &util::mk_all_dir ($binjavadir);
201
202 #create the config files
203 if (!$noinstall) {
204 # create the install.cfg file
205 my $installcfg = &util::filename_cat ($topdir, "install.cfg");
206 if (!open (INSTALLCFG, ">$installcfg")) {
207 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $installcfg);
208 die "\n";
209 }
210 print INSTALLCFG "CompanyName:New Zealand Digital Library\n";
211 print INSTALLCFG "CollectionName:$cdname\n";
212 print INSTALLCFG "CollectionDirName:$cdname\n";
213 print INSTALLCFG "CollectionVersion:1.0\n";
214 print INSTALLCFG "CollectionVolume:1\n";
215 print INSTALLCFG "ProgramGroupName:Greenstone\n";
216 close INSTALLCFG;
217
218 # create the manifest.cfg file
219 my $manifestcfg = &util::filename_cat ($topdir, "manifest.cfg");
220 if (!open (MANIFESTCFG, ">$manifestcfg")) {
221 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $manifestcfg);
222 die "\n";
223 }
224 print MANIFESTCFG "all:\n";
225 print MANIFESTCFG " {library} {collection}\n\n";
226 print MANIFESTCFG "library:\n";
227 print MANIFESTCFG " server.exe\n\n";
228 print MANIFESTCFG "database:\n";
229 print MANIFESTCFG ' etc ';
230 foreach my $c (@valid_coll_list) {
231 print MANIFESTCFG "collect\\$c\\index\\text\\$c.ldb ";
232 }
233 print MANIFESTCFG "\n\n";
234 print MANIFESTCFG "collection:\n";
235 print MANIFESTCFG " collect etc images macros mappings bin\n";
236 close MANIFESTCFG;
237
238 }
239
240 #create the autorun.inf file
241 my $autoruninf = &util::filename_cat ($topdir, "Autorun.inf");
242 if (!open (AUTORUNINF, ">$autoruninf")) {
243 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $autoruninf);
244 die "\n";
245 }
246
247 print AUTORUNINF "[autorun]\n";
248 if ($noinstall) {
249 print AUTORUNINF "OPEN=server.exe\n";
250 } else {
251 print AUTORUNINF "OPEN=Setup.exe\n";
252 }
253 close AUTORUNINF;
254
255 # copy the necessary stuff from GSDLHOME
256 my $imagesdir = &util::filename_cat ($ENV{'GSDLHOME'}, "images");
257 my $macrosdir = &util::filename_cat ($ENV{'GSDLHOME'}, "macros");
258 my $mappingsdir = &util::filename_cat ($ENV{'GSDLHOME'}, "mappings");
259 my $maincfg = &util::filename_cat ($ENV{'GSDLHOME'}, "etc", "main.cfg");
260 my $serverexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "server.exe");
261 my $setupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "Setup.exe");
262 my $phindjar = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "java", "Phind.jar");
263 my $gsdlcollageappletjar = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "java", "GsdlCollageApplet.jar");
264
265 if ((!-d $imagesdir) || (!-d $macrosdir) || (!-d $mappingsdir) || (!-e $maincfg) ||
266 (!-e $serverexe) || (!-e $gssetupexe) || (!-e $setupexe) || (!-e $phindjar) ||
267 (!-e $gsdlcollageappletjar)) {
268 &gsprintf($out, "{exportcol.fail} {exportcol.non_exist_files}\n");
269 &gsprintf($out, " $imagesdir\n");
270 &gsprintf($out, " $macrosdir\n");
271 &gsprintf($out, " $mappingsdir\n");
272 &gsprintf($out, " $maincfg\n");
273 &gsprintf($out, " $serverexe\n");
274 &gsprintf($out, " $gssetupexe\n");
275 &gsprintf($out, " $setupexe\n");
276 &gsprintf($out, " $phindjar\n");
277 &gsprintf($out, " $gsdlcollageappletjar\n");
278 die "\n";
279 }
280
281 &util::cp_r ($imagesdir, $gsdldir);
282 &util::cp_r ($macrosdir, $gsdldir);
283 &util::cp_r ($mappingsdir, $gsdldir);
284 &util::cp ($maincfg, $etcdir);
285 &util::cp ($serverexe, $gsdldir);
286 &util::cp ($phindjar, $binjavadir);
287 &util::cp ($gsdlcollageappletjar, $binjavadir);
288
289 if (!$noinstall) {
290 &util::cp ($gssetupexe, $topdir);
291 &util::cp ($setupexe, $topdir);
292 }
293
294 # now change the home.dm macro file to a simple version
295 my $newmacrodir = &util::filename_cat ($gsdldir, "macros");
296 my $exporthome = &util::filename_cat ($newmacrodir, "exported_home.dm");
297 my $oldhome = &util::filename_cat ($newmacrodir, "home.dm");
298 if (-e $exporthome) {
299 &util::rm($oldhome);
300 &util::mv($exporthome, $oldhome);
301 }
302
303 # copy the collections over
304 foreach my $c (@valid_coll_list) {
305 #old directories
306 my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
307 my $colindexdir = &util::filename_cat ($colldir, "index");
308 my $coletcdir = &util::filename_cat ($colldir, "etc");
309 my $colimagesdir = &util::filename_cat ($colldir, "images");
310 my $colmacrosdir = &util::filename_cat ($colldir, "macros");
311 # new coll directory
312 my $newcoldir = &util::filename_cat ($collectdir, $c);
313
314 &util::mk_all_dir ($newcoldir);
315 &util::cp_r ($colindexdir, $newcoldir);
316 &util::cp_r ($coletcdir, $newcoldir);
317 &util::cp_r ($colimagesdir, $newcoldir) if (-e $colimagesdir);
318 &util::cp_r ($colmacrosdir, $newcoldir) if (-e $colmacrosdir);
319
320 # now we need to check the collect.cfg file to make sure it's public
321 my $collectcfg = &util::filename_cat ($newcoldir, "etc", "collect.cfg");
322 open INFILE, "<$collectcfg";
323 open OUTFILE, ">$collectcfg.tmp";
324 my $line;
325 while ($line = <INFILE>) {
326 if ($line =~ /^\s*public\s+false/) {
327 print OUTFILE "public\ttrue\n";
328 last; # stop matching once we have found the line
329 } else {
330 print OUTFILE "$line";
331 }
332 }
333 # continue with no checking
334 while ($line = <INFILE>) {
335 print OUTFILE "$line";
336 }
337 close INFILE;
338 close OUTFILE;
339 &util::mv("$collectcfg.tmp", $collectcfg);
340 }
341 &gsprintf($out, "{exportcol.success}");
342
343 my $successcolls = "";
344 my $first = 1;
345 foreach my $c (@valid_coll_list) {
346 if ($first) {
347 $first=0;
348 } else {
349 $successcolls .=", ";
350 }
351 $successcolls .= "$c";
352 }
353
354 my $gsdl_home = $ENV{'GSDLHOME'};
355 my $portable_topdir = $topdir;
356 # Disabled this because it isn't currently useful (the GLI applet doesn't do exporting)
357 # It doesn't work on Windows, either
358 # $portable_topdir =~ s/$gsdl_home/\$GSDLHOME/g;
359
360 &gsprintf($out, "{exportcol.output_dir}\n", $successcolls, $portable_topdir);
361 &gsprintf($out, "exportcol.pl succeeded:{exportcol.instructions}\n");
362 close OUT if $close_out;
363}
364
Note: See TracBrowser for help on using the repository browser.