Thursday 22 February 2007

Useful and unknown feature of apt

Note: this feature was at least unknown to me.

If you have a local mirror and one which is further, you will most surely have the local mirror listed first in your /etc/apt/sources.list so that apt tries to download first from the local mirror. Nothing new here.

Add a laptop to that mix and moving frequently to another place, let's say office at work, where the link to the second mirror is waaay faster than the one to your home local mirror.

How do you make updates/installations via the most speedy connection, no matter if you are at work or near the local mirror at home?

Simple (if you count simple something I had to figure out in 1 months or so - to quote partially aj :-); apt will use that mirror if you comment out the lines that point to your local mirror and will use those without the need to run update.

Are you getting my drift? So, how does that add up? Throw in there laptop-net and its feature to replace files depending on profile and you got it all almost sorted out (you'll have to make a restore feature based on the ${PROFILE}/before-deselect hook).

So, to conclude, here are the instructions:
  • install laptop-net
  • create a profile for the local mirror connections (there is a skeleton example in /etc/laptop-net/profiles/_skel with some examples and pointers, please read the README, at least) that is meant for the place where you have the local mirror
  • create the files.d directory in the new profile and add there etc/apt/sources.list (with the intermediate directories) the variant that has the local mirror specification uncommented
  • modify ${PROFILE}/before-deselect hook script to replace the sources.list file with one that does have the local mirror lines commented (I created a files-back.d/ directory whose contents is copied over the / directory, exactly like laptop-net does itself for files.d/; that is not actually a backup, but is good enough)
Now you should be able to always install from the fastest mirror at all times.

No comments: