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

Last change on this file since 1031 was 1031, checked in by nzdl, 24 years ago

point perl at /usr/bin/perl by default

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.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
33BEGIN {
34 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
35 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
36}
37
38use parsargv;
39
40sub print_usage {
41 print STDERR "\n usage: $0 [options] collection-name\n\n";
42 print STDERR " options:\n";
43 print STDERR " -creator email Your email address\n";
44 print STDERR " -maintainer email The current maintainer's email address\n";
45 print STDERR " -public true|false If this collection has anonymous access\n";
46 print STDERR " -beta true|false If this collection is still under development\n";
47# print STDERR " -index type The indexes which should be made\n";
48# print STDERR " -indextext name The index description\n";
49# print STDERR " -defaultindex type The index to use if no others are supplied\n";
50
51 print STDERR " -title text The title for the collection\n";
52 print STDERR " -about text The about text for the collection\n";
53 print STDERR " -plugins list Space separated list of perl plugin modules to use\n";
54 print STDERR " -refine list Space separated list of perl plugin modules to use\n";
55
56
57}
58
59sub traverse_dir
60{
61 my ($modeldir, $coldir) = @_;
62 my ($newfile, @filetext);
63
64 if (!(-e $coldir)) {
65
66 my $store_umask = umask(0002);
67 my $mkdir_ok = mkdir ($coldir, 0777);
68 umask($store_umask);
69
70 if (!$mkdir_ok)
71 {
72 die "$!";
73 }
74 }
75
76 opendir(DIR, $modeldir) || die "Can't read $modeldir";
77 my @files = grep(!/^(\.\.?|CVS)$/, readdir(DIR));
78 closedir(DIR);
79
80 foreach $file (@files)
81 {
82 if (-d "$modeldir/$file") {
83 traverse_dir ("$modeldir/$file", "$coldir/$file");
84
85 } else {
86 my $destfile = $file;
87 $destfile =~ s/^\modelcol/$collection/;
88 $destfile =~ s/^\MODELCOL/$capcollection/;
89
90 print STDERR "doing replacements for $modeldir/$file\n";
91 open (INFILE, "$modeldir/$file") ||
92 die "Can't read file $modeldir/$file";
93 open (OUTFILE, ">$coldir/$destfile") ||
94 die "Can't create file $coldir/destfile";
95
96 while (defined ($line = <INFILE>)) {
97 $line =~ s/\*\*collection\*\*/$collection/g;
98 $line =~ s/\*\*COLLECTION\*\*/$capcollection/g;
99 $line =~ s/\*\*creator\*\*/$creator/g;
100 $line =~ s/\*\*maintainer\*\*/$maintainer/g;
101 $line =~ s/\*\*public\*\*/$public/g;
102 $line =~ s/\*\*beta\*\*/$beta/g;
103 $line =~ s/\*\*indexes\*\*/$indexesstr/g;
104 $line =~ s/\*\*indexestext\*\*/$indexestextstr/g;
105 $line =~ s/\*\*defaultindex\*\*/$defaultindex/g;
106 $line =~ s/\*\*title\*\*/$title/g;
107 $line =~ s/\*\*about\*\*/$about/g;
108 $line =~ s/\*\*plugins\*\*/$plugins/g;
109 $line =~ s/\*\*refine\*\*/$refine/g;
110
111 print OUTFILE $line;
112 }
113
114 close (OUTFILE);
115 close (INFILE);
116 }
117 }
118}
119
120
121my (@indexes, @indexestext);
122
123# get and check options
124if (!&parsargv::parse(\@ARGV,
125 'creator/\w+\@[\w\.]+/', \$creator,
126 'maintainer/\w+\@[\w\.]+/', \$maintainer,
127 'public/true|false/true', \$public,
128 'beta/true|false/true', \$beta,
129 'index/.*/document:all', \@indexes,
130 'indextext/\.*/Terms must appear within the same document', \@indexestext,
131 'defaultindex/.*/document:all', \$defaultindex,
132 'title/.+/', \$title,
133 'about/.+/', \$about,
134 'plugins/.+/GMLPlug TEXTPlug ArcPlug RecPlug/', \$plugins,
135 'refine/.+/', \$refine
136 )) {
137 &print_usage();
138 die "\n";
139}
140
141# get and check the collection name
142($collection) = @ARGV;
143if (!defined($collection)) {
144 &print_usage();
145 die "\n";
146}
147
148if (length($collection) > 8) {
149 print STDERR "The collection name must be less than 8 characters\n";
150 print STDERR "so compatibility with earlier filesystems can be\n";
151 print STDERR "maintained.\n";
152 die "\n";
153}
154
155if ($collection eq "modelcol") {
156 print STDERR "No collection can be named modelcol as this is the\n";
157 print STDERR "name of the model collection.\n";
158 die "\n";
159}
160
161if ($collection eq "CVS") {
162 print STDERR "No collection can be named CVS as this may interfere\n";
163 print STDERR "with directories created by the CVS versioning system\n";
164 die "\n";
165}
166
167if (!defined($creator) || $creator eq "") {
168 print STDERR "The creator was not defined. This variable is\n";
169 print STDERR "needed to recognise duplicate collection names.\n";
170 die "\n";
171}
172
173if (!defined($maintainer) || $maintainer eq "") {
174 $maintainer = $creator;
175}
176
177$public = "true" unless defined $public;
178$beta = "true" unless defined $beta;
179
180
181if (!defined($title) || $title eq "") {
182 $title = $collection;
183}
184
185# get capitalised version of the collection
186$capcollection = $collection;
187$capcollection =~ tr/a-z/A-Z/;
188
189
190# get the strings to include.
191$indexesstr = join ("\t", @indexes);
192$indexestextstr = "";
193for ($i=0; $i<scalar(@indexestext); $i++) {
194 $indexestextstr .= "_$indexes[$i]_[] {$indexestext[$i]}\n";
195}
196
197
198# make sure the model collection exists
199die "Cannot find the model collection $ENV{'GSDLHOME'}/collect/modelcol" unless
200 (-d "$ENV{'GSDLHOME'}/collect/modelcol");
201
202# make sure this collection does not already exist
203if (-e "$ENV{'GSDLHOME'}/collect/$collection") {
204 print STDERR "This collection already exists\n";
205 die "\n";
206}
207
208
209# start creating the collection
210print STDERR "Creating the collection $collection\n\n";
211&traverse_dir ("$ENV{'GSDLHOME'}/collect/modelcol", "$ENV{'GSDLHOME'}/collect/$collection");
212print STDERR "\n\nThe new collection is in $ENV{'GSDLHOME'}/collect/$collection.\n\n";
213
214
Note: See TracBrowser for help on using the repository browser.