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

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

tidied up mkcol.pl's help text

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