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
    $configText .= "#"."\n";
161
    $configText .= "# These are the sites and their coordinates. Coordinates are in"."\n";
162
    $configText .= "# degrees:minutes:seconds:direction format"."\n";
163
    $configText .= "# Make sure there is a lat/lon pair for every site"."\n";
164
    $configText .= "#"."\n";
165
    $configText .= "# example format ..."."\n";
166
    $configText .= "# lat [UK] Harwood forest[Sitka Spruce] = 55:12:46:N"."\n";
167
    $configText .= "# lon [UK] Harwood forest[Sitka Spruce] = 2:2:15:W"."\n";
168
169
170
    #print $configText;
171
172
    my $writefilehandle = new IO::File;
173
    $writefilehandle->open(">../../../lib/style/skins/$scope/$scope.cfg") or die "Could not open ../../../lib/style/skins/$scope/$scope.cfg";
174
    $writefilehandle->write($configText, length($configText));
175
    $writefilehandle->close;
176
}
177
178
sub copyFile{
179
    my $filename = shift;
180
181
    my $readfilehandle = new IO::File;
182
    $readfilehandle->open("<$filename") or die "Could not open $filename";
183
184
    my $text = "";
185
    my $newtext;
186
187
    while ($readfilehandle->read($newtext, 1)){
188
	$text .= $newtext;
189
    }
190
191
    $text =~ s/<\@scope\@>/$scope/g;
192
    $text =~ s/<\@organization\@>/$org/g;
193
    $text =~ s/<\@orgabbrev\@>/$orgabbrev/g;
194
    $text =~ s/<\@orgurl\@>/$orgurl/g;
195
196
    $readfilehandle->close;
197
198
    my $writefilehandle = new IO::File;
199
    $writefilehandle->open(">../../../lib/style/skins/$scope/$filename") or die "Could not open $filename";
200
    $writefilehandle->write($text, length($text));
201
    $readfilehandle->close;
202
    $writefilehandle->close;
203
}
204
205
206
sub copyAndRenameFile{
207
    my $ext = shift;
208
209
    my $readfilehandle = new IO::File;
210
    $readfilehandle->open("<scope.$ext") or die "Could not open scope.$ext";
211
212
    my $text = "";
213
    my $newtext;
214
215
    while ($readfilehandle->read($newtext, 1)){
216
	$text .= $newtext;
217
    }
218
219
    $text =~ s/<\@scope\@>/$scope/g;
220
    $text =~ s/<\@organization\@>/$org/g;
221
    $text =~ s/<\@orgabbrev\@>/$orgabbrev/g;
222
    $text =~ s/<\@orgurl\@>/$orgurl/g;
223
224
    $readfilehandle->close;
225
226
    my $writefilehandle = new IO::File;
227
    $writefilehandle->open(">../../../lib/style/skins/$scope/$scope.$ext") or die "Could not open ../../../lib/style/skins/$scope/$scope.$ext";
228
    $writefilehandle->write($text, length($text));
229
    $readfilehandle->close;
230
    $writefilehandle->close;
231
}