Check a list of packages to install with apt-get

Posted by Joel on Stack Overflow See other posts from Stack Overflow or by Joel
Published on 2011-01-07T17:49:45Z Indexed on 2011/01/07 17:54 UTC
Read the original article Hit count: 212

Filed under:
|
|
|

I am writing a post-install script for Ubuntu in Perl (same script as seen here). One of the steps is to install a list of packages. The problem is that if apt-get install fails in some of many different ways for any one of the packages the script dies badly. I would like to prevent that from happening.

This happens because of the ways that apt-get install fails for packages that it doesn't like. For example when I try to install a nonsense word (i.e. typed in the wrong package name)

$ sudo apt-get install oblihbyvl
Reading package lists... Done
Building dependency tree       
Reading state information... Done
E: Unable to locate package oblihbyvl

but if instead the package name has been obsoleted (installing handbrake from ppa)

$ sudo apt-get install handbrake
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package handbrake is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'handbrake' has no installation candidate
$ apt-cache search handbrake
handbrake-cli - versatile DVD ripper and video transcoder - command line
handbrake-gtk - versatile DVD ripper and video transcoder - GTK GUI

I have tried parsing the results of apt-cache and apt-get -s install to try to catch all possibilities before doing the install, but I seem to keep finding new ways to allow failures to continue to the actual install system command.

My question is, is there some facility either in Perl (e.g. a module, though I would like to avoid installing modules if possible as this is supposed to be the first thing run after a new install of Ubuntu) or apt-* or dpkg that would let me be sure that the packages are all available to be installed before installing and if not fail gracefully in some way that lets the user decide what to do?

© Stack Overflow or respective owner

Related posts about perl

Related posts about ubuntu