Something
Emporium

Easy Updates with apt-enable

Easy Updates with apt-enable

I find that on Debian and Ubuntu machines, I spend quite a bit of time playing around with my apt sources.list file. When you want to enable multiverse/universe, that's a change. When you install non-standard software from a third-party repository, that's a change. When a repository dies, or gets out of date, and you no longer want to use it, that's a change. And when you want to change which mirror you're using, that's a change.

It's that last one that really irks me. I have a few Ubuntu machines, so I run their apt upgrades through a proxy. Which means I need to keep their respective mirrors synchronised (or the proxy won't do its job; yes, I've tried apt-proxy, that's a story for another time). So, I have my machines set up to use the bog-standard New Zealand mirror. Unfortunately, the New Zealand mirror is often out of date, and quite often completely down. I then need to temporarily change the mirror I'm using, which means breaking out the text editor.

Also, I've found myself needing to apt-get things on campus. And that means a download speed of 7kBps, unless you use the internal university mirror. But the university mirror isn't available off campus, so it's not a long-term option. And 'just' putting the university mirror in sources.list.d/ (which is great, by the way) doesn't work, because the regular entries in sources.list take precedence.

The solution I've found is to split absolutely everything in sources.list into separate sources.list.d/ entries. And then to manage those entries with a couple of (very) simple scripts:

apt-enable:
[email protected]:~$ cat /usr/local/bin/apt-enable
#!/bin/sh
SOURCES=/etc/apt/sources.list.d
sudo mv $SOURCES/$1.list.disabled $SOURCES/$1.list

apt-disable:
[email protected]:~$ cat /usr/local/bin/apt-disable
#!/bin/sh
SOURCES=/etc/apt/sources.list.d
sudo mv $SOURCES/$1.list $SOURCES/$1.list.disabled

That's it. Say I head into uni now. All I have to do to use the uni mirrors is:

[email protected]:~$ sudo apt-disable nz
[email protected]:~$ sudo apt-enable uoa
[email protected]:~$ sudo apt-get update

My sources.list fragments don't go anywhere; they're just renamed to disable them. And I didn't have to touch a text editor, beyond the initial setup.

Now I just need some nice bash autocompletion, and to set things up with whereami.

Dominic