Ubuntu – How to mark all packages with installed dependents as “Automatically Installed”

apt

There are some similar questions, but here is precisely what I would like to achieve and the dots which I am having trouble connecting:

  1. Query a list of "Manually Installed" packages (apt-mark showmanual works)
  2. Check each package for installed dependents
  3. Mark each such package as "Automatically Installed" (apt-mark auto <pkg ...> works)

So I think my command will look something like:

apt-mark showmanual | <esoteric apt/bash magic> | apt-mark auto -

Would that be correct?

Related Questions

  1. How do I find which packages could be set as automatically installed?
  2. Why are almost all packages marked as manually installed? (See also https://bugs.launchpad.net/ubuntu/+source/livecd-rootfs/+bug/424643/comments/26)

Best Answer

You could use Aptitude's why command:

for x in $(apt-mark showmanual)
do
  r="$(echo ${x} | sed -e 's/\([+.]\)/[\1]/g')"
  aptitude why ${x} | egrep -q "^i.* (Pre)?Depends +${r}( |$)" && apt-mark auto ${x}
done

Not tested, because it's not something I want to (have to un-)do on my machine.