1 |
williamc |
1.8 |
#!/usr/local/bin/perl5
|
2 |
williamc |
1.1 |
#
|
3 |
|
|
# User Interface
|
4 |
|
|
#
|
5 |
|
|
|
6 |
|
|
$inputcmd=shift;
|
7 |
|
|
$found='false';
|
8 |
|
|
@allowed_commands=qw(project build env install version list arch);
|
9 |
|
|
|
10 |
|
|
foreach $command ( @allowed_commands ) {
|
11 |
|
|
do { &$command; $found='true'; last;} if ( $inputcmd=~/^$command\Z/i);
|
12 |
|
|
}
|
13 |
|
|
|
14 |
|
|
if ( ! ( $found=~/true/ ) ) {
|
15 |
|
|
print "scram help\n--------\n";
|
16 |
|
|
print "Recognised Commands: \n";
|
17 |
|
|
foreach $command ( @allowed_commands ) {
|
18 |
|
|
print " ".$command."\n";
|
19 |
|
|
}
|
20 |
|
|
}
|
21 |
|
|
|
22 |
|
|
sub build {
|
23 |
|
|
# is this a based or free release?
|
24 |
|
|
FullEnvInit();
|
25 |
|
|
use BuildSetup;
|
26 |
williamc |
1.10 |
$ENV{MAKETARGETS}=join ' ',@ARGV;
|
27 |
williamc |
1.1 |
BuildSetup($ENV{THISDIR},@ARGV);
|
28 |
|
|
# system("$ENV{TOOL_HOME}/BuildSetup",$ENV{THISDIR},@ARGV);
|
29 |
|
|
}
|
30 |
|
|
|
31 |
|
|
sub project {
|
32 |
williamc |
1.7 |
# process options
|
33 |
|
|
while ( $ARGV[0]=~"^-" ) {
|
34 |
|
|
if ( (shift @ARGV)=~/-d/ ) { #installation area directory
|
35 |
|
|
chdir $ARGV[0];
|
36 |
|
|
shift @ARGV;
|
37 |
|
|
}
|
38 |
|
|
}
|
39 |
williamc |
1.1 |
my $project=shift @ARGV;
|
40 |
|
|
my $version=shift @ARGV;
|
41 |
|
|
environmentinit();
|
42 |
|
|
use File::Copy;
|
43 |
williamc |
1.2 |
use Utilities::AddDir;
|
44 |
williamc |
1.1 |
|
45 |
|
|
use BootStrapProject;
|
46 |
|
|
# get the bootstrap files downloaded
|
47 |
|
|
BootStrapProject("$project\?\?$version");
|
48 |
|
|
# Go setup the rest of the environement, now we can
|
49 |
|
|
chdir $ENV{LOCALTOP};
|
50 |
|
|
&localtop;
|
51 |
|
|
LoadEnvFile();
|
52 |
|
|
#
|
53 |
|
|
# Now create the directories specified in the interface
|
54 |
|
|
#
|
55 |
|
|
foreach $key ( keys %ENV ) {
|
56 |
|
|
if ( $key=~/^INT/ ) {
|
57 |
williamc |
1.5 |
AddDir::adddir($ENV{$key});
|
58 |
williamc |
1.1 |
}
|
59 |
|
|
}
|
60 |
williamc |
1.6 |
if ( ! -e "$ENV{LOCALTOP}/$ENV{projconfigdir}" ) {
|
61 |
|
|
system("cp", "-r", "$ENV{RELEASETOP}/$ENV{projconfigdir}",
|
62 |
|
|
"$ENV{LOCALTOP}/$ENV{projconfigdir}");
|
63 |
|
|
}
|
64 |
williamc |
1.1 |
use clientfile;
|
65 |
|
|
BuildClientFile( $ENV{SCRAM_ProjReqsDoc} );
|
66 |
williamc |
1.7 |
use Cwd;
|
67 |
|
|
print "Installation Located at:\n".cwd()."\n";
|
68 |
williamc |
1.11 |
ReturnToContinue();
|
69 |
williamc |
1.1 |
}
|
70 |
williamc |
1.7 |
|
71 |
williamc |
1.1 |
sub FullEnvInit {
|
72 |
|
|
environmentinit();
|
73 |
|
|
localtop();
|
74 |
|
|
LoadEnvFile();
|
75 |
|
|
}
|
76 |
|
|
|
77 |
|
|
sub environmentinit {
|
78 |
williamc |
1.2 |
use Utilities::setarchitecture;
|
79 |
williamc |
1.1 |
my $name;
|
80 |
|
|
my $value;
|
81 |
|
|
|
82 |
|
|
$ENV{LatestBuildFile}=""; # stop recursive behaviour in make
|
83 |
williamc |
1.4 |
setarchitecture::setarch();
|
84 |
williamc |
1.1 |
$ENV{INTwork}="tmp/$ENV{SCRAM_ARCH}";
|
85 |
|
|
$ENV{INTlib}="lib/$ENV{SCRAM_ARCH}";
|
86 |
|
|
$ENV{INTsrc}="src";
|
87 |
|
|
$ENV{INTbin}="bin/$ENV{SCRAM_ARCH}";
|
88 |
|
|
$ENV{INTlog}="logs";
|
89 |
|
|
|
90 |
|
|
if ( ! ( exists $ENV{SCRAM_HOME}) ){
|
91 |
williamc |
1.8 |
$ENV{SCRAM_HOME}="/afs/cern.ch/cms/Releases";
|
92 |
williamc |
1.1 |
print "Warning : Environment Variable SCRAM_HOME not set.\n";
|
93 |
|
|
print "Defaulting to $ENV{SCRAM_HOME}\n";
|
94 |
|
|
}
|
95 |
|
|
if ( ! ( exists $ENV{SCRAM_CONFIG} ) ){
|
96 |
williamc |
1.3 |
$ENV{SCRAM_CONFIG}="$ENV{SCRAM_HOME}/configuration";
|
97 |
williamc |
1.1 |
}
|
98 |
|
|
if ( ! ( exists $ENV{TOOL_HOME} ) ){
|
99 |
williamc |
1.4 |
$ENV{TOOL_HOME}="$ENV{SCRAM_HOME}/src";
|
100 |
williamc |
1.1 |
}
|
101 |
|
|
if ( ! ( exists $ENV{SCRAM_LOOKUPDB} ) ){
|
102 |
|
|
$ENV{SCRAM_LOOKUPDB}="$ENV{SCRAM_CONFIG}/project.lookup";
|
103 |
|
|
}
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
sub localtop {
|
107 |
|
|
# find localtop
|
108 |
|
|
use Cwd;
|
109 |
|
|
my $thispath=cwd;
|
110 |
|
|
block: {
|
111 |
|
|
do {
|
112 |
|
|
if ( -e "$thispath/.SCRAM" ) {
|
113 |
|
|
$ENV{LOCALTOP}=$thispath;
|
114 |
|
|
last block;
|
115 |
|
|
}
|
116 |
|
|
} while ( ( $thispath=~s/(.*)\/.*/$1/ )=~/./ );
|
117 |
|
|
if ( ! (defined $ENV{LOCALTOP}) ) {
|
118 |
|
|
print "Unable to locate the top of local release. Exiting\n";
|
119 |
williamc |
1.11 |
ReturnToContinue();
|
120 |
williamc |
1.1 |
}
|
121 |
|
|
} #end block
|
122 |
|
|
($ENV{THISDIR}=cwd)=~s/^$ENV{LOCALTOP}//;
|
123 |
|
|
$ENV{THISDIR}=~s/^\///;
|
124 |
|
|
$ENV{SCRAM_WORKDIR}="$ENV{LOCALTOP}/.SCRAM";
|
125 |
|
|
}
|
126 |
|
|
|
127 |
|
|
sub LoadEnvFile {
|
128 |
|
|
open ( SCRAMENV, "<$ENV{SCRAM_WORKDIR}/Environment" ) ||
|
129 |
|
|
die "Cant find Environment file $!\n";
|
130 |
|
|
while ( <SCRAMENV> ) {
|
131 |
|
|
chomp;
|
132 |
|
|
next if /^#/;
|
133 |
|
|
next if /^\s*$/ ;
|
134 |
|
|
($name, $value)=split /=/;
|
135 |
|
|
eval "\$ENV{${name}}=\"$value\"";
|
136 |
|
|
}
|
137 |
|
|
close SCRAMENV;
|
138 |
|
|
}
|
139 |
|
|
|
140 |
|
|
sub env {
|
141 |
|
|
print "Sorry - Not yet\n";
|
142 |
|
|
}
|
143 |
|
|
|
144 |
|
|
#
|
145 |
|
|
# Create a lookup tag in the site database
|
146 |
|
|
#
|
147 |
|
|
sub install ( $tagname, $version ) {
|
148 |
|
|
my $tagname=shift @ARGV;
|
149 |
|
|
my $version=shift @ARGV;
|
150 |
|
|
|
151 |
|
|
# create database entry
|
152 |
|
|
do { &help_install; } if $tagname=~/help/i;
|
153 |
|
|
&FullEnvInit;
|
154 |
|
|
if ( $version eq "" ) {
|
155 |
|
|
$version=$ENV{SCRAM_PROJVERSION};
|
156 |
|
|
}
|
157 |
|
|
if ( $tagname eq "" ) {
|
158 |
|
|
$tagname=$ENV{SCRAM_PROJECTNAME};
|
159 |
|
|
}
|
160 |
|
|
my $filename="$ENV{SCRAM_CONFIG}/project.lookup";
|
161 |
|
|
my $outfile="$ENV{SCRAM_CONFIG}/project.lookup.tmp";
|
162 |
|
|
open ( LOCALLOOKUPDB, "<$filename" );
|
163 |
|
|
open ( OUTFILE , ">$outfile" );
|
164 |
|
|
while ( <LOCALLOOKUPDB> ) {
|
165 |
|
|
if ( /^$tagname/ ) {
|
166 |
|
|
print "Related tag :".$_."\n";
|
167 |
|
|
if ( /$version/) {
|
168 |
|
|
print "$tagname $version already exists. Overwrite (y/n)\n";
|
169 |
|
|
if ( ! (<STDIN>=~/y/i ) ) {
|
170 |
|
|
print "Aborting install ...\n";
|
171 |
|
|
close OUTFILE;
|
172 |
|
|
close LOCALLOOKUPDB;
|
173 |
|
|
exit 1;
|
174 |
|
|
}
|
175 |
|
|
}
|
176 |
|
|
else {
|
177 |
|
|
print OUTFILE $_;
|
178 |
|
|
}
|
179 |
|
|
}
|
180 |
|
|
else {
|
181 |
|
|
print OUTFILE $_;
|
182 |
|
|
}
|
183 |
|
|
}
|
184 |
|
|
print OUTFILE "$tagname:$version:file:$ENV{LOCALTOP}".
|
185 |
|
|
"/.SCRAM/InstallFile\n";
|
186 |
|
|
close OUTFILE;
|
187 |
|
|
close LOCALLOOKUPDB;
|
188 |
|
|
copy ( "$outfile", "$filename" )
|
189 |
|
|
|| die "Unable to copy $! \n";
|
190 |
|
|
|
191 |
|
|
}
|
192 |
|
|
|
193 |
|
|
sub help_install() {
|
194 |
|
|
|
195 |
|
|
helpheader("install");
|
196 |
|
|
print <<ENDTEXT;
|
197 |
|
|
Associates a label with the current release in the SCRAM database.
|
198 |
|
|
This allows other users to refer to a centrally installed project by
|
199 |
|
|
this label rather than a remote url reference.
|
200 |
|
|
|
201 |
|
|
Usage:
|
202 |
|
|
|
203 |
|
|
scram install [[label] [version]]
|
204 |
|
|
|
205 |
|
|
label : override default label (the project name of the current release)
|
206 |
|
|
version : the version tag of the current release. If version is not
|
207 |
|
|
specified the base release version will be taken by default.
|
208 |
|
|
|
209 |
|
|
ENDTEXT
|
210 |
|
|
exit;
|
211 |
|
|
}
|
212 |
|
|
|
213 |
|
|
sub helpheader ($label) {
|
214 |
|
|
my $label=shift;
|
215 |
|
|
print <<ENDTEXT;
|
216 |
|
|
*************************************************************************
|
217 |
|
|
SCRAM HELP --------- $label
|
218 |
|
|
*************************************************************************
|
219 |
|
|
ENDTEXT
|
220 |
|
|
}
|
221 |
|
|
|
222 |
|
|
sub version {
|
223 |
|
|
print "Scram version : prototype\n";
|
224 |
|
|
}
|
225 |
|
|
|
226 |
|
|
sub list {
|
227 |
|
|
&environmentinit;
|
228 |
|
|
my $filename="$ENV{SCRAM_CONFIG}/project.lookup";
|
229 |
|
|
open ( LOCALLOOKUPDB, "<$filename" );
|
230 |
|
|
print "Installed Projects\n";
|
231 |
|
|
print "------------------\n";
|
232 |
|
|
print "|Project Name | Project Version |\n";
|
233 |
|
|
print "----------------------------------\n";
|
234 |
|
|
while ( <LOCALLOOKUPDB> ) {
|
235 |
|
|
( $name, $version, $type, $url ) = split ":", $_;
|
236 |
|
|
printf "%1s",$name;
|
237 |
|
|
printf "%25s\n",$version;
|
238 |
|
|
printf "--> %25s\n",$type.":".$url;
|
239 |
|
|
}
|
240 |
|
|
close LOCALLOOKUPDB;
|
241 |
|
|
}
|
242 |
|
|
|
243 |
|
|
sub arch {
|
244 |
|
|
&environmentinit();
|
245 |
|
|
print "$ENV{SCRAM_ARCH}\n";
|
246 |
williamc |
1.11 |
}
|
247 |
|
|
|
248 |
|
|
sub ReturnToContinue {
|
249 |
|
|
print "Press RETURN to exit\n";
|
250 |
|
|
$junk=<STDIN>;
|
251 |
williamc |
1.1 |
}
|