[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 |
|
---|
| 28 | BEGIN {
|
---|
| 29 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
| 30 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
| 31 | }
|
---|
| 32 |
|
---|
[10339] | 33 | use strict;
|
---|
| 34 | no strict 'refs'; # allow filehandles to be variables and vice versa
|
---|
| 35 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
| 36 |
|
---|
[2075] | 37 | use util;
|
---|
[10339] | 38 | use parse2;
|
---|
[6054] | 39 | use printusage;
|
---|
[2075] | 40 |
|
---|
[6054] | 41 | my $arguments =
|
---|
[11944] | 42 | [
|
---|
[6054] | 43 | { 'name' => "cdname",
|
---|
| 44 | 'desc' => "{exportcol.cdname}",
|
---|
| 45 | 'type' => "string",
|
---|
| 46 | 'deft' => "Greenstone Collections",
|
---|
[10225] | 47 | 'reqd' => "no" },
|
---|
| 48 | { 'name' => "cddir",
|
---|
| 49 | 'desc' => "{exportcol.cddir}",
|
---|
| 50 | 'type' => "string",
|
---|
| 51 | 'deft' => "exported_collections",
|
---|
[10339] | 52 | 'reqd' => "no" },
|
---|
[11944] | 53 | { 'name' => "noinstall",
|
---|
| 54 | 'desc' => "{exportcol.noinstall}",
|
---|
| 55 | 'type' => "flag",
|
---|
| 56 | 'reqd' => "no" },
|
---|
| 57 | { 'name' => "language",
|
---|
| 58 | 'desc' => "{scripts.language}",
|
---|
| 59 | 'type' => "string",
|
---|
| 60 | 'reqd' => "no" },
|
---|
| 61 | { 'name' => "out",
|
---|
| 62 | 'desc' => "{exportcol.out}",
|
---|
| 63 | 'type' => "string",
|
---|
| 64 | 'deft' => "STDERR",
|
---|
| 65 | 'reqd' => "no" },
|
---|
[10339] | 66 | { 'name' => "xml",
|
---|
| 67 | 'desc' => "{scripts.xml}",
|
---|
| 68 | 'type' => "flag",
|
---|
| 69 | 'reqd' => "no",
|
---|
| 70 | 'hiddengli' => "yes" },
|
---|
| 71 | { 'name' => "gli",
|
---|
| 72 | 'desc' => "",
|
---|
| 73 | 'type' => "flag",
|
---|
| 74 | 'reqd' => "no",
|
---|
| 75 | 'hiddengli' => "yes" },
|
---|
[6054] | 76 |
|
---|
[10339] | 77 | ];
|
---|
| 78 |
|
---|
[6054] | 79 | my $options = { 'name' => "exportcol.pl",
|
---|
| 80 | 'desc' => "{exportcol.desc}",
|
---|
| 81 | 'args' => $arguments };
|
---|
| 82 |
|
---|
| 83 | sub gsprintf
|
---|
| 84 | {
|
---|
| 85 | return &gsprintf::gsprintf(@_);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
[6921] | 88 |
|
---|
[2075] | 89 | &main();
|
---|
| 90 |
|
---|
| 91 | sub main {
|
---|
[11944] | 92 | my ($language, $out, $cdname, $cddir);
|
---|
| 93 |
|
---|
| 94 | my $noinstall = 0;
|
---|
[6054] | 95 | my $xml = 0;
|
---|
[11944] | 96 | my $gli = 0;
|
---|
[6921] | 97 |
|
---|
[10339] | 98 | my $hashParsingResult = {};
|
---|
[12545] | 99 |
|
---|
[10339] | 100 | # parse options
|
---|
| 101 | my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
|
---|
[12545] | 102 |
|
---|
| 103 | # If parse returns -1 then something has gone wrong
|
---|
| 104 | if ($intArgLeftinAfterParsing == -1)
|
---|
| 105 | {
|
---|
| 106 | &PrintUsage::print_txt_usage($options, "{exportcol.params}");
|
---|
| 107 | die "\n";
|
---|
| 108 | }
|
---|
| 109 |
|
---|
[10339] | 110 | foreach my $strVariable (keys %$hashParsingResult)
|
---|
| 111 | {
|
---|
| 112 | eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
|
---|
[2075] | 113 | }
|
---|
[10339] | 114 |
|
---|
| 115 | # If $language has been specified, load the appropriate resource bundle
|
---|
| 116 | # (Otherwise, the default resource bundle will be loaded automatically)
|
---|
| 117 | if ($language && $language =~ /\S/) {
|
---|
| 118 | &gsprintf::load_language_specific_resource_bundle($language);
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | if ($xml) {
|
---|
| 122 | &PrintUsage::print_xml_usage($options);
|
---|
| 123 | print "\n";
|
---|
| 124 | return;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | if ($gli) { # the gli wants strings to be in UTF-8
|
---|
| 128 | &gsprintf::output_strings_in_UTF8;
|
---|
| 129 | }
|
---|
| 130 |
|
---|
[12545] | 131 | # can have more than one collection name,
|
---|
| 132 | # if the first extra option is -h, then output the help
|
---|
| 133 | if (scalar(@ARGV) == 0 || (@ARGV && $ARGV[0] =~ /^\-+h/)) {
|
---|
[6926] | 134 | &PrintUsage::print_txt_usage($options, "{exportcol.params}");
|
---|
[12545] | 135 | die "\n";
|
---|
[2075] | 136 | }
|
---|
[6921] | 137 |
|
---|
[12545] | 138 | my @coll_list = @ARGV;
|
---|
| 139 |
|
---|
[2075] | 140 | my $close_out = 0;
|
---|
| 141 | if ($out !~ /^(STDERR|STDOUT)$/i) {
|
---|
[6054] | 142 | open (OUT, ">$out") ||
|
---|
[6921] | 143 | (&gsprintf(STDERR, "{common.cannot_open_output_file}\n", $out) && die);
|
---|
[7256] | 144 | $out = 'main::OUT';
|
---|
[2075] | 145 | $close_out = 1;
|
---|
| 146 | }
|
---|
| 147 |
|
---|
[7179] | 148 | # first we do a quick check to see if the export coll function has been
|
---|
| 149 | # installed
|
---|
| 150 | my $gssetupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "gssetup.exe");
|
---|
| 151 | if (!-e $gssetupexe) {
|
---|
| 152 | &gsprintf($out, "{exportcol.fail} {exportcol.export_coll_not_installed}\n");
|
---|
| 153 | die "\n";
|
---|
| 154 | }
|
---|
| 155 |
|
---|
[5920] | 156 | # check each collection
|
---|
| 157 | my @valid_coll_list = ();
|
---|
[10339] | 158 | foreach my $c (@coll_list) {
|
---|
[5920] | 159 | my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
|
---|
| 160 | if (! -d $colldir) {
|
---|
[6054] | 161 | &gsprintf($out, "{exportcol.coll_not_found}\n", $c, $colldir);
|
---|
[5920] | 162 | next;
|
---|
| 163 | }
|
---|
| 164 | my $colindexdir = &util::filename_cat ($colldir, "index");
|
---|
| 165 | my $coletcdir = &util::filename_cat ($colldir, "etc");
|
---|
| 166 | if ((!-d $colindexdir) || (!-d $coletcdir)) {
|
---|
[6054] | 167 | &gsprintf($out, "{exportcol.coll_dirs_not_found}\n", $c);
|
---|
[6921] | 168 | &gsprintf($out, " $colindexdir\n");
|
---|
| 169 | &gsprintf($out, " $coletcdir\n");
|
---|
[5920] | 170 | next;
|
---|
| 171 | }
|
---|
| 172 | # the collection seems ok, we add it to the valid coll list
|
---|
| 173 | push @valid_coll_list, $c;
|
---|
| 174 | }
|
---|
| 175 |
|
---|
| 176 | if (not @valid_coll_list) {
|
---|
| 177 | # no valid colls left
|
---|
[6921] | 178 | &gsprintf($out, "{exportcol.fail} {exportcol.no_valid_colls}\n");
|
---|
[5837] | 179 | die "\n";
|
---|
[2138] | 180 | }
|
---|
| 181 |
|
---|
[2075] | 182 | # create exported directory
|
---|
[10225] | 183 | my $topdir = &util::filename_cat ($ENV{'GSDLHOME'}, "tmp", $cddir);
|
---|
[2075] | 184 | &util::mk_all_dir ($topdir);
|
---|
| 185 | if (!-d $topdir) {
|
---|
[6921] | 186 | &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_dir}\n", $topdir);
|
---|
[2075] | 187 | die "\n";
|
---|
| 188 | }
|
---|
| 189 |
|
---|
[11944] | 190 | # we create either a self installing cd, or one that runs off the cd (and
|
---|
| 191 | # doesn't install anything
|
---|
| 192 |
|
---|
| 193 | # create all the directories - we assume that if we created the top dir ok,
|
---|
| 194 | # then all the other mkdirs will go ok
|
---|
| 195 | my $gsdldir;
|
---|
| 196 | if ($noinstall) {
|
---|
| 197 | $gsdldir = $topdir;
|
---|
| 198 | }
|
---|
| 199 | else {
|
---|
| 200 | $gsdldir = &util::filename_cat ($topdir, "gsdl");
|
---|
| 201 | &util::mk_all_dir ($gsdldir);
|
---|
| 202 | }
|
---|
| 203 |
|
---|
[2075] | 204 | my $collectdir = &util::filename_cat ($gsdldir, "collect");
|
---|
| 205 | &util::mk_all_dir ($collectdir);
|
---|
| 206 | my $etcdir = &util::filename_cat ($gsdldir, "etc");
|
---|
| 207 | &util::mk_all_dir ($etcdir);
|
---|
[19650] | 208 | my $webjavadir = &util::filename_cat ($gsdldir, "web", "java");
|
---|
| 209 | &util::mk_all_dir ($webjavadir);
|
---|
[2075] | 210 |
|
---|
[11944] | 211 | #create the config files
|
---|
| 212 | if (!$noinstall) {
|
---|
| 213 | # create the install.cfg file
|
---|
| 214 | my $installcfg = &util::filename_cat ($topdir, "install.cfg");
|
---|
| 215 | if (!open (INSTALLCFG, ">$installcfg")) {
|
---|
| 216 | &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $installcfg);
|
---|
| 217 | die "\n";
|
---|
| 218 | }
|
---|
| 219 | print INSTALLCFG "CompanyName:New Zealand Digital Library\n";
|
---|
| 220 | print INSTALLCFG "CollectionName:$cdname\n";
|
---|
| 221 | print INSTALLCFG "CollectionDirName:$cdname\n";
|
---|
| 222 | print INSTALLCFG "CollectionVersion:1.0\n";
|
---|
| 223 | print INSTALLCFG "CollectionVolume:1\n";
|
---|
| 224 | print INSTALLCFG "ProgramGroupName:Greenstone\n";
|
---|
| 225 | close INSTALLCFG;
|
---|
| 226 |
|
---|
| 227 | # create the manifest.cfg file
|
---|
| 228 | my $manifestcfg = &util::filename_cat ($topdir, "manifest.cfg");
|
---|
| 229 | if (!open (MANIFESTCFG, ">$manifestcfg")) {
|
---|
| 230 | &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $manifestcfg);
|
---|
| 231 | die "\n";
|
---|
| 232 | }
|
---|
| 233 | print MANIFESTCFG "all:\n";
|
---|
| 234 | print MANIFESTCFG " {library} {collection}\n\n";
|
---|
| 235 | print MANIFESTCFG "library:\n";
|
---|
| 236 | print MANIFESTCFG " server.exe\n\n";
|
---|
| 237 | print MANIFESTCFG "database:\n";
|
---|
| 238 | print MANIFESTCFG ' etc ';
|
---|
| 239 | foreach my $c (@valid_coll_list) {
|
---|
[18660] | 240 | print MANIFESTCFG "collect\\$c\\index\\text\\$c.gdb ";
|
---|
[11944] | 241 | }
|
---|
| 242 | print MANIFESTCFG "\n\n";
|
---|
| 243 | print MANIFESTCFG "collection:\n";
|
---|
[19650] | 244 | print MANIFESTCFG " collect etc macros mappings bin web images\n";
|
---|
[11944] | 245 | close MANIFESTCFG;
|
---|
| 246 |
|
---|
| 247 | }
|
---|
[2075] | 248 |
|
---|
[5837] | 249 | #create the autorun.inf file
|
---|
| 250 | my $autoruninf = &util::filename_cat ($topdir, "Autorun.inf");
|
---|
| 251 | if (!open (AUTORUNINF, ">$autoruninf")) {
|
---|
[6921] | 252 | &gsprintf($out, "{exportcol.fail} {exportcol.couldnt_create_file}\n", $autoruninf);
|
---|
[5837] | 253 | die "\n";
|
---|
| 254 | }
|
---|
[11944] | 255 |
|
---|
[5837] | 256 | print AUTORUNINF "[autorun]\n";
|
---|
[11944] | 257 | if ($noinstall) {
|
---|
| 258 | print AUTORUNINF "OPEN=server.exe\n";
|
---|
| 259 | } else {
|
---|
| 260 | print AUTORUNINF "OPEN=Setup.exe\n";
|
---|
| 261 | }
|
---|
[5837] | 262 | close AUTORUNINF;
|
---|
[11944] | 263 |
|
---|
[2075] | 264 | # copy the necessary stuff from GSDLHOME
|
---|
[19648] | 265 | my $imagesdir = &util::filename_cat ($ENV{'GSDLHOME'}, "web", "images");
|
---|
[2075] | 266 | my $macrosdir = &util::filename_cat ($ENV{'GSDLHOME'}, "macros");
|
---|
| 267 | my $mappingsdir = &util::filename_cat ($ENV{'GSDLHOME'}, "mappings");
|
---|
| 268 | my $maincfg = &util::filename_cat ($ENV{'GSDLHOME'}, "etc", "main.cfg");
|
---|
| 269 | my $serverexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "server.exe");
|
---|
| 270 | my $setupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "Setup.exe");
|
---|
[19648] | 271 | my $phindjar = &util::filename_cat ($ENV{'GSDLHOME'}, "web", "java", "Phind.jar");
|
---|
| 272 | my $gsdlcollageappletjar = &util::filename_cat ($ENV{'GSDLHOME'}, "web", "java", "GsdlCollageApplet.jar");
|
---|
[2075] | 273 |
|
---|
| 274 | if ((!-d $imagesdir) || (!-d $macrosdir) || (!-d $mappingsdir) || (!-e $maincfg) ||
|
---|
[11895] | 275 | (!-e $serverexe) || (!-e $gssetupexe) || (!-e $setupexe) || (!-e $phindjar) ||
|
---|
[6813] | 276 | (!-e $gsdlcollageappletjar)) {
|
---|
[6921] | 277 | &gsprintf($out, "{exportcol.fail} {exportcol.non_exist_files}\n");
|
---|
| 278 | &gsprintf($out, " $imagesdir\n");
|
---|
| 279 | &gsprintf($out, " $macrosdir\n");
|
---|
| 280 | &gsprintf($out, " $mappingsdir\n");
|
---|
| 281 | &gsprintf($out, " $maincfg\n");
|
---|
| 282 | &gsprintf($out, " $serverexe\n");
|
---|
| 283 | &gsprintf($out, " $gssetupexe\n");
|
---|
| 284 | &gsprintf($out, " $setupexe\n");
|
---|
| 285 | &gsprintf($out, " $phindjar\n");
|
---|
| 286 | &gsprintf($out, " $gsdlcollageappletjar\n");
|
---|
[2075] | 287 | die "\n";
|
---|
| 288 | }
|
---|
| 289 |
|
---|
[11747] | 290 | &util::cp_r ($imagesdir, $gsdldir);
|
---|
[2075] | 291 | &util::cp_r ($macrosdir, $gsdldir);
|
---|
| 292 | &util::cp_r ($mappingsdir, $gsdldir);
|
---|
| 293 | &util::cp ($maincfg, $etcdir);
|
---|
| 294 | &util::cp ($serverexe, $gsdldir);
|
---|
[19650] | 295 | &util::cp ($phindjar, $webjavadir);
|
---|
| 296 | &util::cp ($gsdlcollageappletjar, $webjavadir);
|
---|
[2075] | 297 |
|
---|
[11944] | 298 | if (!$noinstall) {
|
---|
| 299 | &util::cp ($gssetupexe, $topdir);
|
---|
| 300 | &util::cp ($setupexe, $topdir);
|
---|
| 301 | }
|
---|
| 302 |
|
---|
[5849] | 303 | # now change the home.dm macro file to a simple version
|
---|
| 304 | my $newmacrodir = &util::filename_cat ($gsdldir, "macros");
|
---|
| 305 | my $exporthome = &util::filename_cat ($newmacrodir, "exported_home.dm");
|
---|
| 306 | my $oldhome = &util::filename_cat ($newmacrodir, "home.dm");
|
---|
| 307 | if (-e $exporthome) {
|
---|
| 308 | &util::rm($oldhome);
|
---|
| 309 | &util::mv($exporthome, $oldhome);
|
---|
| 310 | }
|
---|
| 311 |
|
---|
[5920] | 312 | # copy the collections over
|
---|
[10339] | 313 | foreach my $c (@valid_coll_list) {
|
---|
[5920] | 314 | #old directories
|
---|
| 315 | my $colldir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $c);
|
---|
| 316 | my $colindexdir = &util::filename_cat ($colldir, "index");
|
---|
| 317 | my $coletcdir = &util::filename_cat ($colldir, "etc");
|
---|
| 318 | my $colimagesdir = &util::filename_cat ($colldir, "images");
|
---|
[7951] | 319 | my $colmacrosdir = &util::filename_cat ($colldir, "macros");
|
---|
[5920] | 320 | # new coll directory
|
---|
| 321 | my $newcoldir = &util::filename_cat ($collectdir, $c);
|
---|
[2075] | 322 |
|
---|
[5920] | 323 | &util::mk_all_dir ($newcoldir);
|
---|
| 324 | &util::cp_r ($colindexdir, $newcoldir);
|
---|
[18660] | 325 | &util::rename_gdbm_file(&util::filename_cat ($newcoldir, "index", "text", $c));
|
---|
[5920] | 326 | &util::cp_r ($coletcdir, $newcoldir);
|
---|
| 327 | &util::cp_r ($colimagesdir, $newcoldir) if (-e $colimagesdir);
|
---|
[7951] | 328 | &util::cp_r ($colmacrosdir, $newcoldir) if (-e $colmacrosdir);
|
---|
[5920] | 329 |
|
---|
[6921] | 330 | # now we need to check the collect.cfg file to make sure it's public
|
---|
[5920] | 331 | my $collectcfg = &util::filename_cat ($newcoldir, "etc", "collect.cfg");
|
---|
| 332 | open INFILE, "<$collectcfg";
|
---|
| 333 | open OUTFILE, ">$collectcfg.tmp";
|
---|
[10339] | 334 | my $line;
|
---|
[5920] | 335 | while ($line = <INFILE>) {
|
---|
| 336 | if ($line =~ /^\s*public\s+false/) {
|
---|
| 337 | print OUTFILE "public\ttrue\n";
|
---|
| 338 | last; # stop matching once we have found the line
|
---|
| 339 | } else {
|
---|
| 340 | print OUTFILE "$line";
|
---|
| 341 | }
|
---|
| 342 | }
|
---|
| 343 | # continue with no checking
|
---|
| 344 | while ($line = <INFILE>) {
|
---|
[5846] | 345 | print OUTFILE "$line";
|
---|
| 346 | }
|
---|
[5920] | 347 | close INFILE;
|
---|
| 348 | close OUTFILE;
|
---|
| 349 | &util::mv("$collectcfg.tmp", $collectcfg);
|
---|
[5846] | 350 | }
|
---|
[6054] | 351 | &gsprintf($out, "{exportcol.success}");
|
---|
[6921] | 352 |
|
---|
[6788] | 353 | my $successcolls = "";
|
---|
| 354 | my $first = 1;
|
---|
[10339] | 355 | foreach my $c (@valid_coll_list) {
|
---|
[6788] | 356 | if ($first) {
|
---|
| 357 | $first=0;
|
---|
| 358 | } else {
|
---|
| 359 | $successcolls .=", ";
|
---|
| 360 | }
|
---|
| 361 | $successcolls .= "$c";
|
---|
| 362 | }
|
---|
| 363 |
|
---|
[9236] | 364 | my $gsdl_home = $ENV{'GSDLHOME'};
|
---|
| 365 | my $portable_topdir = $topdir;
|
---|
[9432] | 366 | # Disabled this because it isn't currently useful (the GLI applet doesn't do exporting)
|
---|
| 367 | # It doesn't work on Windows, either
|
---|
| 368 | # $portable_topdir =~ s/$gsdl_home/\$GSDLHOME/g;
|
---|
[9236] | 369 |
|
---|
| 370 | &gsprintf($out, "{exportcol.output_dir}\n", $successcolls, $portable_topdir);
|
---|
[7257] | 371 | &gsprintf($out, "exportcol.pl succeeded:{exportcol.instructions}\n");
|
---|
[2075] | 372 | close OUT if $close_out;
|
---|
| 373 | }
|
---|
[6788] | 374 |
|
---|