How can I get a 'verbose' exit code for apt-get
so that errors like this
Package google-chrome is a virtual package provided by:
google-chrome-stable 29.0.1547.76-r223446
google-chrome-beta 30.0.1599.47-1
You should explicitly select one to install.
E: Package 'google-chrome' has no installation candidate
have a different exit code than download errors like this
Err http://dl.google.com/linux/chrome/deb/ stable/main google-chrome-stable amd64 29.0.1547.76-r223446
Something wicked happened resolving 'dl.google.com:http' (-11 - System error)
Currently, both errors exit with 100
Basically, I'd like to have download errors exit with a different code than errors like the first. If possible, I'd like each specific error to have a different exit code, but the above example is the minimum I need. How can I do this in a vanilla Ubuntu install without additional software (with the exception of aptitude
)?
I believe this is not a case of XY, and you just want to be able to debug apt-get generally speaking. Under such assumptions here is my answer.
From the
man apt.conf
:Hence, you only need to activate the rules for each of the debugging behaviors of
apt-get
:Those 3 are the first that the man page recommends, and the first will help you to debug the first error you show. For the second you may need:
https
,ftp
,cdrom
.The man page has many more, you can list them easily using
man apt.conf | grep -A5 -i debug
.All this should be written using the correct syntax and they are accept boolean values:
or if you want to use multiple lines:
If you want to run for only for a instance of apt-get you can use the
-o
/--option
switch:Another method is creating your personalized configuration file and load it with the
-c
/--config-file
switch:About changing the exit codes, I believe you can not unless you change the source code.
apt-get
is a state of art piece of software, as such it has advanced methods to debug the process without the need of relying of exit codes.Not a complete answer, but you could test for the existence of packages first by doing
apt-cache policy X
and grepping the output for "Candidate (none)" or "Couldn't find package X", etc.