LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 06-14-2010, 04:05 PM   #1
cjmueller
LQ Newbie
 
Registered: Dec 2008
Posts: 5

Rep: Reputation: 1
apt/aptitude package management "auto" flag


Hi all,

this is an answer to a problem I had, not a question...

Background: An [old] x86-based server running Debian Squeeze screwed up one of its SCSI hardware raids. Since the problem seemed more related to the raid controller than the disks (the disks still responded and I was able to restore their contents with some trickery), I got myself a QNAP NAS TS-119 as a replacement, installed Debian on it and wanted to install the original set of packages to the new platform.

Instead of simply installing all packages on the QNAP that were on the old x86 box, I wanted to maintain the status of automatically installed packages in aptitude.

After looking at /var/lib/aptitude/pkgstates and a bit of confusion, I looked at the aptitude source code and found the following rather simple explanation:

Aptitude merges the package status information from apt and aptitude without storing redundant information in its own status file (which is good). This means the information about packages that were automatically installed is tracked in /var/lib/apt/extended_states.

This may seem trivial but I couldn't find this information on the Internet so I thought I'd submit a dummy question here in case others are having similar problems.

For the sake of completeness: There seem to be situations (like pending actions) where aptitude will store auto-install information in its own state file, /var/lib/aptitude/pkgstates. But this was not my problem...

Thanks,
--Christian

Last edited by cjmueller; 06-14-2010 at 04:09 PM.
 
Old 06-14-2010, 04:42 PM   #2
cjmueller
LQ Newbie
 
Registered: Dec 2008
Posts: 5

Original Poster
Rep: Reputation: 1
Re: apt/aptitude package management "auto" flag

Here's a little awk script that will correlate the two files, /var/lib/aptitude/pkgstates and /var/lib/apt/extended_states, and print a list of packages that have been manually installed. It's important to feed the aptitude "pkgstates" file first, then the apt "extended_states" file.

Code:
#!/usr/bin/awk -f
/^Package:/ {
  pkg_name = $2;
}

/^State:/ {
  if ($2 == 1) {
    installed_pkg[pkg_name] = 1;
  }
}

/^Auto-Installed:/ {
  if ($2 == 1 && pkg_name in installed_pkg) {
    printf "- removing package %s because it's auto-installed\n", pkg_name;
    delete installed_pkg[pkg_name];
  }
}

END {
  printf "- manually installed packages:\n";
  for (i in installed_pkg) {
    printf "%s\n", i | "sort";
  }
}
Everything that has a "- " at the beginning of the line should be ignored, the rest is a list of packages which have been installed manually.

Example:

Code:
cat /var/lib/aptitude/pkgstates /var/lib/apt/extended_states | /path/to/awk/script

Last edited by cjmueller; 06-14-2010 at 05:03 PM.
 
Old 10-16-2011, 10:52 PM   #3
j_v
Member
 
Registered: Oct 2011
Distribution: Slackware64
Posts: 364

Rep: Reputation: 67
Just thought I'd point out that the same result can be achieved using apt-mark:

Code:
apt-mark -f /path/to/extended_states showmanual
I found your post interesting, because I had originally used an awk script for this.
Just something I threw together.

Code:
# get_pkg_state.awk
# usage: gawk -f get_pkg_state.awk /path/to/extended_states
# reads file with format found in /var/lib/apt/extended_states.
# output listing of manually installed packages listed (one per line) or
# output listing of automagically installed packages listed (one per line).

BEGIN { RS = "\n\n" ; manualcnt = 0 }
#BEGIN { RS = "\n\n" ; autocnt = 0 }

$6 == 0 { manualpkgs[manualcnt++] = $2 }
#$6 == 1 { autopkgs[autocnt++] = $2 }

END { for (i = 0; i < manualcnt; i++) print manualpkgs[i] }
#END { for (i = 0; i < autocnt; i++) print autopkgs[i] }
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
"Accessing the Package Management Failed" ibex Linux - Software 2 11-16-2009 12:13 PM
apt-get returning: "couldn't find package linux-headers-2.6..." compused Linux - Distributions 12 03-06-2009 10:04 PM
apt-get "recommends" package install question in Lenny kushalkoolwal Debian 8 12-28-2008 10:09 PM
Aptitude giving error after "apt-get update" ciden Linux - Software 6 03-22-2008 03:53 AM
apt-get install "package" mikeshn Linux - Software 6 05-30-2003 10:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 08:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration