Project

General

Profile

1 2172 sgarg
2
#!/usr/bin/perl
3
#
4
#  '$RCSfile$'
5
#  Copyright: 2000 Regents of the University of California
6
#
7
#   '$Author$'
8
#     '$Date$'
9
# '$Revision$'
10
#
11
# This program is free software; you can redistribute it and/or modify
12
# it under the terms of the GNU General Public License as published by
13
# the Free Software Foundation; either version 2 of the License, or
14
# (at your option) any later version.
15
#
16
# This program is distributed in the hope that it will be useful,
17
# but WITHOUT ANY WARRANTY; without even the implied warranty of
18
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
# GNU General Public License for more details.
20
#
21
# You should have received a copy of the GNU General Public License
22
# along with this program; if not, write to the Free Software
23
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24
#
25
#
26
# This is a CGI application for inserting metadata documents into
27
# the Metacat database.  It utilizes the Metacat.pm module for most work.
28
# You can specify two metacats and a list of documents. This script will
29
# copy documents from one metacat to another.
30
31
# read variables from registry.cfg
32
33
use File::Copy;
34
use IO::File;
35
use strict;
36
37
my $scope     = readReqdParam("Enter the scope name:");
38
my $org       = readReqdParam("Enter the organization name:");
39
my $orgabbrev = readReqdParam("Enter the organization abbreviation:");
40
my $orgurl    = readReqdParam("Enter the organization URL:");
41
42
my $username  = readParam("Enter the username:", "uid=".$scope."admin,o=".$orgabbrev.",dc=ecoinformatics,dc=org");
43
my $password  = readParam("Enter the password:", "");
44
my $mailhost  = readParam("Enter the mailhost name:", "hyperion.nceas.ucsb.edu");
45
my $adminName  = readParam("Enter the Administrator's name:", "adminName");
46
my $adminEmail  = readParam("Enter the administrator's email address:", "email\@admin");
47
my $senderEmail  = readParam("Enter the sender's email address:", "registry\@$org");
48
my $debugLevel  = readParam("Enter the debug level:", "0");
49
50
my $hasKeyword  = readParam("Do you want to add keywords to this skin [Yes/No]:", "Yes");
51
my $hasMethod  = readParam("Do you want to add methods to this skin [Yes/No]:", "Yes");
52
my $hasSpatial  = readParam("Do you want to add spatial coverage to this skin [Yes/No]:", "Yes");
53
my $hasTemporal  = readParam("Do you want to add temporal coverage in this skin [Yes/No]:", "Yes");
54
my $hasTaxonomic  = readParam("Do you want to see taxonomic coverage in this skin [Yes/No]:", "Yes");
55
56
57
mkdir "../../../lib/style/skins/$scope", 0744;
58
59
writeConfigFile();
60
copyFile('searchform.html');
61
copyFile('index.html');
62
copyFile('header.html');
63
copyAndRenameFile('xml');
64
copyAndRenameFile('css');
65
copyAndRenameFile('js');
66
67
sub readParam{
68
    my $printString = shift;
69
    my $defaultValue = shift;
70
71
    print "$printString [$defaultValue]\n";
72
    my $returnVal = <>;
73
    chomp $returnVal;
74
75
    if($returnVal eq ""){
76
	$returnVal = $defaultValue;
77
    }
78
79
    return $returnVal;
80
}
81
82
83
sub readReqdParam{
84
    my $printString = shift;
85
86
    print "$printString\n";
87
    my $returnVal = <>;
88
    chomp $returnVal;
89
90
    while($returnVal eq ""){
91
	print "This value is required. $printString\n";
92
	$returnVal = <>;
93
	chomp $returnVal;
94
    }
95
96
    return $returnVal;
97
}
98
99
sub writeConfigFile{
100
101
    my $configText = "";
102
103
    $configText .= "#"."\n";
104
    $configText .= "# General configuration parameters"."\n";
105
    $configText .= "#"."\n";
106
    $configText .= "metacatUrl = http://\@server\@\@servlet-path\@"."\n";
107
    $configText .= "username = ".$username."\n";
108
    $configText .= "password = ".$password."\n";
109
    $configText .= "ldapUrl = \@ldapUrl\@"."\n";
110
    $configText .= "defaultScope = $scope"."\n";
111
    $configText .= "organization = $org"."\n";
112
    $configText .= "orgabbrev = $orgabbrev"."\n";
113
    $configText .= "orgurl = $orgurl"."\n";
114
    $configText .= "responseTemplate = \@responseForm\@"."\n";
115
    $configText .= "entryFormTemplate = \@entryForm\@"."\n";
116
    $configText .= "guideTemplate = \@guide\@"."\n";
117
    $configText .= "confirmDataTemplate = \@confirmData\@"."\n";
118
    $configText .= "deleteDataTemplate = \@deleteData\@"."\n";
119
120
    if($hasKeyword ne "Yes" && $hasKeyword ne "yes"){
121
	$configText .= "hasKeyword = false"."\n";
122
    }
123
124
    if($hasMethod ne "Yes" && $hasMethod ne "yes"){
125
	$configText .= "hasMethod = false"."\n";
126
    }
127
128
    if($hasSpatial ne "Yes" && $hasSpatial ne "yes"){
129
	$configText .= "hasSpatial = false"."\n";
130
    } else {
131
	my $spatialRequired  = readParam("Do you want to make spatial coverage required [Yes/No]:", "Yes");
132
	if($spatialRequired ne "Yes" && $spatialRequired ne "yes"){
133
	    $configText .= "spatialRequired = false"."\n";
134
	}
135
    }
136
137
    if($hasTaxonomic ne "Yes" && $hasTaxonomic ne "yes"){
138
	$configText .= "hasTaxonomic = false"."\n";
139
    }
140
141
    if($hasTemporal ne "Yes" && $hasTemporal ne "yes"){
142
	$configText .= "hasTemporal = false"."\n";
143
    } else {
144
	my $temporalRequired  = readParam("Do you want to make temporal coverage required [Yes/No]:", "Yes");
145
	if($temporalRequired ne "Yes" && $temporalRequired ne "yes"){
146
	    $configText .= "temporalRequired = false"."\n";
147
	}
148
    }
149
150
151
    $configText .= "accesspubid = -//ecoinformatics.org//eml-access-2.0.0beta6//EN"."\n";
152
    $configText .= "accesssysid = eml-access.dtd"."\n";
153
    $configText .= "datasetpubid = eml://ecoinformatics.org/eml-dataset-2.0.0"."\n";
154
    $configText .= "datasetsysid = eml-dataset.dtd"."\n";
155
    $configText .= "mailhost = ".$mailhost."\n";
156
    $configText .= "sender = ".$senderEmail."\n";
157
    $configText .= "recipient = ".$adminEmail."\n";
158
    $configText .= "adminname = ".$adminName."\n";
159
    $configText .= "debug = ".$debugLevel."\n";
160 2800 sgarg
    $configText .= "contactEmailAddressRequired = 'false'\n";
161
    $configText .= "adminIsDocOwner = 'false'\n";
162 2172 sgarg
    $configText .= "#"."\n";
163
    $configText .= "# These are the sites and their coordinates. Coordinates are in"."\n";
164
    $configText .= "# degrees:minutes:seconds:direction format"."\n";
165
    $configText .= "# Make sure there is a lat/lon pair for every site"."\n";
166
    $configText .= "#"."\n";
167
    $configText .= "# example format ..."."\n";
168
    $configText .= "# lat [UK] Harwood forest[Sitka Spruce] = 55:12:46:N"."\n";
169
    $configText .= "# lon [UK] Harwood forest[Sitka Spruce] = 2:2:15:W"."\n";
170
171
172
    #print $configText;
173
174
    my $writefilehandle = new IO::File;
175
    $writefilehandle->open(">../../../lib/style/skins/$scope/$scope.cfg") or die "Could not open ../../../lib/style/skins/$scope/$scope.cfg";
176
    $writefilehandle->write($configText, length($configText));
177
    $writefilehandle->close;
178
}
179
180
sub copyFile{
181
    my $filename = shift;
182
183
    my $readfilehandle = new IO::File;
184
    $readfilehandle->open("<$filename") or die "Could not open $filename";
185
186
    my $text = "";
187
    my $newtext;
188
189
    while ($readfilehandle->read($newtext, 1)){
190
	$text .= $newtext;
191
    }
192
193
    $text =~ s/<\@scope\@>/$scope/g;
194
    $text =~ s/<\@organization\@>/$org/g;
195
    $text =~ s/<\@orgabbrev\@>/$orgabbrev/g;
196
    $text =~ s/<\@orgurl\@>/$orgurl/g;
197
198
    $readfilehandle->close;
199
200
    my $writefilehandle = new IO::File;
201
    $writefilehandle->open(">../../../lib/style/skins/$scope/$filename") or die "Could not open $filename";
202
    $writefilehandle->write($text, length($text));
203
    $readfilehandle->close;
204
    $writefilehandle->close;
205
}
206
207
208
sub copyAndRenameFile{
209
    my $ext = shift;
210
211
    my $readfilehandle = new IO::File;
212
    $readfilehandle->open("<scope.$ext") or die "Could not open scope.$ext";
213
214
    my $text = "";
215
    my $newtext;
216
217
    while ($readfilehandle->read($newtext, 1)){
218
	$text .= $newtext;
219
    }
220
221
    $text =~ s/<\@scope\@>/$scope/g;
222
    $text =~ s/<\@organization\@>/$org/g;
223
    $text =~ s/<\@orgabbrev\@>/$orgabbrev/g;
224
    $text =~ s/<\@orgurl\@>/$orgurl/g;
225
226
    $readfilehandle->close;
227
228
    my $writefilehandle = new IO::File;
229
    $writefilehandle->open(">../../../lib/style/skins/$scope/$scope.$ext") or die "Could not open ../../../lib/style/skins/$scope/$scope.$ext";
230
    $writefilehandle->write($text, length($text));
231
    $readfilehandle->close;
232
    $writefilehandle->close;
233
}