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

Last change on this file since 6945 was 6945, checked in by mdewsnip, 20 years ago

Updated the resource bundle handling code some more. Strings are first looked for in a language specific resource bundle (if specified). If not found there, the default resource bundle is checked. If still not found, the English resource bundle is checked. These resource bundles are loaded on an as-needed basis.

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