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).

phk
  • 5,953
  • 7
  • 42
  • 71
Marcel
  • 1,124
  • 1
  • 15
  • 29

3 Answers3

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.
phk
  • 5,953
  • 7
  • 42
  • 71
lumbric
  • 389
  • 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
phk
  • 5,953
  • 7
  • 42
  • 71
pboin
  • 1,500
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.

tshepang
  • 65,642