source: trunk/gsdl3/bin/script/gs2_mkcol.pl@ 3688

Last change on this file since 3688 was 3688, checked in by kjdon, 21 years ago

gs2 compatible building/conversion scripts

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.6 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# gs2_mkcol.pl -- create the framework for a gs2 compatible collection in
6# gs3
7# A component of the Greenstone digital library software
8# from the New Zealand Digital Library Project at the
9# University of Waikato, New Zealand.
10#
11# Copyright (C) 1999 New Zealand Digital Library Project
12#
13# This program is free software; you can redistribute it and/or modify
14# it under the terms of the GNU General Public License as published by
15# the Free Software Foundation; either version 2 of the License, or
16# (at your option) any later version.
17#
18# This program is distributed in the hope that it will be useful,
19# but WITHOUT ANY WARRANTY; without even the implied warranty of
20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21# GNU General Public License for more details.
22#
23# You should have received a copy of the GNU General Public License
24# along with this program; if not, write to the Free Software
25# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26#
27###########################################################################
28
29
30# This program will setup a new collection from a model one. It does this by
31# copying the model, moving files to have the correct names, and replacing
32# text within the files to match the parameters.
33
34package gs2_mkcol;
35
36BEGIN {
37 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
38 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
39 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
40}
41
42use parsargv;
43use util;
44use cfgread;
45
46sub print_usage {
47 print STDOUT "\n";
48 print STDOUT "gs2_mkcol.pl: Creates the directory structure for a new\n";
49 print STDOUT " Greenstone2 compatible collection in Greenstone3.\n\n";
50 print STDOUT " usage: $0 -site site-home -creator email [options] collection-name\n\n";
51 print STDOUT " options:\n";
52 print STDOUT " -optionfile file Get options from file, useful on systems where\n";
53 print STDOUT " long command lines may cause problems\n";
54 print STDOUT " -collectdir Directory where new collection will be created.\n";
55 print STDOUT " Default is " .
56 &util::filename_cat("site-home", "collect") . "\n";
57 print STDOUT " -maintainer email The collection maintainer's email address (if\n";
58 print STDOUT " different from the creator)\n";
59 print STDOUT " -public true|false If this collection has anonymous access\n";
60 print STDOUT " -title text The title for the collection\n";
61 print STDOUT " -about text The about text for the collection\n";
62 print STDOUT " -plugin text perl plugin module to use (there may be multiple\n";
63 print STDOUT " plugin entries)\n";
64 print STDOUT " -quiet Operate quietly\n";
65 print STDOUT " Note that -creator and -site must be specified. You can make changes to all\n";
66 print STDOUT " options later by editing the collect.cfg configuration file for your\n";
67 print STDOUT " new collection (it'll be in the \"etc\" directory).\n\n";
68 print STDOUT " [Type \"perl -S mkcol.pl | more\" if this help text scrolled off your screen]";
69 print STDOUT "\n" unless $ENV{'GSDLOS'} =~ /^windows$/i;
70}
71
72sub traverse_dir
73{
74 my ($modeldir, $coldir) = @_;
75 my ($newfile, @filetext);
76
77 if (!(-e $coldir)) {
78
79 my $store_umask = umask(0002);
80 my $mkdir_ok = mkdir ($coldir, 0777);
81 umask($store_umask);
82
83 if (!$mkdir_ok)
84 {
85 die "$!";
86 }
87 }
88
89 opendir(DIR, $modeldir) || die "Can't read $modeldir";
90 my @files = grep(!/^(\.\.?|CVS)$/, readdir(DIR));
91 closedir(DIR);
92
93 foreach $file (@files)
94 {
95 my $thisfile = &util::filename_cat ($modeldir, $file);
96 if (-d $thisfile) {
97 my $colfiledir = &util::filename_cat ($coldir, $file);
98 traverse_dir ($thisfile, $colfiledir);
99
100 } else {
101 my $destfile = $file;
102 $destfile =~ s/^modelcol/$collection/;
103 $destfile =~ s/^MODELCOL/$capcollection/;
104 print STDOUT " doing replacements for $destfile\n" unless $quiet;
105 $destfile = &util::filename_cat ($coldir, $destfile);
106
107 open (INFILE, $thisfile) ||
108 die "ERROR: Can't read file $thisfile";
109 open (OUTFILE, ">$destfile") ||
110 die "ERROR: Can't create file $destfile";
111
112 while (defined ($line = <INFILE>)) {
113 $line =~ s/\*\*collection\*\*/$collection/g;
114 $line =~ s/\*\*COLLECTION\*\*/$capcollection/g;
115 $line =~ s/\*\*creator\*\*/$creator/g;
116 $line =~ s/\*\*maintainer\*\*/$maintainer/g;
117 $line =~ s/\*\*public\*\*/$public/g;
118 $line =~ s/\*\*title\*\*/$title/g;
119 $line =~ s/\*\*about\*\*/$about/g;
120 $line =~ s/\*\*plugins\*\*/$pluginstring/g;
121
122 print OUTFILE $line;
123 }
124
125 close (OUTFILE);
126 close (INFILE);
127 }
128 }
129}
130
131# get and check options
132sub parse_args {
133 my ($argref) = @_;
134 if (!&parsargv::parse($argref,
135 'optionfile/.*/', \$optionfile,
136 'collectdir/.*/', \$collectdir,
137 'site/.*/', \$sitehome,
138 'creator/\w+\@[\w\.]+/', \$creator,
139 'maintainer/\w+\@[\w\.]+/', \$maintainer,
140 'public/true|false/true', \$public,
141 'title/.+/', \$title,
142 'about/.+/', \$about,
143 'plugin/.+', \@plugin,
144 'quiet', \$quiet,
145 )) {
146 &print_usage();
147 die "\n";
148 }
149}
150
151sub main {
152
153 &parse_args (\@ARGV);
154 if ($optionfile =~ /\w/) {
155 open (OPTIONS, $optionfile) || die "Couldn't open $optionfile\n";
156 my $line = [];
157 my $options = [];
158 while (defined ($line = &cfgread::read_cfg_line ('mkcol::OPTIONS'))) {
159 push (@$options, @$line);
160 }
161 close OPTIONS;
162 &parse_args ($options);
163
164 }
165
166 # load default plugins if none were on command line
167 if (!scalar(@plugin)) {
168 @plugin = (ZIPPlug,GAPlug,TEXTPlug,HTMLPlug,EMAILPlug,
169 PDFPlug,RTFPlug,WordPlug,PSPlug,ArcPlug,RecPlug);
170 }
171
172 # get and check the collection name
173 ($collection) = @ARGV;
174 if (!defined($collection)) {
175 print STDOUT "ERROR: no collection name was specified\n";
176 &print_usage();
177 die "\n";
178 }
179
180 if (length($collection) > 8) {
181 print STDOUT "ERROR: The collection name must be less than 8 characters\n";
182 print STDOUT " so compatibility with earlier filesystems can be\n";
183 print STDOUT " maintained.\n";
184 die "\n";
185 }
186
187 if ($collection eq "gs2model" || $collection eq "gs3model") {
188 print STDOUT "ERROR: No collection can be named gs2model or gs3model as these are the\n";
189 print STDOUT " names of the model collections.\n";
190 die "\n";
191 }
192
193 if ($collection eq "CVS") {
194 print STDOUT "ERROR: No collection can be named CVS as this may interfere\n";
195 print STDOUT " with directories created by the CVS versioning system\n";
196 die "\n";
197 }
198
199 #check that -site has been specified
200 if (!defined($sitehome) || $sitehome eq "") {
201 print STDOUT "ERROR: The site was not defined. This variable is\n";
202 print STDOUT " needed to locate the collect directory.\n";
203 die "\n";
204 }
205 #check that its a valid directory
206 if (!-d $sitehome) {
207 print STDOUT "ERROR: $sitehome doesn't exist\n";
208 die "\n";
209 }
210 if (!defined($creator) || $creator eq "") {
211 print STDOUT "ERROR: The creator was not defined. This variable is\n";
212 print STDOUT " needed to recognise duplicate collection names.\n";
213 die "\n";
214 }
215
216 if (!defined($maintainer) || $maintainer eq "") {
217 $maintainer = $creator;
218 }
219
220 $public = "true" unless defined $public;
221
222 if (!defined($title) || $title eq "") {
223 $title = $collection;
224 }
225
226 # get capitalised version of the collection
227 $capcollection = $collection;
228 $capcollection =~ tr/a-z/A-Z/;
229
230 # get the strings to include.
231 $pluginstring = "";
232 foreach $plugin (@plugin) {
233 if ($plugin eq RecPlug) {
234 $pluginstring .= "plugin $plugin -use_metadata_files\n";
235 } else {
236 $pluginstring .= "plugin $plugin\n";
237 }
238 }
239
240 $mdir = &util::filename_cat ($sitehome, "collect", "gs2model");
241
242 if (defined $collectdir && $collectdir =~ /\w/) {
243 if (!-d $collectdir) {
244 print STDOUT "ERROR: $collectdir doesn't exist\n";
245 die "\n";
246 }
247 $cdir = &util::filename_cat ($collectdir, $collection);
248 } else {
249 $cdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
250 }
251
252 # make sure the model collection exists
253 die "ERROR: Cannot find the model collection $mdir" unless (-d $mdir);
254
255 # make sure this collection does not already exist
256 if (-e $cdir) {
257 print STDOUT "ERROR: This collection already exists\n";
258 die "\n";
259 }
260
261 # start creating the collection
262 print STDOUT "\nCreating the collection $collection...\n" unless $quiet;
263 &traverse_dir ($mdir, $cdir);
264 print STDOUT "\nThe new collection was created successfully at\n" unless $quiet;
265 print STDOUT "$cdir\n" unless $quiet;
266}
267
268&main ();
Note: See TracBrowser for help on using the repository browser.