Elric's random thoughts in idle times

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

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.


Written by elric80

January 8, 2011 at 6:46 pm

Posted in debian, linux

Tagged with , , , , , ,

5 Responses

Subscribe to comments with RSS.

  1. linux is for fascists and pederasts!!!
    fucking nerds sucks!!!


    January 10, 2011 at 12:20 am

  2. First of all Thanks for the credit link.

    I am excited in using your script and happy that my code served your purpose.

    Anant Shrivastava

    January 10, 2011 at 8:11 am

    • Thanks for your comment Anant, and I’m glad you find it useful :)


      January 10, 2011 at 4:32 pm

  3. Excelente ;-)

    Un saludo.


    January 11, 2011 at 8:29 pm

    • Gracias :) Además de otras cosas, acabo de añadir un fichero para bash_completion, que agiliza bastante las cosas.
      Si tienes alguna idea, escríbela aquí :)


      January 20, 2011 at 12:40 am

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: