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

3 Answers 3

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. 
1
  • 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). Commented Jul 12, 2011 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
  • 2
    Why you calling this pseudo-code? It does work. Commented Jul 12, 2011 at 17:27
  • True, it does. There's just no sanity checking, error reporting, etc... Commented Jul 12, 2011 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.

2
  • 1
    You've just reinvented xargs, minus its quoting issues but they're not a problem here. Commented Jul 12, 2011 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 :) Commented Jul 12, 2011 at 22:00

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.