source: branches/gsdl-2_70-distribution-branch/gsdl/bin/script/exportcol.pl@ 11709

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

no netscape option any more. no longer bundle netscape

  • Property svn:keywords set to Author Date Id Revision
File size: 12.1 KB
RevLine 
[2075]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
[10339]33use strict;
34no strict 'refs'; # allow filehandles to be variables and vice versa
35no strict 'subs'; # allow barewords (eg STDERR) as function arguments
36
[2075]37use util;
[10339]38use parse2;
[6054]39use printusage;
[2075]40
[6054]41my $arguments =
[6921]42 [ { 'name' => "language",
43 'desc' => "{scripts.language}",
44 'type' => "string",
45 'reqd' => "no" },
46 { 'name' => "out",
[6054]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",
[10225]55 'reqd' => "no" },
56 { 'name' => "cddir",
57 'desc' => "{exportcol.cddir}",
58 'type' => "string",
59 'deft' => "exported_collections",
[10339]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" },
[6054]71
[10339]72 ];
73
[6054]74my $options = { 'name' => "exportcol.pl",
75 'desc' => "{exportcol.desc}",
76 'args' => $arguments };
77
78sub gsprintf
79{
80 return &gsprintf::gsprintf(@_);
81}
82
[6921]83
[2075]84&main();
85
86sub main {
[10339]87 my ($language, $out, $cdname, $cddir, $gli);
[6054]88
89 my $xml = 0;
[6921]90
[10339]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\"}";
[2075]99 }
[10339]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
[6945]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 }
[6926]122
[6054]123 if ($xml) {
[6926]124 &PrintUsage::print_xml_usage($options);
[6054]125 die "\n";
126 }
[6921]127
[7101]128 if ($gli) { # the gli wants strings to be in UTF-8
129 &gsprintf::output_strings_in_UTF8;
130 }
[2075]131
[5920]132 my @coll_list = @ARGV;
[10339]133
[5920]134 if (not @coll_list) { # empty list
[6926]135 &PrintUsage::print_txt_usage($options, "{exportcol.params}");
[5920]136 exit(1);
[2075]137 }
[6921]138
[2075]139 my $close_out = 0;
140 if ($out !~ /^(STDERR|STDOUT)$/i) {
[6054]141 open (OUT, ">$out") ||
[6921]142 (&gsprintf(STDERR, "{common.cannot_open_output_file}\n", $out) && die);
[7256]143 $out = 'main::OUT';
[2075]144 $close_out = 1;
145 }
146
[7179]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
[5920]155 # check each collection
156 my @valid_coll_list = ();
[10339]157 foreach my $c (@coll_list) {
[5920]158 my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
159 if (! -d $colldir) {
[6054]160 &gsprintf($out, "{exportcol.coll_not_found}\n", $c, $colldir);
[5920]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)) {
[6054]166 &gsprintf($out, "{exportcol.coll_dirs_not_found}\n", $c);
[6921]167 &gsprintf($out, " $colindexdir\n");
168 &gsprintf($out, " $coletcdir\n");
[5920]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
[6921]177 &gsprintf($out, "{exportcol.fail} {exportcol.no_valid_colls}\n");
[5837]178 die "\n";
[2138]179 }
180
[2075]181 # create exported directory
[10225]182 my $topdir = &util::filename_cat ($ENV{'GSDLHOME'}, "tmp", $cddir);
[2075]183 &util::mk_all_dir ($topdir);
184 if (!-d $topdir) {
[6921]185 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_dir}\n", $topdir);
[2075]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);
[3730]197 my $binjavadir = &util::filename_cat ($gsdldir, "bin", "java");
198 &util::mk_all_dir ($binjavadir);
[2075]199
200 # create the install.cfg file
201 my $installcfg = &util::filename_cat ($topdir, "install.cfg");
202 if (!open (INSTALLCFG, ">$installcfg")) {
[6921]203 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $installcfg);
[2075]204 die "\n";
205 }
206 print INSTALLCFG "CompanyName:New Zealand Digital Library\n";
[5920]207 print INSTALLCFG "CollectionName:$cdname\n";
208 print INSTALLCFG "CollectionDirName:$cdname\n";
[2075]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")) {
[6921]217 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $manifestcfg);
[2075]218 die "\n";
219 }
220 print MANIFESTCFG "all:\n";
221 print MANIFESTCFG " {library} {collection}\n\n";
222 print MANIFESTCFG "library:\n";
[2334]223 print MANIFESTCFG " net32 net16 server.exe\n\n";
[2075]224 print MANIFESTCFG "database:\n";
[5920]225 print MANIFESTCFG ' etc ';
[10339]226 foreach my $c (@valid_coll_list) {
[5920]227 print MANIFESTCFG "collect\\$c\\index\\text\\$c.ldb ";
228 }
229 print MANIFESTCFG "\n\n";
[2075]230 print MANIFESTCFG "collection:\n";
[3730]231 print MANIFESTCFG " collect etc images macros mappings bin\n";
[2075]232 close MANIFESTCFG;
233
[5837]234 #create the autorun.inf file
235 my $autoruninf = &util::filename_cat ($topdir, "Autorun.inf");
236 if (!open (AUTORUNINF, ">$autoruninf")) {
[6921]237 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $autoruninf);
[5837]238 die "\n";
239 }
[6921]240
[5837]241 print AUTORUNINF "[autorun]\n";
242 print AUTORUNINF "OPEN=Setup.exe\n";
243 close AUTORUNINF;
[6921]244
[2075]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");
[7179]251 #my $gssetupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "gssetup.exe"); - have checked this earlier
[2075]252 my $setupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "Setup.exe");
[2334]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");
[3730]256 my $phindjar = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "java", "Phind.jar");
[6813]257 my $gsdlcollageappletjar = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "java", "GsdlCollageApplet.jar");
[2075]258
259 if ((!-d $imagesdir) || (!-d $macrosdir) || (!-d $mappingsdir) || (!-e $maincfg) ||
[2334]260 (!-e $serverexe) || (!-e $gssetupexe) || (!-e $setupexe) || (!-d $net32dir) ||
[11709]261 (!-d $net16dir) || (!-d $win32sdir) || (!-e $phindjar) ||
[6813]262 (!-e $gsdlcollageappletjar)) {
[6921]263 &gsprintf($out, "{exportcol.fail} {exportcol.non_exist_files}\n");
264 &gsprintf($out, " $imagesdir\n");
265 &gsprintf($out, " $macrosdir\n");
266 &gsprintf($out, " $mappingsdir\n");
267 &gsprintf($out, " $maincfg\n");
268 &gsprintf($out, " $serverexe\n");
269 &gsprintf($out, " $gssetupexe\n");
270 &gsprintf($out, " $setupexe\n");
271 &gsprintf($out, " $net32dir\n");
272 &gsprintf($out, " $net16dir\n");
273 &gsprintf($out, " $win32sdir\n");
274 &gsprintf($out, " $phindjar\n");
275 &gsprintf($out, " $gsdlcollageappletjar\n");
[2075]276 die "\n";
277 }
278
[11709]279 &util::cp_r ($imagesdir, $gsdldir);
[2075]280 &util::cp_r ($macrosdir, $gsdldir);
281 &util::cp_r ($mappingsdir, $gsdldir);
282 &util::cp ($maincfg, $etcdir);
283 &util::cp ($serverexe, $gsdldir);
284 &util::cp ($gssetupexe, $topdir);
285 &util::cp ($setupexe, $topdir);
[2334]286 &util::cp_r ($net32dir, $gsdldir);
287 &util::cp_r ($net16dir, $gsdldir);
288 &util::cp_r ($win32sdir, $topdir);
[3730]289 &util::cp ($phindjar, $binjavadir);
[6813]290 &util::cp ($gsdlcollageappletjar, $binjavadir);
[2075]291
[5849]292 # now change the home.dm macro file to a simple version
293 my $newmacrodir = &util::filename_cat ($gsdldir, "macros");
294 my $exporthome = &util::filename_cat ($newmacrodir, "exported_home.dm");
295 my $oldhome = &util::filename_cat ($newmacrodir, "home.dm");
296 if (-e $exporthome) {
297 &util::rm($oldhome);
298 &util::mv($exporthome, $oldhome);
299 }
300
[5920]301 # copy the collections over
[10339]302 foreach my $c (@valid_coll_list) {
[5920]303 #old directories
304 my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
305 my $colindexdir = &util::filename_cat ($colldir, "index");
306 my $coletcdir = &util::filename_cat ($colldir, "etc");
307 my $colimagesdir = &util::filename_cat ($colldir, "images");
[7951]308 my $colmacrosdir = &util::filename_cat ($colldir, "macros");
[5920]309 # new coll directory
310 my $newcoldir = &util::filename_cat ($collectdir, $c);
[2075]311
[5920]312 &util::mk_all_dir ($newcoldir);
313 &util::cp_r ($colindexdir, $newcoldir);
314 &util::cp_r ($coletcdir, $newcoldir);
315 &util::cp_r ($colimagesdir, $newcoldir) if (-e $colimagesdir);
[7951]316 &util::cp_r ($colmacrosdir, $newcoldir) if (-e $colmacrosdir);
[5920]317
[6921]318 # now we need to check the collect.cfg file to make sure it's public
[5920]319 my $collectcfg = &util::filename_cat ($newcoldir, "etc", "collect.cfg");
320 open INFILE, "<$collectcfg";
321 open OUTFILE, ">$collectcfg.tmp";
[10339]322 my $line;
[5920]323 while ($line = <INFILE>) {
324 if ($line =~ /^\s*public\s+false/) {
325 print OUTFILE "public\ttrue\n";
326 last; # stop matching once we have found the line
327 } else {
328 print OUTFILE "$line";
329 }
330 }
331 # continue with no checking
332 while ($line = <INFILE>) {
[5846]333 print OUTFILE "$line";
334 }
[5920]335 close INFILE;
336 close OUTFILE;
337 &util::mv("$collectcfg.tmp", $collectcfg);
[5846]338 }
[6054]339 &gsprintf($out, "{exportcol.success}");
[6921]340
[6788]341 my $successcolls = "";
342 my $first = 1;
[10339]343 foreach my $c (@valid_coll_list) {
[6788]344 if ($first) {
345 $first=0;
346 } else {
347 $successcolls .=", ";
348 }
349 $successcolls .= "$c";
350 }
351
[9236]352 my $gsdl_home = $ENV{'GSDLHOME'};
353 my $portable_topdir = $topdir;
[9432]354 # Disabled this because it isn't currently useful (the GLI applet doesn't do exporting)
355 # It doesn't work on Windows, either
356 # $portable_topdir =~ s/$gsdl_home/\$GSDLHOME/g;
[9236]357
358 &gsprintf($out, "{exportcol.output_dir}\n", $successcolls, $portable_topdir);
[7257]359 &gsprintf($out, "exportcol.pl succeeded:{exportcol.instructions}\n");
[2075]360 close OUT if $close_out;
361}
[6788]362
Note: See TracBrowser for help on using the repository browser.