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;
|
---|
35 |
|
---|
36 | sub print_usage {
|
---|
37 | print STDERR "\n";
|
---|
38 | print STDERR "exportcol.pl: Exports a collection for writing to CD-ROM.\n\n";
|
---|
39 | print STDERR " usage: $0 [options] collection-name\n\n";
|
---|
40 | print STDERR " -out Filename or handle to print debug info to.\n";
|
---|
41 | print STDERR " The default is STDERR\n\n";
|
---|
42 | }
|
---|
43 |
|
---|
44 | &main();
|
---|
45 |
|
---|
46 | sub main {
|
---|
47 | my ($out, $collection);
|
---|
48 | if (!parsargv::parse(\@ARGV, 'out/.*/STDERR', \$out)) {
|
---|
49 | &print_usage();
|
---|
50 | die "\n";
|
---|
51 | }
|
---|
52 |
|
---|
53 | # get and check the collection name
|
---|
54 | if (($collection = &util::use_collection(@ARGV)) eq "") {
|
---|
55 | &print_usage();
|
---|
56 | exit (1);
|
---|
57 | }
|
---|
58 |
|
---|
59 | my $close_out = 0;
|
---|
60 | if ($out !~ /^(STDERR|STDOUT)$/i) {
|
---|
61 | open (OUT, ">$out") || die "Couldn't open output file $out\n";
|
---|
62 | $out = OUT;
|
---|
63 | $close_out = 1;
|
---|
64 | }
|
---|
65 |
|
---|
66 | # make sure the collection is built (or at least contains all the
|
---|
67 | # directories we expect it to) - we expect that it should contain an
|
---|
68 | # index and an etc directory and will also copy across an images
|
---|
69 | # directory if it exists
|
---|
70 | my $colindexdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection, "index");
|
---|
71 | my $colimagesdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection, "images");
|
---|
72 | my $coletcdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection, "etc");
|
---|
73 | if ((!-d $colindexdir) || (!-d $coletcdir)) {
|
---|
74 | print $out "exportcol.pl failed: One or more the the following necessary\n";
|
---|
75 | print $out "directories does not exist\n\n";
|
---|
76 | print $out " $colindexdir\n";
|
---|
77 | print $out " $coletcdir\n";
|
---|
78 | }
|
---|
79 |
|
---|
80 | # create exported directory
|
---|
81 | my $topdir = &util::filename_cat ($ENV{'GSDLHOME'}, "tmp", "exported_$collection");
|
---|
82 | &util::mk_all_dir ($topdir);
|
---|
83 | if (!-d $topdir) {
|
---|
84 | print $out "exportcol.pl failed: couldn't create directory $topdir\n";
|
---|
85 | die "\n";
|
---|
86 | }
|
---|
87 |
|
---|
88 | # make other directories (we'll assume that if we created topdir
|
---|
89 | # successfully there'll be no problems creating these)
|
---|
90 | my $gsdldir = &util::filename_cat ($topdir, "gsdl");
|
---|
91 | &util::mk_all_dir ($gsdldir);
|
---|
92 | my $collectdir = &util::filename_cat ($gsdldir, "collect");
|
---|
93 | &util::mk_all_dir ($collectdir);
|
---|
94 | my $etcdir = &util::filename_cat ($gsdldir, "etc");
|
---|
95 | &util::mk_all_dir ($etcdir);
|
---|
96 |
|
---|
97 | # create the install.cfg file
|
---|
98 | my $installcfg = &util::filename_cat ($topdir, "install.cfg");
|
---|
99 | if (!open (INSTALLCFG, ">$installcfg")) {
|
---|
100 | print $out "exportcol.pl failed: Could not create $installcfg\n";
|
---|
101 | die "\n";
|
---|
102 | }
|
---|
103 | print INSTALLCFG "CompanyName:New Zealand Digital Library\n";
|
---|
104 | print INSTALLCFG "CollectionName:$collection\n";
|
---|
105 | print INSTALLCFG "CollectionDirName:$collection\n";
|
---|
106 | print INSTALLCFG "CollectionVersion:1.0\n";
|
---|
107 | print INSTALLCFG "CollectionVolume:1\n";
|
---|
108 | print INSTALLCFG "ProgramGroupName:Greenstone\n";
|
---|
109 | close INSTALLCFG;
|
---|
110 |
|
---|
111 | # create the manifest.cfg file
|
---|
112 | my $manifestcfg = &util::filename_cat ($topdir, "manifest.cfg");
|
---|
113 | if (!open (MANIFESTCFG, ">$manifestcfg")) {
|
---|
114 | print $out "exportcol.pl failed: Could not create $manifestcfg\n";
|
---|
115 | die "\n";
|
---|
116 | }
|
---|
117 | print MANIFESTCFG "all:\n";
|
---|
118 | print MANIFESTCFG " {library} {collection}\n\n";
|
---|
119 | print MANIFESTCFG "library:\n";
|
---|
120 | print MANIFESTCFG " net32 net16 server.exe\n\n";
|
---|
121 | print MANIFESTCFG "database:\n";
|
---|
122 | print MANIFESTCFG ' etc collect\$(COLDIRNAME)\index\text\$(COLDIRNAME).ldb' . "\n\n";
|
---|
123 | print MANIFESTCFG "collection:\n";
|
---|
124 | print MANIFESTCFG " collect etc images macros mappings\n";
|
---|
125 | close MANIFESTCFG;
|
---|
126 |
|
---|
127 | # copy the necessary stuff from GSDLHOME
|
---|
128 | my $imagesdir = &util::filename_cat ($ENV{'GSDLHOME'}, "images");
|
---|
129 | my $macrosdir = &util::filename_cat ($ENV{'GSDLHOME'}, "macros");
|
---|
130 | my $mappingsdir = &util::filename_cat ($ENV{'GSDLHOME'}, "mappings");
|
---|
131 | my $maincfg = &util::filename_cat ($ENV{'GSDLHOME'}, "etc", "main.cfg");
|
---|
132 | my $serverexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "server.exe");
|
---|
133 | my $gssetupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "gssetup.exe");
|
---|
134 | my $setupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "Setup.exe");
|
---|
135 | my $net32dir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "net32");
|
---|
136 | my $net16dir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "net16");
|
---|
137 | my $netscapedir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "netscape");
|
---|
138 | my $win32sdir = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "Win32s");
|
---|
139 |
|
---|
140 | if ((!-d $imagesdir) || (!-d $macrosdir) || (!-d $mappingsdir) || (!-e $maincfg) ||
|
---|
141 | (!-e $serverexe) || (!-e $gssetupexe) || (!-e $setupexe) || (!-d $net32dir) ||
|
---|
142 | (!-d $net16dir) || (!-d $netscapedir) || (!-d $win32sdir)) {
|
---|
143 | print $out "exportcol.pl failed: One or more the the following necessary\n";
|
---|
144 | print $out "files and directories does not exist\n\n";
|
---|
145 | print $out " $imagesdir\n";
|
---|
146 | print $out " $macrosdir\n";
|
---|
147 | print $out " $mappingsdir\n";
|
---|
148 | print $out " $maincfg\n";
|
---|
149 | print $out " $serverexe\n";
|
---|
150 | print $out " $gssetupexe\n";
|
---|
151 | print $out " $setupexe\n";
|
---|
152 | print $out " $net32dir\n";
|
---|
153 | print $out " $net16dir\n";
|
---|
154 | print $out " $netscapedir\n";
|
---|
155 | print $out " $win32sdir\n";
|
---|
156 | die "\n";
|
---|
157 | }
|
---|
158 |
|
---|
159 | &util::cp_r ($imagesdir, $gsdldir);
|
---|
160 | &util::cp_r ($macrosdir, $gsdldir);
|
---|
161 | &util::cp_r ($mappingsdir, $gsdldir);
|
---|
162 | &util::cp ($maincfg, $etcdir);
|
---|
163 | &util::cp ($serverexe, $gsdldir);
|
---|
164 | &util::cp ($gssetupexe, $topdir);
|
---|
165 | &util::cp ($setupexe, $topdir);
|
---|
166 | &util::cp_r ($net32dir, $gsdldir);
|
---|
167 | &util::cp_r ($net16dir, $gsdldir);
|
---|
168 | &util::cp_r ($netscapedir, $topdir);
|
---|
169 | &util::cp_r ($win32sdir, $topdir);
|
---|
170 |
|
---|
171 | # copy the collection itself
|
---|
172 | my $thiscoldir = &util::filename_cat ($collectdir, $collection);
|
---|
173 | &util::mk_all_dir ($thiscoldir);
|
---|
174 | &util::cp_r ($colindexdir, $thiscoldir);
|
---|
175 | &util::cp_r ($coletcdir, $thiscoldir);
|
---|
176 | &util::cp_r ($colimagesdir, $thiscoldir) if (-e $colimagesdir);
|
---|
177 |
|
---|
178 | print $out "exportcol.pl succeeded: The exported collection is in $topdir\n";
|
---|
179 | close OUT if $close_out;
|
---|
180 | }
|
---|