Ubuntu: July 2008 Archives

In an earlier post I said that I'd post details on how to manually remove stale diversions with dpkg-divert if anyone wanted them. Uwe Koch asked, so here it is!

Solution

The first problem is to find the stale diversions. If you type something like:

$ dpkg-divert --list
You'll get several lines like this:
diversion of /usr/lib/libGL.so.1.2 to /usr/lib/fglrx/libGL.so.1.2.xlibmesa by xorg-driver-fglrx

Since you want to filter out the ones that apply to the ATI drivers, and all of them contain fglrx, you can do this:

$ dpkg-divert --list | grep fglrx

The bit you want is the first path. You can extract that with either:

$ dpkg-divert --list | grep fglrx | cut -d' ' -f3

or

$ dpkg-divert --list | awk '/fglrx/ {print $3}'

You should get a list like this:

/usr/lib/libGL.so.1.2
/usr/X11R6/lib/libGL.so.1.2
/usr/X11R6/lib32/libGL.so.1.2
/usr/X11R6/lib32/libGL.so.1
/usr/lib32/libGL.so.1.2
/usr/lib32/libGL.so.1

You can then manually go through the list, removing the diversions one-by-one:

$ sudo dpkg-divert --remove /usr/lib/libGL.so.1.2

Alternatively, if you're highly confident in your own bash-fu skills:

$ dpkg-divert --list | awk '/fglrx/ {print $3}' | \
> while read; do \
>    sudo dpkg-divert --remove $REPLY; \
> done

The above is shown broken over four lines just so that it isn't too wide for the web-page: in practice, I would type it all on one line. This is what is “really looks like” completely: the backslashes (\) are typed in and escape the newline which must follow immediately. Bash supplies the > character at the start of each line, which is the secondary shell prompt.

Job done!