Subversion Repositories DevTools

Rev

Rev 3413 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/usr/bin/perl -w
# nbannon 20050523
# chmod 777 /devl/dpkg_archive/*

use File::stat;

$DIR="/export/devl/dpkg_archive";
chdir($DIR) or die "$0: Could not change to \"$DIR\": $!\n";

($name, $passwd, $buildadm, $buildgid) = getpwnam ('buildadm');
$name = '';
$passwd = '';

die "$0: Could not determine uid of builadadm\n"
        unless ($buildadm && $buildgid);

die "$0: Not run as root\n"
        if ( $> );

opendir(DPKGARCHIVE, ".") or die "$0: Could not open \"$DIR\": $!\n";
LOOP: while (defined($pkg=readdir(DPKGARCHIVE))) {
   next if ( $pkg eq ".." );
   next if ( $pkg eq "." );
   next if ( $pkg eq "dpkg_archive_list.txt" );

    $sb=lstat($pkg);
    $rwx=$sb->mode & 00777;
    $uid=$sb->uid;

    # Rather than change everything every day, change it only if it's wrong
    if ($rwx != 00775) {
      system("/usr/bin/logger", "-p", "local0.notice", "-t", $0,
        sprintf("%s/%s: was chmod %04o", $DIR, $pkg, $rwx));
      printf STDERR ("%s: %s/%s: was chmod %04o\n", $0, $DIR, $pkg, $rwx);
      $rwx=($sb->mode & 07000) | 00775;
      unless (chmod($rwx, $pkg) == 1) {
        printf STDERR "%s: Could not chmod %04o %s/%s: %s\n", $0, $rwx, $DIR, $pkg, $!;
      }
    }

    if ($uid != $buildadm ) {
      system("/usr/bin/logger", "-p", "local0.notice", "-t", $0,
        sprintf("%s/%s: was uid %d", $DIR, $pkg, $uid));
      printf STDERR ("%s: %s/%s: was uid %d\n", $0, $DIR, $pkg, $uid);
      unless (chown($buildadm, $buildgid, $pkg) == 1) {
        printf STDERR "%s: Could not chown buildadm (%d) %s/%s: %s\n", $0,$uid, $DIR, $pkg, $!;
    }
  }
}
closedir(DPKGARCHIVE);