source: trunk/locker/sbin/parallel-find.pl @ 1366

Last change on this file since 1366 was 1285, checked in by ezyang, 15 years ago
Implement searching for Wizard autoinstalls.
  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#!/usr/bin/perl
2
3# Script to help generate find the .scripts-version files
4
5use lib '/mit/scripts/sec-tools/perl';
6
7open(FILE, "</mit/scripts/sec-tools/store/scriptslist");
8my $dump = "/mit/scripts/sec-tools/store/versions";
9
10(! -e $dump) || die "Output directory exists: $dump";
11system("mkdir", $dump) && die;
12
13use Proc::Queue size => 40, debug => 0, trace => 0;
14use 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
22sub 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
30sub old_version ($) {
31    my $dirname = shift;
32    open my $h, "$dirname/.scripts-version";
33    return (<$h>)[-1];
34}
35
36sub version ($) {
37    my $dirname = shift;
38    open my $h, "$dirname/.scripts/version";
39    return (<$h>)[-1];
40}
41
42sub find ($$) {
43    my $user = shift;
44    my $homedir = shift;
45
46    open my $files, "find $homedir/web_scripts -xdev -name .scripts-version -o -name .scripts 2>/dev/null |";
47    open my $out, ">$dump/$user";
48    while (my $f = <$files>) {
49        chomp $f;
50        my $old_style;
51        $old_style = ($f =~ s!/\.scripts-version$!!);
52        if (! $old_style) {
53            $f =~ s!/\.scripts$!!;
54        }
55        if (! updatable($f)) {
56            print STDERR "not updatable: $f";
57            next;
58        }
59        $v = $old_style ? old_version($f) : version($f);
60        print $out "$f:$v";
61    }
62    return 0;
63}
64
65while (<FILE>) {
66    my ($user, $homedir) = /^([^ ]*) (.*)$/;
67    my $f=fork;
68    if(defined ($f) and $f==0) {
69        if ($homedir !~ m|^/afs/athena| && $homedir !~ m|^/afs/sipb| && $homedir !~ m|^/afs/zone|) {
70            print "ignoring foreign-cell $user $homedir\n";
71            exit(0);
72        }
73        print "$user\n";
74        $ret = find($user, $homedir);
75        sleep rand 1;
76        exit($ret);
77    }
78    1 while waitpid(-1, WNOHANG)>0; # avoids memory leaks in Proc::Queue
79}
Note: See TracBrowser for help on using the repository browser.