Thursday, November 20, 2008

Perl to the Rescue Again

Lately I've been having some interesting problems with apt on my Ubuntu installation. I had just finished reinstalling Hardy on my laptop after failing to get wireless working on Gentoo (again). I was attempting to install some of my essential Linux programs like konsole and amarok; however, apt was not properly downloading the files. Whether I was on wireless or plugged into the wall, it would download a couple kb of the .deb file (perhaps a single packet?) and then stall. I tried different times, different servers, different network ports, but nothing worked. Other packages would download fine, but not these. I could kill apt and restart it, and it would then download the next few kb and stall. This is no way to download updates.

Interestingly, I figured out what files it was trying to grab and attempted to fetch them with wget...it worked. Downloading with Firefox? Worked again. For some reason apt was failing to download certain packages from any server. So I wrote a nifty little Perl script that takes a package name as input, queries apt for a list of files to fetch, downloads them with wget (displaying nice progress indicators along the way), places them in the appropriate apt cache location, and then runs apt-get to install the package using the cached files. I later added functionality for other apt commands like update, upgrade, and dist-upgrade, effectively making it a simple apt-get wrapper that bypasses whatever apt uses to download .deb files. Well, it works and it's pretty cool. Perl to the rescue once more. I think it shall never run out of usefulness to me.

1 comment:

John Tibble said...

This is EXACTLY why the people-friendly Ubuntu is not ready for public consumption.