login about faq

Sometimes I come to a machine where another admin installed some CSW packages which pulled in a lot of dependencies. Is there a way to list the packages that where meant to be installed?

This question is marked "community wiki".

asked Mar 26 '12 at 22:44

Dagobert's gravatar image

Dagobert ♦♦
151367

edited Mar 26 '12 at 23:04


This question seems rather trivial – just use pkginfo and be done with it. However, this gives you the complete list of installed CSW packages. 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);

link

answered Mar 26 '12 at 22:47

Dagobert's gravatar image

Dagobert ♦♦
151367

mental exercise: Where is the mistake:

This should deliver the same result, but it doesn't:

#!/usr/bin/env python

from subprocess import Popen, PIPE
import re

allpkg = []
f = Popen("/usr/bin/pkginfo", stdout=PIPE).stdout
allpkg = [ pkg.split()[1] for pkg in f if re.match('^CSW\w+',pkg.split()[1]) ]
f.close()

minimal = allpkg
for pkg in allpkg:
    try:
        f = open('/var/sadm/pkg/%s/install/depend' % pkg)
        for line in f:
            if len(line)>3 and line.split()[0] == 'P':
                try:
                    minimal.remove(line.split()[1])
                except ValueError:
                    pass
        f.close()
    except IOError:
        pass

for pkg in minimal:
    print pkg
link

answered Mar 28 '12 at 13:18

cgrzemba's gravatar image

cgrzemba
1225

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or __italic__
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×13
×1
×1

Asked: Mar 26 '12 at 22:44

Seen: 526 times

Last updated: Mar 28 '12 at 13:18

powered by OSQA