Which CSW packages have been installed?

September 29th, 2010 by Dagobert Michelsen

This question seems rather trivial – just use pkginfo and be done with it. However, this gives you the complete list of installed CSW packages. Sometimes I come to a machine where another admin installed some CSW packages which pulled in a lot of dependencies. When trying to find out what the initial cause for installation was I wrote this tiny script that prints the minimal set of CSW packages needed to be installed to result in the current set of CSW packages installed. No magic in there, but sometimes these little helpers come in handy 🙂

#!/opt/csw/bin/perl

my @allpkgs = grep { /^CSW/ }
              map { (split( /\s+/ ))[1] }
              `/usr/bin/pkginfo`;
my %minimal;
$minimal{$_} = 1 foreach (@allpkgs);

# Remove dependencies
foreach (@allpkgs) {
  open D, "/var/sadm/pkg/$_/install/depend" or next;
  while( <D> ) {
    my ($type, $pkg) = split( /\s+/ );
    next if( $type ne "P" );
    delete $minimal{$pkg};
  }
  close D;
}
print "$_\n" foreach (keys %minimal);