You are not logged in.

#1 2015-04-17 01:45:02

canolucas
Member
Registered: 2010-05-23
Posts: 52

[SOLVED] System Maintenance, Pacman issue

Hey !
I've had arch installed on my machine for three years now, and the list of explicitly installed packages is slowly getting huge.

Almost half of my packages are marked as explicit. So, I was thinking in a way of fixing this:

i.e.
Instead of having both yelp and yelp-xsl, i want to unmark yelp-xsl (as it is a dependency of the first one)

I was thinking of making a BASH script to do the job. However, I don't know what's the best way to implement this.

What I need is basically to loop the list of explicit packages:

for each item of (pacman -Qe) check if another one has it as a dependency. if so, unmark it.

How can I implement this programatically ? I was thinking of doing something like:

# function to check if a list ($1) contains an item ($2)
listcontains() {
    for word in $1; do
        [[ $word = $2 ]] && return 0
    done
    return 1
}

# for each explicit package
for item in `pacman -Qe | awk '{print $1;}'` ; do

    # query all dependencies
    for dependency in `pacman -Si ${item} | sed -n '/Depends\ On/,/:/p' | sed '$d'|cut -d: -f2` ; do

            # check if the dependency is also on the list
            if listcontains `pacman -Qe | awk '{print $1;}'` ${dependency}; then

                # if so, unmark as explicit (mark as dependency)
                pacman -D --asdeps ${item}
            fi
    done
done

However, I fear to break my system even worse. Any suggestions ?

Thanks in advance !

Last edited by canolucas (2015-04-17 02:52:17)

Offline

#2 2015-04-17 02:37:12

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,330
Website

Re: [SOLVED] System Maintenance, Pacman issue

First, you could use -Qeq rather that -Qe and the awk command for pacman.  Then if you really wanted to keep reusing that list, you could store it in a bash array rather than rerunning the same pacman command over and over.  Further, there is no reason to reinstall all those packages, just use -D to change the install reason.  Finally, expac would be a huge help:

for pkg in $(pacman -Qeq); do
	expac %N $pkg | grep -q "[a-z]" && pacman -D --asdeps $pkg
done

Note, however, that this will mark every single package that is someone else's dependency "asdep" - this can have horrible side effects if you ever decide to uninstall a high-level package.  You should really only do this for any packages that you have no desire to keep on their own merits - or in otherwords, replace the pacman -D command with "echo" then just take the list the script spits out and apply the asdesp change only to those members of that list you have no interest in keeping.

mod note: this is not really a pacman issue - it is a scripting question.  Moving to programming and scripting.

EDIT: actually there is an even easier and much faster way to get that list:

expac "%n %N" | awk 'NF>1 {print $1;}'

and if you really want to switch them all to "asdeps" (I strongly advise against this):

pacman -D --asdeps $(expac "%n %N" | awk 'NF>1 {print $1;}')

EDIT 2: I realized the above commands actually include all packages that are dependencies of others whether they were installed explicitly or already 'asdeps' - that makes not change in the actual result of the process, but the list is a bit longer than it need be.  This can be resolved with a slight change:

expac "%w %n %N" | awk '/^explicit/ && NF>2 {print $2;}'

But this made me realize this can also be done without expac:

comm -23 <(pacman -Qeq) <(pacman -Qeqtt)

Last edited by Trilby (2015-04-17 11:18:00)


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

Board footer

Powered by FluxBB