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

Last change on this file since 10225 was 10225, checked in by davidb, 19 years ago

cddir minus option put back in. Needed by applet version of GLI.

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