View Single Post
Posts: 236 | Thanked: 223 times | Joined on Oct 2009 @ NE UK
#20
Just for fun, I've knocked together a quick perl script that can find the non-optified disk usage for a given package:

Code:
#!/usr/bin/perl

%known_optified = ();
%known_nonoptified = ();

sub is_secretly_optified($) {
  my ($file) = @_;

  # print "testing $file\n";

  if($known_optified{$file}) {
     # print "known optfified $file\n";
    return 1;
  }

  if($known_nonoptified{$file}) {
    # print "known nonoptfified $file\n";
    return 0;
  }

  unless($file) {
    return 0;
  }
  my $orig = $file;

  unless( -l $file) {
    $file =~ s/\/[^\/]*$//;
    if(is_secretly_optified($file)) {
      $known_optified{$orig} = 1;
      return 1;
    } else {
      $known_nonoptified{$orig} = 1;
      return 0;
    }
  }

  my $lsresult = `/bin/ls -l $file`;
  chomp($lsresult);

  if($lsresult =~ /->\s+(.*)/) {
    my $target = $1;
    # print "found symlink to $target\n";
    if($target =~ /^\/opt/ or $target =~ /^\/home/) {
      # print "remembering $target is optified?\n";
      # print "remembering $orig is optified?\n";
      $known_optified{$orig} = 1;
      return 1;
    } else {
      if(is_secretly_optified($target)) {
        $known_optified{$orig} = 1;
        return 1;
      } else {
        $known_nonoptified{$orig} = 1;
        return 0;
      }
    }
  }
}

while(<>) {
  unless($currentfile eq $ARGV) {
    $currentfile = $ARGV;
    if($out) {
      if($total >= 1024) {
        $total = sprintf("%0.2fM", $total / 1024);
      } else {
        $total = sprintf("%0.2fK", $total);
      }
      print "$out$currentpkg : total non-opt usage: "
            . "$total\n----------\n";
    }
    $out = undef;
    $total = undef;
    $currentfile = $ARGV;

    $currentpkg = $currentfile;
    $currentpkg =~ s/\.md5sums//;
    $currentpkg =~ s/.*\///;
  }

  s/^\S+\s+//;
  $suspect = "/$_";

  $du = undef;
  unless(/^opt/ or /^home/ or /^usr\/share\/(man|doc)\//) {
    next if(is_secretly_optified($suspect));
    $du = `du -s $suspect`;
    chomp $du;
    if($du =~ /^(\d+)/) {
      $total += $1;
      if($1 >= 1024) {
        $val  = sprintf("%0.2fM", $1 / 1024);
      } else {
        $val  = sprintf("%0.2fK", $1);
      }

      $du =~ s/^\d+/$val/;
    }
    $out .= "$currentpkg : $du\n";
  }
}


if($out) {
  if($total >= 1024) {
    $total = sprintf("%0.2fM", $total / 1024);
  } else {
    $total = sprintf("%0.2fK", $total);
  }
  print "$out$currentpkg : total non-opt usage: "
        . "$total\n---------\n";
}
If you save it as /usr/local/bin/find_non_opt_files.pl, you can run it giving /var/lib/dpkg/info/<pkgname>.md5sums as an argument. Here is the commandline and output running it on a sample package:

~# /usr/local/bin/find_non_opt_files.pl /var/lib/dpkg/info/burgerspace.md5sums
burgerspace : 4.00K /usr/share/pixmaps/burgerspace.xpm
burgerspace : 4.00K /usr/share/applications/hildon/burgerspace.desktop
burgerspace : 8.00K /usr/share/icons/hicolor/scalable/hildon/burgerspace.png
burgerspace : 4.00K /usr/share/icons/hicolor/48x48/hildon/burgerspace.png
burgerspace : 4.00K /usr/share/icons/hicolor/32x32/hildon/burgerspace.png
burgerspace : 4.00K /usr/share/menu/burgerspace
burgerspace : total non-opt usage: 28.00K
-------------------------------------------------------
It will also take multiple arguments, so to see the results for all packages:

Code:
 /usr/local/bin/find_non_opt_files.pl /var/lib/dpkg/info/*.md5sums
which will produce a lot of output, including about system packages..

Edit: Just to add, this hasn't been security audited, so if you should have a line like "1234 asdf;rm -rf /" in one of your *.md5sums, or other similar problems, you're on your own!

Further Edit: Script amended to take account of symlinked directories as per posts around http://talk.maemo.org/showthread.php...655#post438655

One more edit: don't count files in /home as non-optified

Last edited by kwotski; 2009-12-25 at 16:34.
 

The Following 21 Users Say Thank You to kwotski For This Useful Post: