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

Last change on this file since 2138 was 2138, checked in by sjboddie, 23 years ago

tinkered with the export collection function a little so that it only
exports those parts of a collection that are required at display time

  • Property svn:keywords set to Author Date Id Revision
File size: 6.3 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;
35
36sub 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
46sub 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 " server.exe\n\n";
121 print MANIFESTCFG "database:\n";
122 print MANIFESTCFG ' 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
136 if ((!-d $imagesdir) || (!-d $macrosdir) || (!-d $mappingsdir) || (!-e $maincfg) ||
137 (!-e $serverexe) || (!-e $gssetupexe) || (!-e $setupexe)) {
138 print $out "exportcol.pl failed: One or more the the following necessary\n";
139 print $out "files and directories does not exist\n\n";
140 print $out " $imagesdir\n";
141 print $out " $macrosdir\n";
142 print $out " $mappingsdir\n";
143 print $out " $maincfg\n";
144 print $out " $serverexe\n";
145 print $out " $gssetupexe\n";
146 print $out " $setupexe\n";
147 die "\n";
148 }
149
150 &util::cp_r ($imagesdir, $gsdldir);
151 &util::cp_r ($macrosdir, $gsdldir);
152 &util::cp_r ($mappingsdir, $gsdldir);
153 &util::cp ($maincfg, $etcdir);
154 &util::cp ($serverexe, $gsdldir);
155 &util::cp ($gssetupexe, $topdir);
156 &util::cp ($setupexe, $topdir);
157
158 # copy the collection itself
159 my $thiscoldir = &util::filename_cat ($collectdir, $collection);
160 &util::mk_all_dir ($thiscoldir);
161 &util::cp_r ($colindexdir, $thiscoldir);
162 &util::cp_r ($coletcdir, $thiscoldir);
163 &util::cp_r ($colimagesdir, $thiscoldir) if (-e $colimagesdir);
164
165 print $out "exportcol.pl succeeded: The exported collection is in $topdir\n";
166 close OUT if $close_out;
167}
Note: See TracBrowser for help on using the repository browser.