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

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

PSPlug now included in default collection configuration

  • 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 " -title text The title for the collection\n";
60 print STDOUT " -about text The about text for the collection\n";
61 print STDOUT " -plugin text perl plugin module to use (there may be multiple\n";
62 print STDOUT " plugin entries)\n";
63 print STDOUT " -quiet Operate quietly\n";
64 print STDOUT " Note that -creator must be specified. You can make changes to all\n";
65 print STDOUT " options later by editing the collect.cfg configuration file for your\n";
66 print STDOUT " new collection (it'll be in the \"etc\" directory).\n\n";
67 print STDOUT " [Type \"perl -S mkcol.pl | more\" if this help text scrolled off your screen]";
68 print STDOUT "\n" unless $ENV{'GSDLOS'} =~ /^windows$/i;
69}
70
71sub traverse_dir
72{
73 my ($modeldir, $coldir) = @_;
74 my ($newfile, @filetext);
75
76 if (!(-e $coldir)) {
77
78 my $store_umask = umask(0002);
79 my $mkdir_ok = mkdir ($coldir, 0777);
80 umask($store_umask);
81
82 if (!$mkdir_ok)
83 {
84 die "$!";
85 }
86 }
87
88 opendir(DIR, $modeldir) || die "Can't read $modeldir";
89 my @files = grep(!/^(\.\.?|CVS)$/, readdir(DIR));
90 closedir(DIR);
91
92 foreach $file (@files)
93 {
94 my $thisfile = &util::filename_cat ($modeldir, $file);
95 if (-d $thisfile) {
96 my $colfiledir = &util::filename_cat ($coldir, $file);
97 traverse_dir ($thisfile, $colfiledir);
98
99 } else {
100 my $destfile = $file;
101 $destfile =~ s/^modelcol/$collection/;
102 $destfile =~ s/^MODELCOL/$capcollection/;
103 print STDOUT " doing replacements for $destfile\n" unless $quiet;
104 $destfile = &util::filename_cat ($coldir, $destfile);
105
106 open (INFILE, $thisfile) ||
107 die "ERROR: Can't read file $thisfile";
108 open (OUTFILE, ">$destfile") ||
109 die "ERROR: Can't create file $destfile";
110
111 while (defined ($line = <INFILE>)) {
112 $line =~ s/\*\*collection\*\*/$collection/g;
113 $line =~ s/\*\*COLLECTION\*\*/$capcollection/g;
114 $line =~ s/\*\*creator\*\*/$creator/g;
115 $line =~ s/\*\*maintainer\*\*/$maintainer/g;
116 $line =~ s/\*\*public\*\*/$public/g;
117 $line =~ s/\*\*title\*\*/$title/g;
118 $line =~ s/\*\*about\*\*/$about/g;
119 $line =~ s/\*\*plugins\*\*/$pluginstring/g;
120
121 print OUTFILE $line;
122 }
123
124 close (OUTFILE);
125 close (INFILE);
126 }
127 }
128}
129
130# get and check options
131sub parse_args {
132 my ($argref) = @_;
133 if (!&parsargv::parse($argref,
134 'optionfile/.*/', \$optionfile,
135 'collectdir/.*/', \$collectdir,
136 'creator/\w+\@[\w\.]+/', \$creator,
137 'maintainer/\w+\@[\w\.]+/', \$maintainer,
138 'public/true|false/true', \$public,
139 'title/.+/', \$title,
140 'about/.+/', \$about,
141 'plugin/.+', \@plugin,
142 'quiet', \$quiet,
143 )) {
144 &print_usage();
145 die "\n";
146 }
147}
148
149sub main {
150
151 &parse_args (\@ARGV);
152 if ($optionfile =~ /\w/) {
153 open (OPTIONS, $optionfile) || die "Couldn't open $optionfile\n";
154 my $line = [];
155 my $options = [];
156 while (defined ($line = &cfgread::read_cfg_line ('mkcol::OPTIONS'))) {
157 push (@$options, @$line);
158 }
159 close OPTIONS;
160 &parse_args ($options);
161
162 }
163
164 # load default plugins if none were on command line
165 if (!scalar(@plugin)) {
166 @plugin = (ZIPPlug,GMLPlug,TEXTPlug,HTMLPlug,EMAILPlug,
167 PDFPlug,RTFPlug,WordPlug,PSPlug,ArcPlug,RecPlug);
168 }
169
170 # get and check the collection name
171 ($collection) = @ARGV;
172 if (!defined($collection)) {
173 print STDOUT "ERROR: no collection name was specified\n";
174 &print_usage();
175 die "\n";
176 }
177
178 if (length($collection) > 8) {
179 print STDOUT "ERROR: The collection name must be less than 8 characters\n";
180 print STDOUT " so compatibility with earlier filesystems can be\n";
181 print STDOUT " maintained.\n";
182 die "\n";
183 }
184
185 if ($collection eq "modelcol") {
186 print STDOUT "ERROR: No collection can be named modelcol as this is the\n";
187 print STDOUT " name of the model collection.\n";
188 die "\n";
189 }
190
191 if ($collection eq "CVS") {
192 print STDOUT "ERROR: No collection can be named CVS as this may interfere\n";
193 print STDOUT " with directories created by the CVS versioning system\n";
194 die "\n";
195 }
196
197 if (!defined($creator) || $creator eq "") {
198 print STDOUT "ERROR: The creator was not defined. This variable is\n";
199 print STDOUT " needed to recognise duplicate collection names.\n";
200 die "\n";
201 }
202
203 if (!defined($maintainer) || $maintainer eq "") {
204 $maintainer = $creator;
205 }
206
207 $public = "true" unless defined $public;
208
209 if (!defined($title) || $title eq "") {
210 $title = $collection;
211 }
212
213 # get capitalised version of the collection
214 $capcollection = $collection;
215 $capcollection =~ tr/a-z/A-Z/;
216
217 # get the strings to include.
218 $pluginstring = "";
219 foreach $plugin (@plugin) {
220 $pluginstring .= "plugin $plugin\n";
221 }
222
223 $mdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", "modelcol");
224 if (defined $collectdir && $collectdir =~ /\w/) {
225 if (!-d $collectdir) {
226 print STDOUT "ERROR: $collectdir doesn't exist\n";
227 die "\n";
228 }
229 $cdir = &util::filename_cat ($collectdir, $collection);
230 } else {
231 $cdir = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
232 }
233
234 # make sure the model collection exists
235 die "ERROR: Cannot find the model collection $mdir" unless (-d $mdir);
236
237 # make sure this collection does not already exist
238 if (-e $cdir) {
239 print STDOUT "ERROR: This collection already exists\n";
240 die "\n";
241 }
242
243 # start creating the collection
244 print STDOUT "\nCreating the collection $collection...\n" unless $quiet;
245 &traverse_dir ($mdir, $cdir);
246 print STDOUT "\nThe new collection was created successfully at\n" unless $quiet;
247 print STDOUT "$cdir\n" unless $quiet;
248}
249
250&main ();
Note: See TracBrowser for help on using the repository browser.