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

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

removed the old commented out print usage stuff, added gli arg if it didn't have it, if gli arg is set, output strings in utf-8

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