You are not logged in.
I've written several scripts to maintain or improve Arch, two of which I've posted here. This one I wrote after I had seriously messed up a Pacman upgrade, and needed to pick up the pieces, so to speak.
findfuckery does nothing more than recurse through a directory tree and find the package owner of every file. I wrote it in Perl so it could cache results (i. e. after doing a pacman -Qo of a file, it would automatically throw in every other file from that package into a "found" hash so it wouldn't do a time-wasting lookup on those files, too). The reason I wrote this is because I accidentally updated about half of gnome without /opt mounted. Needless to say, I needed to easily find out which packages had been installed in there, so that I could remove them, mount opt, and then reinstall them properly.
Now the script. Runs with no arguments, just change directories to the tree you want to run it in (I ran it in /opt), and watch the colors fly. All of the verbose output goes to STDERR... the only thing that goes out to STDOUT is a final, unformatted, list of packages, so you can use this in shell scripts without a problem.
Now, the code:
#!/usr/bin/perl
#findfuckery.pl
# A tool to quickly and recursively find the owner of every file in a particular directory tree
# Copyright 2004 Michael Baehr
#
# This is free software. You may redistribute it under the terms of the GNU Public License,
# version 2 or later.
use strict;
use Cwd;
my %found;
my @packages;
open (FIND,"find . |");
my @files = <FIND>;
close (FIND);
sub color {
my ($h,$b,$f) = @_;
print STDERR "33[$h;$b;$f"."m";
}
sub color_off {
print STDERR "33[0m";
}
while (@files != 0) {
chomp (my $file = pop(@files));
$file =~ s:./::;
&color(1,1,31);
print STDERR "Analyzing file: ";
&color_off;
print STDERR "$file n";
if (!defined($found{$file})) {
my $owner = `pacman -Qo $file 2>/dev/null`;
if ($owner eq "") {
$found{$file} = "";
next;
} else {
my @ownerbits = split (" ",$owner);
my $realowner = $ownerbits[4];
open (OWNED,"pacman -Ql $realowner |");
my @owned = <OWNED>;
close (OWNED);
my $pwd = &Cwd::cwd();
while (@owned != 0) {
chomp (my $owned = pop(@owned));
my @ownedbits = split (" ",$owned);
my $realowned = $ownedbits[1];
$realowned =~ s/$pwd//;
$realowned =~ s:^/::;
if (-d $realowned) {
$realowned =~ s:/$::;
}
$found{$realowned} = $realowner;
}
push (@packages, $realowner);
$found{$file} = $realowner;
}
}
}
&color(1,1,33);
print STDERR "Done figuring out what you fucked up!n";
&color_off;
foreach my $file (keys %found) {
if ($found{$file} ne "") {
&color(1,1,31);
print STDERR "File: ";
&color_off;
print STDERR "$file ";
&color(1,1,31);
print STDERR "is owned by ";
&color_off;
print STDERR $found{$file};
print STDERR "n";
}
}
&color(1,1,33);
print STDERR "And here are the exciting packages: n";
&color(1,1,31);
while (@packages != 0) {
my $package = pop(@packages);
print "$package n";
}
&color_off;
Offline