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