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

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

does a check for one of teh export to cd files first and then tells the user that the export to cd function is not installed if it cant find it

  • Property svn:keywords set to Author Date Id Revision
File size: 10.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' => "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 # first we do a quick check to see if the export coll function has been
122 # installed
123 my $gssetupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "gssetup.exe");
124 if (!-e $gssetupexe) {
125 &gsprintf($out, "{exportcol.fail} {exportcol.export_coll_not_installed}\n");
126 die "\n";
127 }
128
129 # check each collection
130 my @valid_coll_list = ();
131 foreach $c (@coll_list) {
132 my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
133 if (! -d $colldir) {
134 &gsprintf($out, "{exportcol.coll_not_found}\n", $c, $colldir);
135 next;
136 }
137 my $colindexdir = &util::filename_cat ($colldir, "index");
138 my $coletcdir = &util::filename_cat ($colldir, "etc");
139 if ((!-d $colindexdir) || (!-d $coletcdir)) {
140 &gsprintf($out, "{exportcol.coll_dirs_not_found}\n", $c);
141 &gsprintf($out, " $colindexdir\n");
142 &gsprintf($out, " $coletcdir\n");
143 next;
144 }
145 # the collection seems ok, we add it to the valid coll list
146 push @valid_coll_list, $c;
147 }
148
149 if (not @valid_coll_list) {
150 # no valid colls left
151 &gsprintf($out, "{exportcol.fail} {exportcol.no_valid_colls}\n");
152 die "\n";
153 }
154
155 # create exported directory
156 my $topdir = &util::filename_cat ($ENV{'GSDLHOME'}, "tmp", $dirname);
157 &util::mk_all_dir ($topdir);
158 if (!-d $topdir) {
159 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_dir}\n", $topdir);
160 die "\n";
161 }
162
163 # make other directories (we'll assume that if we created topdir
164 # successfully there'll be no problems creating these)
165 my $gsdldir = &util::filename_cat ($topdir, "gsdl");
166 &util::mk_all_dir ($gsdldir);
167 my $collectdir = &util::filename_cat ($gsdldir, "collect");
168 &util::mk_all_dir ($collectdir);
169 my $etcdir = &util::filename_cat ($gsdldir, "etc");
170 &util::mk_all_dir ($etcdir);
171 my $binjavadir = &util::filename_cat ($gsdldir, "bin", "java");
172 &util::mk_all_dir ($binjavadir);
173
174 # create the install.cfg file
175 my $installcfg = &util::filename_cat ($topdir, "install.cfg");
176 if (!open (INSTALLCFG, ">$installcfg")) {
177 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $installcfg);
178 die "\n";
179 }
180 print INSTALLCFG "CompanyName:New Zealand Digital Library\n";
181 print INSTALLCFG "CollectionName:$cdname\n";
182 print INSTALLCFG "CollectionDirName:$cdname\n";
183 print INSTALLCFG "CollectionVersion:1.0\n";
184 print INSTALLCFG "CollectionVolume:1\n";
185 print INSTALLCFG "ProgramGroupName:Greenstone\n";
186 close INSTALLCFG;
187
188 # create the manifest.cfg file
189 my $manifestcfg = &util::filename_cat ($topdir, "manifest.cfg");
190 if (!open (MANIFESTCFG, ">$manifestcfg")) {
191 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $manifestcfg);
192 die "\n";
193 }
194 print MANIFESTCFG "all:\n";
195 print MANIFESTCFG " {library} {collection}\n\n";
196 print MANIFESTCFG "library:\n";
197 print MANIFESTCFG " net32 net16 server.exe\n\n";
198 print MANIFESTCFG "database:\n";
199 print MANIFESTCFG ' etc ';
200 foreach $c (@valid_coll_list) {
201 print MANIFESTCFG "collect\\$c\\index\\text\\$c.ldb ";
202 }
203 print MANIFESTCFG "\n\n";
204 print MANIFESTCFG "collection:\n";
205 print MANIFESTCFG " collect etc images macros mappings bin\n";
206 close MANIFESTCFG;
207
208 #create the autorun.inf file
209 my $autoruninf = &util::filename_cat ($topdir, "Autorun.inf");
210 if (!open (AUTORUNINF, ">$autoruninf")) {
211 &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $autoruninf);
212 die "\n";
213 }
214
215 print AUTORUNINF "[autorun]\n";
216 print AUTORUNINF "OPEN=Setup.exe\n";
217 close AUTORUNINF;
218
219 # copy the necessary stuff from GSDLHOME
220 my $imagesdir = &util::filename_cat ($ENV{'GSDLHOME'}, "images");
221 my $macrosdir = &util::filename_cat ($ENV{'GSDLHOME'}, "macros");
222 my $mappingsdir = &util::filename_cat ($ENV{'GSDLHOME'}, "mappings");
223 my $maincfg = &util::filename_cat ($ENV{'GSDLHOME'}, "etc", "main.cfg");
224 my $serverexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "server.exe");
225 #my $gssetupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "gssetup.exe"); - have checked this earlier
226 my $setupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "Setup.exe");
227 my $net32dir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "net32");
228 my $net16dir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "net16");
229 my $netscapedir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "netscape");
230 my $win32sdir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "Win32s");
231 my $phindjar = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "java", "Phind.jar");
232 my $gsdlcollageappletjar = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "java", "GsdlCollageApplet.jar");
233
234 if ((!-d $imagesdir) || (!-d $macrosdir) || (!-d $mappingsdir) || (!-e $maincfg) ||
235 (!-e $serverexe) || (!-e $gssetupexe) || (!-e $setupexe) || (!-d $net32dir) ||
236 (!-d $net16dir) || (!-d $netscapedir) || (!-d $win32sdir) || (!-e $phindjar) ||
237 (!-e $gsdlcollageappletjar)) {
238 &gsprintf($out, "{exportcol.fail} {exportcol.non_exist_files}\n");
239 &gsprintf($out, " $imagesdir\n");
240 &gsprintf($out, " $macrosdir\n");
241 &gsprintf($out, " $mappingsdir\n");
242 &gsprintf($out, " $maincfg\n");
243 &gsprintf($out, " $serverexe\n");
244 &gsprintf($out, " $gssetupexe\n");
245 &gsprintf($out, " $setupexe\n");
246 &gsprintf($out, " $net32dir\n");
247 &gsprintf($out, " $net16dir\n");
248 &gsprintf($out, " $netscapedir\n");
249 &gsprintf($out, " $win32sdir\n");
250 &gsprintf($out, " $phindjar\n");
251 &gsprintf($out, " $gsdlcollageappletjar\n");
252 die "\n";
253 }
254
255 &util::cp_r ($imagesdir, $gsdldir);
256 &util::cp_r ($macrosdir, $gsdldir);
257 &util::cp_r ($mappingsdir, $gsdldir);
258 &util::cp ($maincfg, $etcdir);
259 &util::cp ($serverexe, $gsdldir);
260 &util::cp ($gssetupexe, $topdir);
261 &util::cp ($setupexe, $topdir);
262 &util::cp_r ($net32dir, $gsdldir);
263 &util::cp_r ($net16dir, $gsdldir);
264 &util::cp_r ($netscapedir, $topdir);
265 &util::cp_r ($win32sdir, $topdir);
266 &util::cp ($phindjar, $binjavadir);
267 &util::cp ($gsdlcollageappletjar, $binjavadir);
268
269 # now change the home.dm macro file to a simple version
270 my $newmacrodir = &util::filename_cat ($gsdldir, "macros");
271 my $exporthome = &util::filename_cat ($newmacrodir, "exported_home.dm");
272 my $oldhome = &util::filename_cat ($newmacrodir, "home.dm");
273 if (-e $exporthome) {
274 &util::rm($oldhome);
275 &util::mv($exporthome, $oldhome);
276 }
277
278 # copy the collections over
279 foreach $c (@valid_coll_list) {
280 #old directories
281 my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
282 my $colindexdir = &util::filename_cat ($colldir, "index");
283 my $coletcdir = &util::filename_cat ($colldir, "etc");
284 my $colimagesdir = &util::filename_cat ($colldir, "images");
285 # new coll directory
286 my $newcoldir = &util::filename_cat ($collectdir, $c);
287
288 &util::mk_all_dir ($newcoldir);
289 &util::cp_r ($colindexdir, $newcoldir);
290 &util::cp_r ($coletcdir, $newcoldir);
291 &util::cp_r ($colimagesdir, $newcoldir) if (-e $colimagesdir);
292
293 # now we need to check the collect.cfg file to make sure it's public
294 my $collectcfg = &util::filename_cat ($newcoldir, "etc", "collect.cfg");
295 open INFILE, "<$collectcfg";
296 open OUTFILE, ">$collectcfg.tmp";
297 while ($line = <INFILE>) {
298 if ($line =~ /^\s*public\s+false/) {
299 print OUTFILE "public\ttrue\n";
300 last; # stop matching once we have found the line
301 } else {
302 print OUTFILE "$line";
303 }
304 }
305 # continue with no checking
306 while ($line = <INFILE>) {
307 print OUTFILE "$line";
308 }
309 close INFILE;
310 close OUTFILE;
311 &util::mv("$collectcfg.tmp", $collectcfg);
312 }
313 &gsprintf($out, "{exportcol.success}");
314
315 my $successcolls = "";
316 my $first = 1;
317 foreach $c (@valid_coll_list) {
318 if ($first) {
319 $first=0;
320 } else {
321 $successcolls .=", ";
322 }
323 $successcolls .= "$c";
324 }
325
326 &gsprintf($out, "{exportcol.output_dir}\n", $successcolls, $topdir);
327 &gsprintf($out, "{exportcol.instructions}\n");
328 close OUT if $close_out;
329}
330
Note: See TracBrowser for help on using the repository browser.