Command Line – Script to Enable ‘Source’ Downloads in a Deterministic Manner

aptcommand linescriptssoftware-sourcesupdates

I wrote a couple of scripts to help users pull their current kernel source package, apply some patches of mine, and build it as a .deb package with make-kpkg. One of the few steps that requires manual intervention is enabling the "Source" downloads via:

  • "Ubuntu Software Center"
    • Edit…
      • Software Sources…
        • "Source Code"

enter image description here

Is there a way to do this automatically via the command line? It's to my understanding I could just un-comment the first few "deb-src" lines in /etc/apt/sources.list, like so:

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://ca.archive.ubuntu.com/ubuntu/ trusty main restricted
deb-src http://ca.archive.ubuntu.com/ubuntu/ trusty main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://ca.archive.ubuntu.com/ubuntu/ trusty-updates main restricted
deb-src http://ca.archive.ubuntu.com/ubuntu/ trusty-updates main restricted

This is somewhat error-prone though, given the sed scripts I've written don't necessarily work if the sources are out of the default order, or various other reasons. More importantly, I'd like this to work on Ubuntu 14.04, Ubuntu 16.04, etc (ie: as generic as possible).

Are there any command-line apt-related tools to accomplish this via a shell script?

Thank you.

Best Answer

In the end, I just enabled all the src repos.

sed -i '/^#\sdeb-src /s/^#//' "/etc/apt/sources.list"

This doesn't require upgrading the OS to an arbitrary version.