[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Unused libs for deletion?



Hello Gunnar,

> Is there some script I can use to find out which installed packages
> aren't used by other packages.

Something like the below?

Note that it doesn't even attempt to do are alternatives and virtual packages.
This means that it'll miss some things that aren't necessary, and it'll list
some things that provide something useful.


Hope it helps...

Jiri <jiri@baum.com.au>

--
#!/usr/bin/perl

print <<ENDDOC and exit if $ARGV[0] =~ /-h/;
List installed packages which are "wanted". This means they are not essential
or required, and are not depended or recommended by another installed package.

$0 [-h|--help|-v|--verbose]

  -h, --help      show this help

  -v, --verbose   show the description of each package as well as its name

BUGS

* alternatives aren't handled properly

* virtual packages aren't handled

* the descriptions are shown without the proper formatting
ENDDOC
# ' #(fix apostrophes for syntax highlighting)

$v=1 if $ARGV[0] =~ /-v/;

$/="";

open(status,'/var/lib/dpkg/status') or die "$0: can't open status file.\n";

while (<status>) {
  next unless /^Status:\s*\S+ ok installed\s*?$/mi;

  s/^(\S+?:)/lc($1)/emg;
  %pkg = ('',split /^(\S+?):\s*/m); chomp %pkg;

  $_ = "$pkg{depends},$pkg{recommends},$pkg{'pre-depends'}";
  s/\(.*?\)//g; s/\|/,/g; s/\s+//g; s/,,/,/g; s/,$//; s/^,//;
  for (split /,/) {$used{$_}=1};

  next if $pkg{essential} =~ /yes/i or $pkg{priority} =~ /required/i;

  push @inst,$pkg{package};
  $desc{$pkg{package}}=$pkg{description} if $v;
}

if ($v) {
  for (sort @inst) {print "$_ - $desc{$_}\n\n" unless $used{$_}};
} else {
  for (sort @inst) {print "$_\n" unless $used{$_}};
}



Reply to: