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

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

commented out or deleted all references to win32s, net16 and net32 which we no longer distribute

  • Property svn:keywords set to Author Date Id Revision
File size: 12.0 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 [ { 'name' => "language",
43 'desc' => "{scripts.language}",
44 'type' => "string",
45 'reqd' => "no" },
46 { 'name' => "out",
47 'desc' => "{exportcol.out}",
48 'type' => "string",
49 'deft' => "STDERR",
50 'reqd' => "no" },
51 { 'name' => "cdname",
52 'desc' => "{exportcol.cdname}",
53 'type' => "string",
54 'deft' => "Greenstone Collections",
55 'reqd' => "no" },
56 { 'name' => "cddir",
57 'desc' => "{exportcol.cddir}",
58 'type' => "string",
59 'deft' => "exported_collections",
60 'reqd' => "no" },
61 { 'name' => "xml",
62 'desc' => "{scripts.xml}",
63 'type' => "flag",
64 'reqd' => "no",
65 'hiddengli' => "yes" },
66 { 'name' => "gli",
67 'desc' => "",
68 'type' => "flag",
69 'reqd' => "no",
70 'hiddengli' => "yes" },
71
72 ];
73
74my $options = { 'name' => "exportcol.pl",
75 'desc' => "{exportcol.desc}",
76 'args' => $arguments };
77
78sub gsprintf
79{
80 return &gsprintf::gsprintf(@_);
81}
82
83
84&main();
85
86sub main {
87 my ($language, $out, $cdname, $cddir, $gli);
88
89 my $xml = 0;
90
91 my $hashParsingResult = {};
92 my $blnParseFailed = "false";
93 # parse options
94 my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
95 # don't care how many args are left - can have multiple collection names
96 foreach my $strVariable (keys %$hashParsingResult)
97 {
98 eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
99 }
100
101 # If $language has been specified, load the appropriate resource bundle
102 # (Otherwise, the default resource bundle will be loaded automatically)
103 if ($language && $language =~ /\S/) {
104 &gsprintf::load_language_specific_resource_bundle($language);
105 }
106
107 if ($xml) {
108 &PrintUsage::print_xml_usage($options);
109 print "\n";
110 return;
111 }
112
113 if ($gli) { # the gli wants strings to be in UTF-8
114 &gsprintf::output_strings_in_UTF8;
115 }
116
117 # If $language has been specified, load the appropriate resource bundle
118 # (Otherwise, the default resource bundle will be loaded automatically)
119 if ($language) {
120 &gsprintf::load_language_specific_resource_bundle($language);
121 }
122
123 if ($xml) {
124 &PrintUsage::print_xml_usage($options);
125 die "\n";
126 }
127
128 if ($gli) { # the gli wants strings to be in UTF-8
129 &gsprintf::output_strings_in_UTF8;
130 }
131
132 my @coll_list = @ARGV;
133
134 if (not @coll_list) { # empty list
135 &PrintUsage::print_txt_usage($options, "{exportcol.params}");
136 exit(1);
137 }
138
139 my $close_out = 0;
140 if ($out !~ /^(STDERR|STDOUT)$/i) {
141 open (OUT, ">$out") ||
142 (&gsprintf(STDERR, "{common.cannot_open_output_file}\n", $out) && die);
143 $out = 'main::OUT';
144 $close_out = 1;
145 }
146
147 # first we do a quick check to see if the export coll function has been
148 # installed
149 my $gssetupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "gssetup.exe");
150 if (!-e $gssetupexe) {
151 &gsprintf($out, "{exportcol.fail} {exportcol.export_coll_not_installed}\n");
152 die "\n";
153 }
154
155 # check each collection
156 my @valid_coll_list = ();
157 foreach my $c (@coll_list) {
158 my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
159 if (! -d $colldir) {
160 &gsprintf($out, "{exportcol.coll_not_found}\n", $c, $colldir);
161 next;
162 }
163 my $colindexdir = &util::filename_cat ($colldir, "index");
164 my $coletcdir = &util::filename_cat ($colldir, "etc");
165 if ((!-d $colindexdir) || (!-d $coletcdir)) {
166 &gsprintf($out, "{exportcol.coll_dirs_not_found}\n", $c);
167 &gsprintf($out, " $colindexdir\n");
168 &gsprintf($out, " $coletcdir\n");
169 next;
170 }
171 # the collection seems ok, we add it to the valid coll list
172 push @valid_coll_list, $c;
173 }
174
175 if (not @valid_coll_list) {
176 # no valid colls left
177 &gsprintf($out, "{exportcol.fail} {exportcol.no_valid_colls}\n");
178 die "\n";
179 }
180
181 # create exported directory
182 my $topdir = &util::filename_cat ($ENV{'GSDLHOME'}, "tmp", $cddir);
183 &util::mk_all_dir ($topdir);
184 if (!-d $topdir) {
185 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_dir}\n", $topdir);
186 die "\n";
187 }
188
189 # make other directories (we'll assume that if we created topdir
190 # successfully there'll be no problems creating these)
191 my $gsdldir = &util::filename_cat ($topdir, "gsdl");
192 &util::mk_all_dir ($gsdldir);
193 my $collectdir = &util::filename_cat ($gsdldir, "collect");
194 &util::mk_all_dir ($collectdir);
195 my $etcdir = &util::filename_cat ($gsdldir, "etc");
196 &util::mk_all_dir ($etcdir);
197 my $binjavadir = &util::filename_cat ($gsdldir, "bin", "java");
198 &util::mk_all_dir ($binjavadir);
199
200 # create the install.cfg file
201 my $installcfg = &util::filename_cat ($topdir, "install.cfg");
202 if (!open (INSTALLCFG, ">$installcfg")) {
203 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $installcfg);
204 die "\n";
205 }
206 print INSTALLCFG "CompanyName:New Zealand Digital Library\n";
207 print INSTALLCFG "CollectionName:$cdname\n";
208 print INSTALLCFG "CollectionDirName:$cdname\n";
209 print INSTALLCFG "CollectionVersion:1.0\n";
210 print INSTALLCFG "CollectionVolume:1\n";
211 print INSTALLCFG "ProgramGroupName:Greenstone\n";
212 close INSTALLCFG;
213
214 # create the manifest.cfg file
215 my $manifestcfg = &util::filename_cat ($topdir, "manifest.cfg");
216 if (!open (MANIFESTCFG, ">$manifestcfg")) {
217 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $manifestcfg);
218 die "\n";
219 }
220 print MANIFESTCFG "all:\n";
221 print MANIFESTCFG " {library} {collection}\n\n";
222 print MANIFESTCFG "library:\n";
223 print MANIFESTCFG " server.exe\n\n";
224 print MANIFESTCFG "database:\n";
225 print MANIFESTCFG ' etc ';
226 foreach my $c (@valid_coll_list) {
227 print MANIFESTCFG "collect\\$c\\index\\text\\$c.ldb ";
228 }
229 print MANIFESTCFG "\n\n";
230 print MANIFESTCFG "collection:\n";
231 print MANIFESTCFG " collect etc images macros mappings bin\n";
232 close MANIFESTCFG;
233
234 #create the autorun.inf file
235 my $autoruninf = &util::filename_cat ($topdir, "Autorun.inf");
236 if (!open (AUTORUNINF, ">$autoruninf")) {
237 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $autoruninf);
238 die "\n";
239 }
240
241 print AUTORUNINF "[autorun]\n";
242 print AUTORUNINF "OPEN=Setup.exe\n";
243 close AUTORUNINF;
244
245 # copy the necessary stuff from GSDLHOME
246 my $imagesdir = &util::filename_cat ($ENV{'GSDLHOME'}, "images");
247 my $macrosdir = &util::filename_cat ($ENV{'GSDLHOME'}, "macros");
248 my $mappingsdir = &util::filename_cat ($ENV{'GSDLHOME'}, "mappings");
249 my $maincfg = &util::filename_cat ($ENV{'GSDLHOME'}, "etc", "main.cfg");
250 my $serverexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "server.exe");
251 #my $gssetupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "gssetup.exe"); - have checked this earlier
252 my $setupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "Setup.exe");
253 #my $net32dir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "net32");
254 #my $net16dir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "net16");
255 #my $win32sdir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "Win32s");
256 my $phindjar = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "java", "Phind.jar");
257 my $gsdlcollageappletjar = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "java", "GsdlCollageApplet.jar");
258
259 if ((!-d $imagesdir) || (!-d $macrosdir) || (!-d $mappingsdir) || (!-e $maincfg) ||
260 (!-e $serverexe) || (!-e $gssetupexe) || (!-e $setupexe) || (!-e $phindjar) ||
261 (!-e $gsdlcollageappletjar)) {
262 &gsprintf($out, "{exportcol.fail} {exportcol.non_exist_files}\n");
263 &gsprintf($out, " $imagesdir\n");
264 &gsprintf($out, " $macrosdir\n");
265 &gsprintf($out, " $mappingsdir\n");
266 &gsprintf($out, " $maincfg\n");
267 &gsprintf($out, " $serverexe\n");
268 &gsprintf($out, " $gssetupexe\n");
269 &gsprintf($out, " $setupexe\n");
270# &gsprintf($out, " $net32dir\n");
271# &gsprintf($out, " $net16dir\n");
272# &gsprintf($out, " $win32sdir\n");
273 &gsprintf($out, " $phindjar\n");
274 &gsprintf($out, " $gsdlcollageappletjar\n");
275 die "\n";
276 }
277
278 &util::cp_r ($imagesdir, $gsdldir);
279 &util::cp_r ($macrosdir, $gsdldir);
280 &util::cp_r ($mappingsdir, $gsdldir);
281 &util::cp ($maincfg, $etcdir);
282 &util::cp ($serverexe, $gsdldir);
283 &util::cp ($gssetupexe, $topdir);
284 &util::cp ($setupexe, $topdir);
285# &util::cp_r ($net32dir, $gsdldir);
286# &util::cp_r ($net16dir, $gsdldir);
287# &util::cp_r ($win32sdir, $topdir);
288 &util::cp ($phindjar, $binjavadir);
289 &util::cp ($gsdlcollageappletjar, $binjavadir);
290
291 # now change the home.dm macro file to a simple version
292 my $newmacrodir = &util::filename_cat ($gsdldir, "macros");
293 my $exporthome = &util::filename_cat ($newmacrodir, "exported_home.dm");
294 my $oldhome = &util::filename_cat ($newmacrodir, "home.dm");
295 if (-e $exporthome) {
296 &util::rm($oldhome);
297 &util::mv($exporthome, $oldhome);
298 }
299
300 # copy the collections over
301 foreach my $c (@valid_coll_list) {
302 #old directories
303 my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
304 my $colindexdir = &util::filename_cat ($colldir, "index");
305 my $coletcdir = &util::filename_cat ($colldir, "etc");
306 my $colimagesdir = &util::filename_cat ($colldir, "images");
307 my $colmacrosdir = &util::filename_cat ($colldir, "macros");
308 # new coll directory
309 my $newcoldir = &util::filename_cat ($collectdir, $c);
310
311 &util::mk_all_dir ($newcoldir);
312 &util::cp_r ($colindexdir, $newcoldir);
313 &util::cp_r ($coletcdir, $newcoldir);
314 &util::cp_r ($colimagesdir, $newcoldir) if (-e $colimagesdir);
315 &util::cp_r ($colmacrosdir, $newcoldir) if (-e $colmacrosdir);
316
317 # now we need to check the collect.cfg file to make sure it's public
318 my $collectcfg = &util::filename_cat ($newcoldir, "etc", "collect.cfg");
319 open INFILE, "<$collectcfg";
320 open OUTFILE, ">$collectcfg.tmp";
321 my $line;
322 while ($line = <INFILE>) {
323 if ($line =~ /^\s*public\s+false/) {
324 print OUTFILE "public\ttrue\n";
325 last; # stop matching once we have found the line
326 } else {
327 print OUTFILE "$line";
328 }
329 }
330 # continue with no checking
331 while ($line = <INFILE>) {
332 print OUTFILE "$line";
333 }
334 close INFILE;
335 close OUTFILE;
336 &util::mv("$collectcfg.tmp", $collectcfg);
337 }
338 &gsprintf($out, "{exportcol.success}");
339
340 my $successcolls = "";
341 my $first = 1;
342 foreach my $c (@valid_coll_list) {
343 if ($first) {
344 $first=0;
345 } else {
346 $successcolls .=", ";
347 }
348 $successcolls .= "$c";
349 }
350
351 my $gsdl_home = $ENV{'GSDLHOME'};
352 my $portable_topdir = $topdir;
353 # Disabled this because it isn't currently useful (the GLI applet doesn't do exporting)
354 # It doesn't work on Windows, either
355 # $portable_topdir =~ s/$gsdl_home/\$GSDLHOME/g;
356
357 &gsprintf($out, "{exportcol.output_dir}\n", $successcolls, $portable_topdir);
358 &gsprintf($out, "exportcol.pl succeeded:{exportcol.instructions}\n");
359 close OUT if $close_out;
360}
361
Note: See TracBrowser for help on using the repository browser.