source: trunk/gsdl/bin/script/mkcol.pl@ 2431

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

* empty log message *

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# mkcol.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
29# This program will setup a new collection from a model one. It does this by
30# copying the model, moving files to have the correct names, and replacing
31# text within the files to match the parameters.
32
33package mkcol;
34
35BEGIN {
36 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
37 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
38 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
39}
40
41use parsargv;
42use util;
43use cfgread;
44
45sub print_usage {
46 print STDOUT "\n";
47 print STDOUT "mkcol.pl: Creates the directory structure for a new\n";
48 print STDOUT " Greenstone collection.\n\n";
49 print STDOUT " usage: $0 -creator email [options] collection-name\n\n";
50 print STDOUT " options:\n";
51 print STDOUT " -optionfile file Get options from file, useful on systems where\n";
52 print STDOUT " long command lines may cause problems\n";
53 print STDOUT " -collectdir Directory where new collection will be created.\n";
54 print STDOUT " Default is " .
55 &util::filename_cat($ENV{'GSDLHOME'}, "collect") . "\n";
56 print STDOUT " -maintainer email The collection maintainer's email address (if\n";
57 print STDOUT " different from the creator)\n";
58 print STDOUT " -public true|false If this collection has anonymous access\n";
59 print STDOUT " -beta true|false If this collection is still under development\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 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 $destfile = &util::filename_cat ($coldir, $destfile);
105
106 print STDOUT "doing replacements for $thisfile\n" unless $quiet;
107 open (INFILE, $thisfile) ||
108 die "Can't read file $thisfile";
109 open (OUTFILE, ">$destfile") ||
110 die "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/\*\*beta\*\*/$beta/g;
119 $line =~ s/\*\*title\*\*/$title/g;
120 $line =~ s/\*\*about\*\*/$about/g;
121 $line =~ s/\*\*plugins\*\*/$pluginstring/g;
122
123 print OUTFILE $line;
124 }
125
126 close (OUTFILE);
127 close (INFILE);
128 }
129 }
130}
131
132# get and check options
133sub parse_args {
134 my ($argref) = @_;
135 if (!&parsargv::parse($argref,
136 'optionfile/.*/', \$optionfile,
137 'collectdir/.*/', \$collectdir,
138 'creator/\w+\@[\w\.]+/', \$creator,
139 'maintainer/\w+\@[\w\.]+/', \$maintainer,
140 'public/true|false/true', \$public,
141 'beta/true|false/true', \$beta,
142 'title/.+/', \$title,
143 'about/.+/', \$about,
144 'plugin/.+', \@plugin,
145 'quiet', \$quiet,
146 )) {
147 &print_usage();
148 die "\n";
149 }
150}
151
152sub main {
153
154 &parse_args (\@ARGV);
155 if ($optionfile =~ /\w/) {
156 open (OPTIONS, $optionfile) || die "Couldn't open $optionfile\n";
157 my $line = [];
158 my $options = [];
159 while (defined ($line = &cfgread::read_cfg_line ('mkcol::OPTIONS'))) {
160 push (@$options, @$line);
161 }
162 close OPTIONS;
163 &parse_args ($options);
164
165 }
166
167 # load default plugins if none were on command line
168 if (!scalar(@plugin)) {
169 @plugin = (ZIPPlug,GMLPlug,TEXTPlug,HTMLPlug,EMAILPlug,PDFPlug,WordPlug,ArcPlug,RecPlug);
170 }
171
172 # get and check the collection name
173 ($collection) = @ARGV;
174 if (!defined($collection)) {
175 print STDOUT "no collection name was specified\n";
176 &print_usage();
177 die "\n";
178 }
179
180 if (length($collection) > 8) {
181 print STDOUT "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 "modelcol") {
188 print STDOUT "No collection can be named modelcol as this is the\n";
189 print STDOUT "name of the model collection.\n";
190 die "\n";
191 }
192
193 if ($collection eq "CVS") {
194 print STDOUT "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 if (!defined($creator) || $creator eq "") {
200 print STDOUT "The creator was not defined. This variable is\n";
201 print STDOUT "needed to recognise duplicate collection names.\n";
202 die "\n";
203 }
204
205 if (!defined($maintainer) || $maintainer eq "") {
206 $maintainer = $creator;
207 }
208
209 $public = "true" unless defined $public;
210 $beta = "true" unless defined $beta;
211
212 if (!defined($title) || $title eq "") {
213 $title = $collection;
214 }
215
216 # get capitalised version of the collection
217 $capcollection = $collection;
218 $capcollection =~ tr/a-z/A-Z/;
219
220 # get the strings to include.
221 $pluginstring = "";
222 foreach $plugin (@plugin) {
223 $pluginstring .= "plugin $plugin\n";
224 }
225
226 $mdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", "modelcol");
227 if (defined $collectdir && $collectdir =~ /\w/) {
228 if (!-d $collectdir) {
229 print STDOUT "ERROR: $collectdir doesn't exist\n";
230 die "\n";
231 }
232 $cdir = &util::filename_cat ($collectdir, $collection);
233 } else {
234 $cdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
235 }
236
237 # make sure the model collection exists
238 die "Cannot find the model collection $mdir" unless (-d $mdir);
239
240 # make sure this collection does not already exist
241 if (-e $cdir) {
242 print STDOUT "This collection already exists\n";
243 die "\n";
244 }
245
246 # start creating the collection
247 print STDOUT "Creating the collection $collection\n" unless $quiet;
248 &traverse_dir ($mdir, $cdir);
249 print STDOUT "The new collection is in $cdir.\n" unless $quiet;
250}
251
252&main ();
Note: See TracBrowser for help on using the repository browser.