Gentoo, list installed packages with USE flags
Saving of operating system state could be very important sometimes. If you ever faced with a problem that you needed to find out which updated component caused a strange behaviour of some program then you know what I mean. Over the last few years I've been using my own backup program that creates reserve copies from different data sources. It also stores the system state as a set of config files and reports. History of changes is tracked by a version control system so each change is described by a system administrator. My program is not ready for publication yet since it should be improved in order to be used by other people. But I will share some of its components periodically. Today I'll tell you about report that contains list of all packages installed on Gentoo GNU/Linux including their USE flags.
Many of Gentoo users probably know the command for listing all installed packages. It could be done with equery utility from gentoolkit package.
# equery list
... [I--] [ ] x11-libs/Xaw3d-1.5-r1 (0) [I--] [ ] x11-libs/cairo-1.8.8 (0) [I--] [ ] x11-libs/gtk+-2.16.6 (2) [I--] [ ] x11-libs/libICE-1.0.5 (0) [I--] [ ] x11-libs/libSM-1.1.1 (0) [I--] [ ] x11-libs/libX11-1.2.2 (0) [I--] [ ] x11-libs/libXScrnSaver-1.1.3 (0) ...
Its output is pretty useful but isn't often sufficient for our needs since a package state depends on USE flags. To list them all for each package you can use my script.
# list-gentoo-packages.sh
... x11-libs/Xaw3d-1.5-r1 x11-libs/cairo-1.8.8 +X +opengl +svg -cleartype -debug -directfb -doc -glitz -xcb x11-libs/gtk+-2.16.6 +cups +jpeg +tiff -debug -doc -jpeg2k -test -vim-syntax -xinerama x11-libs/libICE-1.0.5 +ipv6 -debug x11-libs/libSM-1.1.1 +ipv6 +uuid -debug -elibc_FreeBSD x11-libs/libX11-1.2.2 +ipv6 +xcb -debug x11-libs/libXScrnSaver-1.1.3 -debug ...
This is done by direct analysis of Portage database, that is located at /var/db/pkg/, and IUSE files for each package. It could be useful to compare reports generated before and after system update. This helps to reveal trivial mistakes. I hope it will be helpful for you.
Download list-gentoo-packages.sh, version 0.2.
Nikita Melnichenko.
Comments
Thanks, I looked for something like that.
Thanks, that will really help!
Thanks, great job!
Hi,
How can I use this list to install the same software (same USE flags and same version) on a other server?
Thanks in advance for any answer.
Hi plop,
Consider the following:
# list-gentoo-packages.sh > installed-packages
# cat installed-packages | sed 's/^/=/' > use
# cat use
...
=x11-libs/cairo-1.10.2-r1 +X +glib +opengl +qt4 +svg -aqua -debug -directfb -doc -drm -gallium -openvg -static-libs -xcb
=x11-libs/gdk-pixbuf-2.24.0-r1 +X +introspection +jpeg +tiff -debug -doc -jpeg2k -test
=x11-libs/gtk+-2.24.5-r1 +cups +introspection -aqua -debug -doc -examples -test -vim-syntax -xinerama
=x11-libs/gtksourceview-2.10.5-r1 -doc -glade -test
=x11-libs/libICE-1.0.7 +ipv6 -doc -static-libs
...
# cat installed-packages | awk '{ print $1; }' | sed 's/^/=/' > atoms
# cat atoms
...
=x11-libs/cairo-1.10.2-r1
=x11-libs/gdk-pixbuf-2.24.0-r1
=x11-libs/gtk+-2.24.5-r1
=x11-libs/gtksourceview-2.10.5-r1
=x11-libs/libICE-1.0.7
...
Copy 'use', 'atoms', /etc/portage/, /usr/portage/ as well as /etc/make.conf, /var/lib/portage/world and overlays to another machine and then do:
# cat use >> /etc/portage/package.use
# emerge -pv1 $(cat atoms)
"unofficial but fast" :)
$ time sh list-gentoo-packages.sh > /dev/null
time: Real 0m20.2s User 0m0.8s System 0m1.0s
raptor: ~
$ flush_cache
raptor: ~
$ time find /var/db/pkg/ -name IUSE | xargs -L1 awk -f moo.awk >/dev/null
time: Real 0m4.1s User 0m0.0s System 0m0.1s
---
moo.awk
{ gsub("[-+]","",$0) }
NR == 1 { split($0,use," ") }
NR == 2 { split($0,iuse," ") }
END {
printf FILENAME " "
for (i in use) { flags[use[i]]++ };
for (i in iuse) { flags[iuse[i]]++ };
for (i in flags) {
printf "%s%s ", flags[i]==2 ? "+" : "-" , i
}
print
}
actually, the input must be cat /var/db/pkg/x11-wm/fluxbox-1.3.2/USE /var/db/pkg/x11-wm/fluxbox-1.3.2/IUSE, but I think you get the point :)