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

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

Added new perl script for use when exporting collections to cd-rom

  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 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 # create exported directory
67 my $topdir = &util::filename_cat ($ENV{'GSDLHOME'}, "tmp", "exported_$collection");
68 &util::mk_all_dir ($topdir);
69 if (!-d $topdir) {
70 print $out "exportcol.pl failed: couldn't create directory $topdir\n";
71 die "\n";
72 }
73
74 # make other directories (we'll assume that if we created topdir
75 # successfully there'll be no problems creating these)
76 my $gsdldir = &util::filename_cat ($topdir, "gsdl");
77 &util::mk_all_dir ($gsdldir);
78 my $collectdir = &util::filename_cat ($gsdldir, "collect");
79 &util::mk_all_dir ($collectdir);
80 my $etcdir = &util::filename_cat ($gsdldir, "etc");
81 &util::mk_all_dir ($etcdir);
82
83 # create the install.cfg file
84 my $installcfg = &util::filename_cat ($topdir, "install.cfg");
85 if (!open (INSTALLCFG, ">$installcfg")) {
86 print $out "exportcol.pl failed: Could not create $installcfg\n";
87 die "\n";
88 }
89 print INSTALLCFG "CompanyName:New Zealand Digital Library\n";
90 print INSTALLCFG "CollectionName:$collection\n";
91 print INSTALLCFG "CollectionDirName:$collection\n";
92 print INSTALLCFG "CollectionVersion:1.0\n";
93 print INSTALLCFG "CollectionVolume:1\n";
94 print INSTALLCFG "ProgramGroupName:Greenstone\n";
95 close INSTALLCFG;
96
97 # create the manifest.cfg file
98 my $manifestcfg = &util::filename_cat ($topdir, "manifest.cfg");
99 if (!open (MANIFESTCFG, ">$manifestcfg")) {
100 print $out "exportcol.pl failed: Could not create $manifestcfg\n";
101 die "\n";
102 }
103 print MANIFESTCFG "all:\n";
104 print MANIFESTCFG " {library} {collection}\n\n";
105 print MANIFESTCFG "library:\n";
106 print MANIFESTCFG " server.exe\n\n";
107 print MANIFESTCFG "database:\n";
108 print MANIFESTCFG ' collect\$(COLDIRNAME)\index\text\$(COLDIRNAME).ldb' . "\n\n";
109 print MANIFESTCFG "collection:\n";
110 print MANIFESTCFG " collect etc images macros mappings\n";
111 close MANIFESTCFG;
112
113 # copy the necessary stuff from GSDLHOME
114 my $imagesdir = &util::filename_cat ($ENV{'GSDLHOME'}, "images");
115 my $macrosdir = &util::filename_cat ($ENV{'GSDLHOME'}, "macros");
116 my $mappingsdir = &util::filename_cat ($ENV{'GSDLHOME'}, "mappings");
117 my $maincfg = &util::filename_cat ($ENV{'GSDLHOME'}, "etc", "main.cfg");
118 my $serverexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "server.exe");
119 my $gssetupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "gssetup.exe");
120 my $setupexe = &util::filename_cat ($ENV{'GSDLHOME'}, "bin", "windows", "Setup.exe");
121
122 if ((!-d $imagesdir) || (!-d $macrosdir) || (!-d $mappingsdir) || (!-e $maincfg) ||
123 (!-e $serverexe) || (!-e $gssetupexe) || (!-e $setupexe)) {
124 print $out "exportcol.pl failed: One or more the the following necessary\n";
125 print $out "files and directories does not exist\n\n";
126 print $out " $imagesdir\n";
127 print $out " $macrosdir\n";
128 print $out " $mappingsdir\n";
129 print $out " $maincfg\n";
130 print $out " $serverexe\n";
131 print $out " $gssetupexe\n";
132 print $out " $setupexe\n";
133 die "\n";
134 }
135
136 &util::cp_r ($imagesdir, $gsdldir);
137 &util::cp_r ($macrosdir, $gsdldir);
138 &util::cp_r ($mappingsdir, $gsdldir);
139 &util::cp ($maincfg, $etcdir);
140 &util::cp ($serverexe, $gsdldir);
141 &util::cp ($gssetupexe, $topdir);
142 &util::cp ($setupexe, $topdir);
143
144 # copy the collection itself
145 &util::cp_r (&util::filename_cat($ENV{'GSDLHOME'}, "collect", $collection), $collectdir);
146
147 print $out "exportcol.pl succeeded: The exported collection is in $topdir\n";
148 close OUT if $close_out;
149}
Note: See TracBrowser for help on using the repository browser.