A feature that I wish Linux package managers had

August 5, 2009

One of the things that I wish Linux package managers like yum and Apt had was a convenient way of retrieving the original, stock version of some file and optionally reinstalling it into its original place. I'd expect (and wouldn't mind) that this would require re-downloading the original package that the file came from (and thus it was restricted to packages that were still in the package repository and hadn't been obsoleted and removed by some more recent package).

You might wonder what use this is. Well, perhaps you are more carefully organized than we are, but I find myself periodically wondering 'what did we change in file X?', for various varieties of X, and then trying to answer the question. While we have our customized files carefully saved in our reinstall area, we don't necessarily have the original file and especially we may not have the original file from the current OS release (if we have, for example, been carrying a customized file forward from OS release to OS release instead of attempting to redo our changes on top of each release's version).

(While careful use of a sufficiently sophisticated version control system can make it possible to keep track of all of this, it takes a bunch of additional work that you have to do all the time, even during emergencies when you're doing quick hacks to get the system going again.)

You can already do this by hand if you want, and I have, but it's a bunch of tedious work that the package manager could automate. Personally I think that it's a common enough thing (either in the 'I want to check the original' form or in the 'whoops, let's revert to stock configuration' form) that it should be a package manager feature.

(Today I found myself using 'apt-get purge lighttpd; apt-get install lighttpd' on a test system as the easiest way to get the stock lighttpd.conf file to look at. And you know, it was, and this is not a slam at Apt; I probably would have done the same thing with yum on an RPM-based system.)

Sidebar: how to do it by hand

The incantations that I know of for doing this in a yum-based system or an apt-based one are:

  • for yum: use yumdownloader to get a copy of the .rpm for the package into some convenient scratch directory, then use 'rpm2cpio <whatever>.rpm | cpio -di' to unpack it. Fish out the desired file.

  • for Apt: get the .deb from somewhere (there is probably a magic apt way to do this that's analogous to yumdownloader; I just go to package.ubuntu.com, search around, and follow the links to the binary packages), then use 'dpkg-deb -x <whatever>.deb scratchdir' to unpack it. Fish out the desired file.

As I score this, the two sides come out about equal in the end.

Comments on this page:

From at 2009-08-05 11:43:07:

yum reinstall pkg

By cks at 2009-08-05 12:27:06:

yum reinstall is better than two separate yum commands for this, but it doesn't really solve the problem; first, it reinstalls all of the package, not just one bit, and second it doesn't give me an option of putting the file that I want in some other place, so I can easily compare it with what I currently have.

From at 2009-08-05 14:16:30:

This isn't going to help you much (or anybody else running enterprise server distros), but at least pacman on ArchLinux and paludis on Gentoo (I believe emerge too) offer options to set the root for package installs. So you cam just "reinstall" the package into /tmp for example.

On the other hand those two distributions also live mainly off compressed tarballs which you also can easily extract manually.

From at 2009-08-05 17:28:55:

apt-get install packagename --reinstall will do the equivalent for apt. However, this doesn't solve the problem of only wanting one file.

From at 2009-08-05 17:42:58:

I thought to myself: "This should be pretty easy with a little bit of bash, dpkg, apt and awk"

Five minutes later: http://github.com/agy/get-orig-file/tree/master

The script is horrible (not to mention the name). You've been warned!

From at 2009-08-22 23:14:22:

I had a pretty similar idea to hack one together in bash - http://blog.theinternets.be/2009/08/23/wtf-did-i-change/

Written on 05 August 2009.
« A downside to syndication feed readers respecting permanent HTTP redirects
A rule for Internet software »

Page tools: View Source, View Normal, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Wed Aug 5 02:14:14 2009
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.