Rev 3413 | Rev 5272 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/perl -w# nbannon 20050523# chmod 0775 /devl/dpkg_archive/*############################## Ensure that package directories in dpkg_archive are:# chmod 0775 - Not world writable# chown buildadm - Owned by buildadm## Script should be run as root - so that it can fix file attributes#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";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;if ( -d $pkg && isEmptyDir($pkg) == 1 ){system("/usr/bin/logger", "-p", "local0.notice", "-t", $0,sprintf("%s/%s: is empty", $DIR, $pkg, $rwx));printf STDERR ("%s: %s/%s: is empty\n", $0, $DIR, $pkg, $rwx);unless (rmdir($pkg)) {printf STDERR "%s: Could not delete empty directiry %s/%s: %s\n", $0, $rwx, $DIR, $pkg, $!;next;}}# Rather than change everything every day, change it only if it's wrongif ($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);#-------------------------------------------------------------------------------# Function : isEmptyDir## Description : Tset for empty directiry## Inputs : $dir - Path to directory## Returns : 0 - Contains stuff# 1 - Does not contain stuff# -1 - Does not exist#sub isEmptyDir{my ($dir) = @_;my $rv = -1;if (opendir (my $dh, $dir )){$rv = 1;while (readdir $dh){next if ($_ eq '.');next if ($_ eq '..');$rv = 0;last;}closedir $dh;}return $rv;}