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

Last change on this file since 6788 was 6788, checked in by kjdon, 20 years ago

added a bit more output for a successful export

  • Property svn:keywords set to Author Date Id Revision
File size: 11.8 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 util;
34use parsargv;
35use printusage;
36
37my $arguments =
38 [ { 'name' => "out",
39 'desc' => "{exportcol.out}",
40 'type' => "string",
41 'deft' => "STDERR",
42 'reqd' => "no" },
43 { 'name' => "cdname",
44 'desc' => "{exportcol.cdname}",
45 'type' => "string",
46 'deft' => "Greenstone Collections",
47 'reqd' => "no" }, ];
48
49my $options = { 'name' => "exportcol.pl",
50 'desc' => "{exportcol.desc}",
51 'args' => $arguments };
52
53sub print_xml_usage
54{
55 local $language = shift(@_);
56
57 &PrintUsage::print_xml_header();
58
59 print STDERR "<Info>\n";
60 print STDERR " <Name>$options->{'name'}</Name>\n";
61 print STDERR " <Desc>" . &lookup_string($options->{'desc'}) . "</Desc>\n";
62 print STDERR " <Arguments>\n";
63 if (defined($options->{'args'})) {
64 &PrintUsage::print_options_xml($language, $options->{'args'});
65 }
66 print STDERR " </Arguments>\n";
67 print STDERR "</Info>\n";
68}
69
70sub print_txt_usage
71{
72 local $language = shift(@_);
73
74 local $programname = $options->{'name'};
75 local $programargs = $options->{'args'};
76
77 # Find the length of the longest option string
78 local $descoffset = 0;
79 if (defined($programargs)) {
80 $descoffset = &PrintUsage::find_longest_option_string($programargs);
81 }
82
83 # Produce the usage information using the data structure above
84 print STDERR " " . &lookup_string("{common.usage}") . ": $programname";
85 print STDERR " " . &lookup_string("{exportcol.params}") . "\n\n";
86
87 # Display the program options, if there are some
88 if (defined($programargs)) {
89 # Calculate the column offset of the option descriptions
90 local $optiondescoffset = $descoffset + 2; # 2 spaces between options & descriptions
91
92 print STDERR " " . &lookup_string("{common.options}") . ":\n";
93
94 # Display the program options
95 &PrintUsage::print_options_txt($language, $programargs, $optiondescoffset);
96 }
97}
98
99
100sub lookup_string
101{
102 return &gsprintf::lookup_string($language, shift(@_));
103}
104
105sub gsprintf
106{
107 return &gsprintf::gsprintf(@_);
108}
109
110#sub print_usage {
111# print STDERR "\n";
112# print STDERR "exportcol.pl: Exports collection for writing to CD-ROM.\n\n";
113# print STDERR " usage: $0 [options] collection-name\n\n";
114# print STDERR " -out Filename or handle to print debug info to.\n";
115# print STDERR " The default is STDERR\n";
116# print STDERR " -cdname The name of the cd - this is what will appear in the start menu once the cd is installed.\n";
117# print STDERR " The default is 'Greenstone Collections'.\n\n";
118#}
119
120&main();
121
122sub main {
123 my ($out, $cdname);
124
125 my $xml = 0;
126
127 if (!parsargv::parse(\@ARGV,
128 'out/.*/STDERR', \$out,
129 'cdname/.*/', \$cdname,
130 q^xml^, \$xml)) {
131
132 &print_txt_usage();
133 die "\n";
134 }
135
136 if ($xml) {
137 &print_xml_usage($language);
138 die "\n";
139 }
140
141 my $dirname="";
142 if ($cdname eq "") {
143 $cdname = "Greenstone Collections";
144 $dirname = "exported_collections";
145 } else {
146 $dirname = $cdname;
147 $dirname =~ s/\s//g;
148 $dirname = "exported_".$dirname;
149 }
150
151 my @coll_list = @ARGV;
152
153 if (not @coll_list) { # empty list
154 &print_txt_usage();
155 exit(1);
156 }
157
158 my $close_out = 0;
159 if ($out !~ /^(STDERR|STDOUT)$/i) {
160 open (OUT, ">$out") ||
161 die &lookup_string("{common.cannot_open_output_file}") . " $out\n";
162 $out = OUT;
163 $close_out = 1;
164 }
165
166 # check each collection
167 my @valid_coll_list = ();
168 foreach $c (@coll_list) {
169 my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
170 if (! -d $colldir) {
171 &gsprintf($out, "{exportcol.coll_not_found}\n", $c, $colldir);
172 next;
173 }
174 my $colindexdir = &util::filename_cat ($colldir, "index");
175 my $coletcdir = &util::filename_cat ($colldir, "etc");
176 if ((!-d $colindexdir) || (!-d $coletcdir)) {
177 &gsprintf($out, "{exportcol.coll_dirs_not_found}\n", $c);
178 print $out " $colindexdir\n";
179 print $out " $coletcdir\n";
180 next;
181 }
182 # the collection seems ok, we add it to the valid coll list
183 push @valid_coll_list, $c;
184
185 }
186
187 if (not @valid_coll_list) {
188 # no valid colls left
189 &gsprintf($out, "{exportcol.fail}");
190 &gsprintf($out, "{exportcol.no_valid_colls}\n");
191 die "\n";
192 }
193
194 # create exported directory
195 my $topdir = &util::filename_cat ($ENV{'GSDLHOME'}, "tmp", $dirname);
196 &util::mk_all_dir ($topdir);
197 if (!-d $topdir) {
198 &gsprintf($out, "{exportcol.fail}");
199 &gsprintf($out, "{exportcol.couldnt_create_dir}\n", $topdir);
200 die "\n";
201 }
202
203 # make other directories (we'll assume that if we created topdir
204 # successfully there'll be no problems creating these)
205 my $gsdldir = &util::filename_cat ($topdir, "gsdl");
206 &util::mk_all_dir ($gsdldir);
207 my $collectdir = &util::filename_cat ($gsdldir, "collect");
208 &util::mk_all_dir ($collectdir);
209 my $etcdir = &util::filename_cat ($gsdldir, "etc");
210 &util::mk_all_dir ($etcdir);
211 my $binjavadir = &util::filename_cat ($gsdldir, "bin", "java");
212 &util::mk_all_dir ($binjavadir);
213
214 # create the install.cfg file
215 my $installcfg = &util::filename_cat ($topdir, "install.cfg");
216 if (!open (INSTALLCFG, ">$installcfg")) {
217 &gsprintf($out, "{exportcol.fail}");
218 &gsprintf($out, "{exportcol.couldnt_create_file}\n", $installcfg );
219 die "\n";
220 }
221 print INSTALLCFG "CompanyName:New Zealand Digital Library\n";
222 print INSTALLCFG "CollectionName:$cdname\n";
223 print INSTALLCFG "CollectionDirName:$cdname\n";
224 print INSTALLCFG "CollectionVersion:1.0\n";
225 print INSTALLCFG "CollectionVolume:1\n";
226 print INSTALLCFG "ProgramGroupName:Greenstone\n";
227 close INSTALLCFG;
228
229 # create the manifest.cfg file
230 my $manifestcfg = &util::filename_cat ($topdir, "manifest.cfg");
231 if (!open (MANIFESTCFG, ">$manifestcfg")) {
232 &gsprintf($out, "{exportcol.fail}");
233 &gsprintf($out, "{exportcol.couldnt_create_file}\n", $manifestcfg );
234 die "\n";
235 }
236 print MANIFESTCFG "all:\n";
237 print MANIFESTCFG " {library} {collection}\n\n";
238 print MANIFESTCFG "library:\n";
239 print MANIFESTCFG " net32 net16 server.exe\n\n";
240 print MANIFESTCFG "database:\n";
241 print MANIFESTCFG ' etc ';
242 foreach $c (@valid_coll_list) {
243 print MANIFESTCFG "collect\\$c\\index\\text\\$c.ldb ";
244 }
245 print MANIFESTCFG "\n\n";
246 print MANIFESTCFG "collection:\n";
247 print MANIFESTCFG " collect etc images macros mappings bin\n";
248 close MANIFESTCFG;
249
250 #create the autorun.inf file
251 my $autoruninf = &util::filename_cat ($topdir, "Autorun.inf");
252 if (!open (AUTORUNINF, ">$autoruninf")) {
253 &gsprintf($out, "{exportcol.fail}");
254 &gsprintf($out, "{exportcol.couldnt_create_file}\n", $autoruninf );
255 die "\n";
256 }
257
258 print AUTORUNINF "[autorun]\n";
259 print AUTORUNINF "OPEN=Setup.exe\n";
260 close AUTORUNINF;
261
262 # copy the necessary stuff from GSDLHOME
263 my $imagesdir = &util::filename_cat ($ENV{'GSDLHOME'}, "images");
264 my $macrosdir = &util::filename_cat ($ENV{'GSDLHOME'}, "macros");
265 my $mappingsdir = &util::filename_cat ($ENV{'GSDLHOME'}, "mappings");
266 my $maincfg = &util::filename_cat ($ENV{'GSDLHOME'}, "etc", "main.cfg");
267 my $serverexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "server.exe");
268 my $gssetupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "gssetup.exe");
269 my $setupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "Setup.exe");
270 my $net32dir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "net32");
271 my $net16dir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "net16");
272 my $netscapedir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "netscape");
273 my $win32sdir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "Win32s");
274 my $phindjar = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "java", "Phind.jar");
275
276 if ((!-d $imagesdir) || (!-d $macrosdir) || (!-d $mappingsdir) || (!-e $maincfg) ||
277 (!-e $serverexe) || (!-e $gssetupexe) || (!-e $setupexe) || (!-d $net32dir) ||
278 (!-d $net16dir) || (!-d $netscapedir) || (!-d $win32sdir) || (!-e $phindjar)) {
279 &gsprintf($out, "{exportcol.fail}");
280 &gsprintf($out, "{exportcol.non_exist_files}\n");
281 print $out " $imagesdir\n";
282 print $out " $macrosdir\n";
283 print $out " $mappingsdir\n";
284 print $out " $maincfg\n";
285 print $out " $serverexe\n";
286 print $out " $gssetupexe\n";
287 print $out " $setupexe\n";
288 print $out " $net32dir\n";
289 print $out " $net16dir\n";
290 print $out " $netscapedir\n";
291 print $out " $win32sdir\n";
292 print $out " $phindjar\n";
293 die "\n";
294 }
295
296 &util::cp_r ($imagesdir, $gsdldir);
297 &util::cp_r ($macrosdir, $gsdldir);
298 &util::cp_r ($mappingsdir, $gsdldir);
299 &util::cp ($maincfg, $etcdir);
300 &util::cp ($serverexe, $gsdldir);
301 &util::cp ($gssetupexe, $topdir);
302 &util::cp ($setupexe, $topdir);
303 &util::cp_r ($net32dir, $gsdldir);
304 &util::cp_r ($net16dir, $gsdldir);
305 &util::cp_r ($netscapedir, $topdir);
306 &util::cp_r ($win32sdir, $topdir);
307 &util::cp ($phindjar, $binjavadir);
308
309 # now change the home.dm macro file to a simple version
310 my $newmacrodir = &util::filename_cat ($gsdldir, "macros");
311 my $exporthome = &util::filename_cat ($newmacrodir, "exported_home.dm");
312 my $oldhome = &util::filename_cat ($newmacrodir, "home.dm");
313 if (-e $exporthome) {
314 &util::rm($oldhome);
315 &util::mv($exporthome, $oldhome);
316 }
317
318 # copy the collections over
319 foreach $c (@valid_coll_list) {
320 #old directories
321 my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
322 my $colindexdir = &util::filename_cat ($colldir, "index");
323 my $coletcdir = &util::filename_cat ($colldir, "etc");
324 my $colimagesdir = &util::filename_cat ($colldir, "images");
325 # new coll directory
326 my $newcoldir = &util::filename_cat ($collectdir, $c);
327
328 &util::mk_all_dir ($newcoldir);
329 &util::cp_r ($colindexdir, $newcoldir);
330 &util::cp_r ($coletcdir, $newcoldir);
331 &util::cp_r ($colimagesdir, $newcoldir) if (-e $colimagesdir);
332
333 # now we need to check the collect.cfg file to make sure its public
334 my $collectcfg = &util::filename_cat ($newcoldir, "etc", "collect.cfg");
335 open INFILE, "<$collectcfg";
336 open OUTFILE, ">$collectcfg.tmp";
337 while ($line = <INFILE>) {
338 if ($line =~ /^\s*public\s+false/) {
339 print OUTFILE "public\ttrue\n";
340 last; # stop matching once we have found the line
341 } else {
342 print OUTFILE "$line";
343 }
344 }
345 # continue with no checking
346 while ($line = <INFILE>) {
347 print OUTFILE "$line";
348 }
349 close INFILE;
350 close OUTFILE;
351 &util::mv("$collectcfg.tmp", $collectcfg);
352 }
353 &gsprintf($out, "{exportcol.success}");
354 my $successcolls = "";
355 my $first = 1;
356 foreach $c (@valid_coll_list) {
357 if ($first) {
358 $first=0;
359 } else {
360 $successcolls .=", ";
361 }
362 $successcolls .= "$c";
363
364 }
365
366 &gsprintf($out, "{exportcol.output_dir}\n", $successcolls, $topdir);
367 &gsprintf($out, "{exportcol.instructions}\n");
368 close OUT if $close_out;
369}
370
Note: See TracBrowser for help on using the repository browser.