Elric's random thoughts in idle times

"Why stop now, when I'm just starting to hate it?" – Marvin the robot

Posts Tagged ‘scripting

Debian: script to manipulate apt sources quickly from the command line

with 5 comments

I’m one of those who just uses the command line to manage packages, and since I don’t use synaptic, it makes no sense to have the application ‘Software Preferences’ installed, which all in all pulls in a lot of packages.

But sometimes it’s tiresome to open an editor to enable or disable sources, or throw some sed command to change the line, which is anyway some typing. And it’s worse if you want to enable or disable several repositories at once.

So I created a bash script, aptsources (pretty unoriginal), to deal with repositories’ files under the directory ‘/etc/apt/sources.list.d/’. It doesn’t touch the file ‘/etc/apt/sources.list’ file at all, as it’s the file I edit the least. I have most Debian’s distributions entries uncommented (squeeze, sid, etc), with the use of apt-pinning.

The script allows to enable, disable, remove and add files under that directory. It also sets launchpad’s ppa repositories (Note and disclaimer: Ubuntu packages are not binary compatible!) with a syntax similar to add-apt-repository, allowing to set as an argument the Ubuntu version you think your Debian system is closer to. Thanks to Anant Shirvastava, as this function uses the code in his script. It also does backup, shows content, etc…

You can only specify one parameter a time, but some of them (--enable, --disable, --source) accept multiple arguments.

This is:

# aptsources --enable wine zeitgeist

would enable (uncomment) the ‘deb’ lines (not the ‘deb-src’ ones) in the files ‘wine.list’ and ‘zeitgeist.list’ at once.

One handy feature of the script is listing repos grouping them as enabled or disabled.

omar~$ aptsources -l
Enabled: cardapio docky multimedia synapse
Disabled: awn burg codeblocks getdeb hadret mpd-sound-menu notify-osd orta playdeb translate ufw-gtk vineyard wine zeitgeist

The script doesn’t run “exotic” commands, and it’s very easy to read. I stopped posting it here cause it got too big. You can download it from github. Click on the “Download” button and you will get a compressed archive with the latest version. You can install the script to ‘/usr/local/bin’ and bash-completion feature with aptsources.sh -i. I still enhance with small things so you better come back once or twice :)

Play with it and I hope it’s useful for more people than just me.

Enjoy!

Written by elric80

January 8, 2011 at 6:46 pm

Posted in debian, linux

Tagged with , , , , , ,