1 arta 1.1 #!/usr/bin/perl -w
2
3 # script for synchronizing your CVS working directory with the CVS JSOC module (new tree)
4
5 # must run from root of JSOC tree (not necessarily from $JSOCROOT)
6
7 # run this on each machine to be used.
8 # n02 - for linux_X86_64 machines
9 # n00 - for linux4 machines such as n00, phil, etc.
10 #
11 # n12 formerly used for AMD x86-64 can also be used instead of n02
12 # lws Itaniam processors no longer supported for JSOC
13
14 $JSOCROOT = $ENV{"JSOCROOT"};
15 $CVSLOG = "cvsupdate.log";
16 $CVSSTATUS = "$JSOCROOT/base/util/scripts/cvsstatus.pl";
17
18 my($aidx) = 0;
19 my($arg);
20 my($line);
21 my($synccmd);
22 arta 1.1 my($wdupdate) = 0;
23 my($lwd); # local working directory
24 my($rwd); # remote working directory
25 my($mach);
|
26 arta 1.3 my(@rsp);
|
27 arta 1.1
|
28 arta 1.7 # Each is a hash of hash references. There will be three elements in this hash: one for
29 # the local machine, and one for each of the machines in @machines. For fs2mount, each hash
30 # reference will be populated with mappings from a file system to a mount point.
|
31 arta 1.1 my(%fs2mount);
32 my(%mount2fs);
33
34 my(@machines) =
35 (
36 "n00",
37 "n02"
38 );
39
40 # set up mappings
41 InitMaps();
42
43 while ($arg = shift(@ARGV))
44 {
45 if (-d $arg)
46 {
47 # Script will update working directory - ensure this is an absolute path.
|
48 arta 1.2 # May be a relative path
49 my($lfspath);
|
50 arta 1.1 my($rfspath);
51 my($savedp);
|
52 arta 1.2
|
53 arta 1.3 @rsp = ResolvePath($arg);
54 $lwd = shift(@rsp);
|
55 arta 1.2
56 @rsp = GetFSPath("local", $lwd);
57 $lfspath = shift(@rsp);
58
59 if ($lfspath !~ /:\S+::/)
60 {
61 print STDERR "Path '$lwd' is mounted locally only; bailing.\n";
62 exit(1);
63 }
|
64 arta 1.1
65 foreach $mach (@machines)
66 {
|
67 arta 1.2 # check for existence of mountpath on $mach that points to $lfspath
68 $rwd = GetMountPath($mach, $lfspath);
|
69 arta 1.1
|
70 arta 1.2 if ($rwd eq "")
|
71 arta 1.1 {
|
72 arta 1.2 print STDERR "Path '$lwd' is not a network filesystem mounted on '$mach'; bailing.\n";
|
73 arta 1.1 exit(1);
74 }
75 }
76
77 $wdupdate = 1;
78 }
79 else
80 {
81 print STDERR "Invalid JSOC working directory argument; bailing.\n";
82 exit(1);
83 }
84
85 $aidx++;
86 }
87
88 if ($wdupdate != 1)
89 {
90 if (!defined($JSOCROOT))
91 {
92 print STDERR "Environment variable 'JSOCROOT' not set; bailing.\n";
93 exit(1);
94 arta 1.1 }
95
96 if (!(-d $JSOCROOT))
97 {
98 print STDERR "Invalid JSOC root directory; bailing.\n";
99 exit(1);
100 }
101
|
102 arta 1.3 @rsp = ResolvePath($JSOCROOT);
103 $lwd = shift(@rsp);
|
104 arta 1.1 }
105
106 # First, synchronize with CVS repository
107 print STDOUT "####### Start cvs update ####################\n";
108 $synccmd = "(cd $lwd; jsoc_sync.pl -l$CVSLOG)";
109 print "Calling '$synccmd'.\n";
110 system($synccmd);
111
112 print STDOUT "##\n";
113 print STDOUT "## A scan of $CVSLOG for files with conflicts follows:\n";
114 print STDOUT "## Start scanning cvsupdate.log\n";
115 system("(cd $lwd; grep '^C ' $CVSLOG)");
116
117 print STDOUT "## Done scanning cvsupdate.log\n";
118 print STDOUT "## Any lines starting with a 'C' between the 'Start' and 'Done' lines above should be fixed.\n";
119 print STDOUT "## See release notes to deal with 'C' status conflicts.\n";
120 print STDOUT "##\n";
121 print STDOUT "## Now Check cvsstatus for files that should be in the release ##\n";
122 print STDOUT "####### Start checking status ####################\n";
123
124 if (-e $CVSSTATUS)
125 arta 1.1 {
126 system("cd $lwd; $CVSSTATUS");
127
128 print STDOUT "####### Done checking status ####################\n";
129 print STDOUT "## If no lines between the 'Start' and 'Done' lines then there are no cvsstatus problems.\n";
130 print STDOUT "## Continue with 'cont' when ready.\n";
131
132 $line = <STDIN>;
133 chomp($line);
134 $line = lc($line);
135
136 if ($line =~ /.*cont.*/)
137 {
138 my($lfspath);
139 my($machtype);
140 my($echocmd) = 'echo $JSOC_MACHINE';
141
|
142 arta 1.5 system("(cd $lwd; ./configure)");
|
143 arta 1.1
144 @rsp = GetFSPath("local", $lwd);
|
145 arta 1.2 $lfspath = shift(@rsp); # could be local only
146
147 if ($lfspath !~ /:\S+::/)
148 {
149 print STDERR "Path '$lwd' is mounted locally only; bailing.\n";
150 exit(1);
151 }
|
152 arta 1.1
|
153 arta 1.6 my($cmd);
154
|
155 arta 1.1 foreach $mach (@machines)
156 {
157 $machtype = `ssh $mach '$echocmd'`;
158 chomp($machtype);
159
160 print STDOUT "start build on $machtype\n";
161 @rsp = GetMountPath($mach, $lfspath);
|
162 arta 1.6 $rwd = shift(@rsp);
163 $cmd = "(ssh $mach 'cd $rwd;$rwd/make_jsoc.pl') 1>make_jsoc_$machtype.log 2>&1";
164 print STDOUT "$cmd\n";
165 system($cmd);
|
166 arta 1.1 print STDOUT "done on $machtype\n";
167 }
168 }
169 else
170 {
171 print STDOUT "Bailing upon user request.\n";
172 exit(0);
173 }
174 }
175 else
176 {
177 print STDERR "Required script $CVSSTATUS missing; bailing.\n";
178 exit(1);
179 }
180
181 print STDOUT "JSOC update Finished.\n";
182
183 sub InitMaps
184 {
185 my($first);
186 my($mach);
187 arta 1.1 my($fs);
188 my($mountpoint);
189
190 # current machine
191 open(DFCMD, "df |");
192 $first = 1;
193 while (defined($line = <DFCMD>))
194 {
195 if ($first == 1)
196 {
197 $first = 0;
198 next;
199 }
200 chomp($line);
|
201 arta 1.2 if ($line =~ /^(\S+:\S+)\s+.+\s+(\S+)$/)
|
202 arta 1.1 {
203 if (defined($1) && defined($2))
204 {
205 $fs = $1;
206 $mountpoint = $2;
207 $fs =~ s/g:/:/;
208 $fs2mount{"local"}->{$fs} = $mountpoint;
209 $mount2fs{"local"}->{$mountpoint} = $fs;
|
210 arta 1.2
211 #print "$fs\t$mountpoint\n";
|
212 arta 1.1 }
213 }
214 }
|
215 arta 1.2
|
216 arta 1.1 close DFCMD;
217
218 # remote machines
219 foreach $mach (@machines)
220 {
221 open(DFCMD, "ssh $mach df |");
222 $first = 1;
223 while (defined($line = <DFCMD>))
224 {
225 if ($first == 1)
226 {
227 $first = 0;
228 next;
229 }
230 chomp($line);
|
231 arta 1.2 if ($line =~ /^(\S+:\S+)\s+.+\s+(\S+)$/)
|
232 arta 1.1 {
233 if (defined($1) && defined($2))
234 {
235 $fs = $1;
236 $mountpoint = $2;
237 $fs =~ s/g:/:/;
238 $fs2mount{$mach}->{$fs} = $mountpoint;
239 $mount2fs{$mach}->{$mountpoint} = $fs;
|
240 arta 1.2
241 #print "$fs\t$mountpoint\n";
|
242 arta 1.1 }
243 }
244 }
245
246 close DFCMD;
247 }
248 }
249
|
250 arta 1.3 sub ResolvePath
251 {
252 my($path) = @_;
253 my($savedp);
254 my($rpath);
255 my(@ret);
256
257 $savedp = `pwd`;
258 chdir($path);
259 $rpath = `pwd`;
260 chdir($savedp);
261 chomp($rpath);
262
263 push(@ret, $rpath);
264 return @ret;
265 }
266
|
267 arta 1.2 # input is an absolute path on $mach
|
268 arta 1.1 sub GetFSPath
269 {
|
270 arta 1.2 my($mach, $mountpath) = @_;
|
271 arta 1.1 my($fs);
272 my($mountpoint);
273 my(@fsinfo);
274 my(@ret);
275 my($fspath);
276
277 @fsinfo = GetFS($mach, $mountpath);
278 $fs = shift(@fsinfo);
279 $mountpoint = shift(@fsinfo);
|
280 arta 1.3
|
281 arta 1.1 $fspath = $mountpath;
282 $fspath =~ s/$mountpoint/${fs}::/;
283
284 push(@ret, $fspath);
285 return @ret;
286 }
287
|
288 arta 1.2 # input is an FS path and a machine on which the FS is mounted
|
289 arta 1.1 sub GetMountPath
290 {
291 my($mach, $fspath) = @_;
292 my($mountpath);
293 my($mountpoint);
294 my($fs);
295 my(@ret);
|
296 arta 1.2
|
297 arta 1.1 $fs = $fspath;
298 if ($fs =~ /(.+)::/)
299 {
300 $fs = $1;
301 }
302
303 $mountpoint = $fs2mount{$mach}->{$fs};
304
|
305 arta 1.2 if (defined($mountpoint))
306 {
307 $mountpath = $fspath;
308 $mountpath =~ s/${fs}::/$mountpoint/;
309
310 if ($mach eq "local")
311 {
312 if (!(-d $mountpath))
313 {
314 print STDERR "Directory '$mountpath' does not exist on machine '$mach'; bailing.\n";
315 exit(1);
316 }
317 }
318 else
319 {
320 open(STATCMD, "(ssh $mach stat $mountpath | sed 's/^/STDOUT:/') 2>&1 |");
321
322 while (defined($line = <STATCMD>))
323 {
324 chomp($line);
325 if ($line !~ /^STDOUT:/)
326 arta 1.2 {
327 if ($line =~ /No such file or directory/)
328 {
329 print STDERR "Directory '$mountpath' does not exist on machine '$mach'; bailing.\n";
330 close STATCMD;
331 exit(1);
332 }
333 }
334 }
335
336 close STATCMD;
337 }
338
339 push(@ret, $mountpath);
340 }
341 else
342 {
343 push(@ret, "");
344 }
345
|
346 arta 1.1 return @ret;
347 }
348
|
349 arta 1.2 # input is an absolute path on $mach
|
350 arta 1.1 sub GetFS
351 {
352 my($mach, $path) = @_;
353 my($fs);
354 my($mountpoint);
355 my(@ret);
356
357 if ($mach eq "local")
358 {
|
359 arta 1.2 if (-d $path)
360 {
361 $fs = `df $path`;
362 }
363 else
364 {
365 print STDERR "Directory '$path' does not exist on machine '$mach'; bailing.\n";
366 exit(1);
367 }
|
368 arta 1.1 }
369 else
370 {
|
371 arta 1.2 open(STATCMD, "(ssh $mach stat $path | sed 's/^/STDOUT:/') 2>&1 |");
372
373 while (defined($line = <STATCMD>))
374 {
375 chomp($line);
376 if ($line !~ /^STDOUT:/)
377 {
378 if ($line =~ /No such file or directory/)
379 {
380 print STDERR "Directory '$path' does not exist on machine '$mach'; bailing.\n";
381 close STATCMD;
382 exit(1);
383 }
384 }
385 }
386
|
387 arta 1.1 $fs = `ssh $mach df $path`;
388 }
389
390 if ($fs =~ /.+\n(\S+)\s+.+\s+(\S+)$/)
391 {
392 $fs = $1;
393 $mountpoint = $2;
394 }
395 else
396 {
|
397 arta 1.2 print STDERR "Invalid 'df' response '$fs'; bailing.\n";
|
398 arta 1.1 exit(1);
399 }
400
401 # This is SU-specific!
402 $fs =~ s/g:/:/;
403
404 push(@ret, $fs);
405 push(@ret, $mountpoint);
406 return @ret;
407 }
|