4

I want to backup my list of manually selected packages in Ubuntu, without listing packages installed as dependencies. For example,

dpkg --get-selections

returns a complete list of all installed packages, manually selected as well as dependencies. How can I filter dependencies?

Johan
  • 746
  • 5
  • 20
  • My goal is to install a new Ubuntu system with the same setup as my current, and I do not want to install my old dependencies as manually selected. The current system is actually Ubuntu 9.10 and the new system is 10.04 beta2, so the dependencies are not necessarily equal. Any suggestion that can lead to my goal would be appreciated. – Johan Apr 19 '10 at 08:17

4 Answers4

3

I hacked myself a solution :)

dpkg --get-selections | cut -f 1 > /tmp/all
apt-mark showauto > /tmp/auto
diff /tmp/all /tmp/auto | grep '<' | sed 's/.* //'

That will first generate a complete list "all" of installed packages, then a list "auto" of automatically installed ones, and finally create a list of differences from all and auto, which is the list I need.

Any better suggestions?

Johan
  • 746
  • 5
  • 20
0

You could filter out the lib packages and manually filter the remaining ones. I don't think that there's a standard way to do this.

dpkg --get-selections |wc -l
1831
dpkg --get-selections |grep -v ^lib | wc -l
1060
Cosu
  • 236
  • 1
  • 4
  • Not good enough. Dependencies can be others than libs and libs are not always dependencies. I have installed my system manually now, but I still find the question interesting. – Johan Apr 19 '10 at 14:18
0

# ASSUMING your dpkg Logs go back to the initial machine install

###(May/Probablly NOT work across dist-upgrades)

apt-mark showauto >/tmp/auto.pkgs

Create a full dpkg timeline log
cp /dev/null /tmp/dpkg.full
for LOG in $(ls -rt /var/log/dpkg.log.[0-9].gz  /var/log/dpkg.log.1[0-9].gz)
do
    test -e $LOG && gunzip -c  $LOG>> /tmp/dpkg.full
done
for LOG in $(ls -rt /var/log/dpkg.log /var/log/dpkg.log.[0-9]  /var/log/dpkg.log.1[0-9]) 
do
    test -e $LOG && cat $LOG >>/tmp/dpkg.full
done
Now Filer out the packages initially installed by the OS
awk -v initialinstall=1 '
   / install grub-pc / {initialinstall = 0; next;}                     
   / install / {if ( initialinstall == 0) print $4;}
' /tmp/dpkg.full | grep -vf /tmp/auto.pkgs >~/iInstalled.pkgs
sysadmin1138
  • 131,083
  • 18
  • 173
  • 296
0

If you want a list of packages that are not marked as automatically installed (which is not always the same as not being a dependency), you can do this in a simpler way using aptitude like so:

aptitude search ~i | grep "^i   " | awk '{ print $2 }'

If you are really concerned with weeding out all dependencies, you can look into the ~R and ~D search patterns. I think aptitude is the currently recommended front-end to dpkg and apt. You will find that it has a number of really useful command-line options, in addition to the ncurses interface.

Karol
  • 323
  • 2
  • 9