Tuesday 14 August 2012

aptitude fun!

We all know how to use aptitude user tags, don't we?
sudo aptitude install --add-user-tag tag_name package_name
sudo aptitude purge '?user-tag(tag_name)'
Well, that was simple. Let's do some more complicated stuff. Let's try to list all packages in our system that has user tag set:
aptitude show "?user-tag(d*)"
Got it? I didn't. You should add a letter (any letter) before your wildcard to get results. How and why it is working that way - no idea. The only thing I know is I run into it by accident. Of course it's a good idea to combine with grep:
aptitude show "?user-tag(d*)" | grep "User Tags"
Now it's more simple. We have a list of our user tags
(OK, OK, I know:
aptitude show "?user-tag(d*)" | grep "User Tags" | awk '{print $3}' | sort -u
)
But what now? Let's assume we want to remove some user tag from a package:
sudo aptitude remove-user-tag tag_name package_name
What if we want to remove user tag from all packages where it's set. Easy: just two commands:
1.
aptitude show "?user-tag(tag_name)" | grep ^Package | awk '{print $2}'

2. make a list of packages and run
sudo aptitude remove-user-tag tag_name [long list of packages here]
Is it really long list? If it really is you should experience a lot of hassle doing copy/paste into the aptitude command. But hopefully there is hope!
USER_TAG=tag_name; for i in $(aptitude show "?user-tag($USER_TAG)" | grep ^Package | awk '{print $2}'); do sudo aptitude remove-user-tag $USER_TAG $i; done
Not so bad, isn't it?