2007-08-13
Migrating aptitudes knowledge about auto-installed packages
Jonathan McDowell wonders how to take aptitude’s knowledge about auto-installed packages from one computer to the other. Well, I looked into the issue for a few minutes and I found a solution though it doesn’t look nice.
for i in
# grep installed package names
`COLUMNS=200 dpkg -l | grep -E '^ii'| awk '{print $2};' `
do
# find package in /var/lib/aptitude/pkgstates
# check for the right state (1 seems to mean
# auto-installed, 3 manually installed)
if
grep-available -s Package,State \
-F Package \
-X $i /var/lib/aptitude/pkgstates \
| grep -q 'State: 1'
then
echo $i
fi
done
Results in a list of auto-installed packages AFAICT. If you change the “State: 1″ into “State: 3″, it seems you get only manually installed packages. So if you take the latter and feed it to “aptitude install”, your database should be right. If you take the former, you feed the list to “aptitude markauto”. A cleaner solution (which works even if /var/lib/aptitude/pkgstates changes formats) would involve checking “aptitude show” output, evaluating the “Automatically installed:” field. However, simply feeding “aptitude show” output to grep-dctrl (or any equivalent) resultes in the rather irritating error message “grep-dctrl: -:14: expected a colon.”, with the 14 changing to a different line in the packages description (usually a line directly following an empty line). So I’m just giving you an idea here.
See also No related posts
Permalink

Romain Francoise said,
August 13, 2007 at 16:35 UTC (+0000)
aptitude search ‘~M’?
Andreas Janssen said,
August 13, 2007 at 18:48 UTC (+0000)
Try this:
aptitude search “~M” -F %p > list
will search all packages set to auto, and only show the
package names.
cat list | xargs aptitude markauto
should import the information.
Gilles Mocellin said,
August 13, 2007 at 20:58 UTC (+0000)
Hum, aptitude has all the required options to make this selection :
# aptitude -F “%p” search ~i\!~M
stew said,
August 14, 2007 at 14:44 UTC (+0000)
your method of finding installed packages:
“COLUMNS=200 dpkg -l | grep -E ‘^ii’| awk ‘{print $2};’ `”
will miss packages that are installed, but on hold. (which would have ‘hi’ and not ‘ii’)
sven said,
August 14, 2007 at 17:05 UTC (+0000)
@stew
Ouch, you are right. I didn’t notice since I don’t have any packages on hold (I checked after your comment).
As for the other comments about aptitude already supporting all that’s needed, I will explain the commandline shown as the manpage for aptitude in Etch is a bit hard to read (see bug#415468). Also the available search tags are not documented in the manpage at all, but in the seperate reference manual.
-F %p
tells aptitude search to only list the package names.
~i shows only installed packages
!~M shows only packages which are not auto-installed.
martin said,
August 15, 2007 at 09:54 UTC (+0000)
Hmm, i just copied the aptitude statefile over from my old 32bit system to my new 64 system…. I don’t remember the details, but it worked like it should. I guess you could even get away only copying the file and then using aptitude to install all the packages too…
sven said,
August 15, 2007 at 10:31 UTC (+0000)
@martin:
That might work, but certainly only if you first install the packages and then copy the file over. If you have a package marked as auto-installed and later call aptitude install on it, it removes the auto-installation mark from then package.