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