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

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