5

I tried to install Gnome 3 on Debian Testing following this explanation. However, this didn't work and left me without any graphical user interface.

At the moment I try to fix that and I realised there is a long list of packages marked as manually installed. I stored a (line-break separated) list of the packages that – in my opinion – should be marked as auto installed (nearly all of them).

Now I want to run apt-mark auto for this list.

How do I do that?

P.S.: I also would appreciate if somebody tells me that this is not a good idea (if it isn't).

7

You can use xargs:

 cat /path/to/file | xargs apt-mark auto

This should work if there is one package name per line in the text file /path/to/file.

Another option would be to use a for loop:

 for pkg in `cat /path/to/file`; do apt-mark auto $pkg; done

The second way might be useful if you have a similar problem where the command can't be called with a list of parameters but you have to call it once for each parameter you have. But in your case it's not that elegant of course… :)

Btw I assume that you are using bash.

Note: On my system apt-mark --help says:

Usage: apt-mark [options] {markauto|unmarkauto} packages...

And also:

apt-mark is deprecated, use apt-get markauto/unmarkauto.
  • 3
    With xargs, you can just write </path/to/file xargs apt-mark auto; and it'll cope with any whitespace separation between package names, not necessarily newlines (xargs has quoting issues but Debian package names don't contain any problematic character so it's ok here). An even simpler method is apt-mark auto $(cat /path/to/file) (which, again, works without requiring any special precaution because package names don't contain special characters). – Gilles 'SO- stop being evil' Jul 12 '11 at 21:06
3

It sounds like you want to dump your list of files into apt-mark auto one at a time. This pseudo-code should get you started:

while read pkgname; do apt-mark auto $pkgname; done <list_of_packages
  • 2
    Why you calling this pseudo-code? It does work. – tshepang Jul 12 '11 at 17:27
  • True, it does. There's just no sanity checking, error reporting, etc... – pboin Jul 12 '11 at 17:52
1

Run the following script with python scriptname.py list-of-packages.txt as root:

import subprocess
import sys

filename = sys.argv[1]
with open(filename) as f:
    packages = f.read()
    packages = packages.split()
    packages = " ".join(packages)
    cmd = "apt-mark auto " + packages
    subprocess.call(cmd, shell=True)

I expect that this wouldn't be a problem since having GNOME implies that you already have Python installed.

  • 1
    You've just reinvented xargs, minus its quoting issues but they're not a problem here. – Gilles 'SO- stop being evil' Jul 12 '11 at 21:07
  • 1
    I was sure there was a better way of doing things. It just so happens I was the first to answer so I thought something sub-optimal is better than nothing :) – tshepang Jul 12 '11 at 22:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.