1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | # Script to help generate find the .scripts-version files |
---|
4 | |
---|
5 | use lib '/mit/scripts/sec-tools/perl'; |
---|
6 | |
---|
7 | open(FILE, "</mit/scripts/sec-tools/store/scriptslist"); |
---|
8 | my $dump = "/mit/scripts/sec-tools/store/versions"; |
---|
9 | |
---|
10 | (! -e $dump) || die "Output directory exists: $dump"; |
---|
11 | system("mkdir", $dump) && die; |
---|
12 | |
---|
13 | use Proc::Queue size => 40, debug => 0, trace => 0; |
---|
14 | use POSIX ":sys_wait_h"; # imports WNOHANG |
---|
15 | |
---|
16 | # this loop creates new childs, but Proc::Queue makes it wait every |
---|
17 | # time the limit (50) is reached until enough childs exit |
---|
18 | |
---|
19 | # Note that we miss things where one volume is inside another if we |
---|
20 | # use -xdev. May miss libraries stuff. |
---|
21 | |
---|
22 | sub updatable ($) { |
---|
23 | my $filename = shift; |
---|
24 | for my $l (`fs la "$filename"`) { |
---|
25 | return 1 if ($l =~ /^ system:scripts-security-upd rlidwk/); |
---|
26 | } |
---|
27 | return 0; |
---|
28 | } |
---|
29 | |
---|
30 | sub version ($) { |
---|
31 | my $dirname = shift; |
---|
32 | open my $h, "$dirname/.scripts-version"; |
---|
33 | return (<$h>)[-1]; |
---|
34 | } |
---|
35 | |
---|
36 | sub find ($$) { |
---|
37 | my $user = shift; |
---|
38 | my $homedir = shift; |
---|
39 | |
---|
40 | open my $files, "find $homedir/web_scripts -xdev -name .scripts-version 2>/dev/null |"; |
---|
41 | open my $out, ">$dump/$user"; |
---|
42 | while (my $f = <$files>) { |
---|
43 | chomp $f; |
---|
44 | $f =~ s!/\.scripts-version$!!; |
---|
45 | if (! updatable($f)) { |
---|
46 | print STDERR "not updatable: $f"; |
---|
47 | next; |
---|
48 | } |
---|
49 | $v = version($f); |
---|
50 | print $out "$f:$v"; |
---|
51 | } |
---|
52 | return 0; |
---|
53 | } |
---|
54 | |
---|
55 | while (<FILE>) { |
---|
56 | my ($user, $homedir) = /^([^ ]*) (.*)$/; |
---|
57 | my $f=fork; |
---|
58 | if(defined ($f) and $f==0) { |
---|
59 | if ($homedir !~ m|^/afs/athena|) { |
---|
60 | print "ignoring non-athena-cell $user $homedir\n"; |
---|
61 | exit(0); |
---|
62 | } |
---|
63 | print "$user\n"; |
---|
64 | $ret = find($user, $homedir); |
---|
65 | sleep rand 1; |
---|
66 | exit($ret); |
---|
67 | } |
---|
68 | 1 while waitpid(-1, WNOHANG)>0; # avoids memory leaks in Proc::Queue |
---|
69 | } |
---|