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.

share|improve this question
1  
There have been plenty of scripts done on this post : askubuntu.com/q/700860/295286 Let me know of any of those work for you – Sergiy Kolodyazhnyy May 7 '16 at 22:35
up vote 2 down vote accepted

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.

share|improve this answer

I had a similar problem as you had and finaly I started doing the following script, to write a temporary sources.list and later removing it again:

# making a copy of the users original sources.list file
cp -v /etc/apt/sources.list /etc/apt/sources.list.orig &&

# writing a custom sources.list file
cat > /etc/apt/sources.list << "EOF"
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted
deb http://archive.ubuntu.com/ubuntu/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu/ xenial multiverse main universe restricted
deb http://archive.ubuntu.com/ubuntu/ xenial-updates main restricted
deb-src http://archive.ubuntu.com/ubuntu/ xenial-updates multiverse main universe restricted
deb http://archive.ubuntu.com/ubuntu/ xenial universe
deb http://archive.ubuntu.com/ubuntu/ xenial-updates universe
deb http://archive.ubuntu.com/ubuntu/ xenial multiverse
deb http://archive.ubuntu.com/ubuntu/ xenial-updates multiverse
deb http://archive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://dearchive.ubuntu.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://security.ubuntu.com/ubuntu xenial-security main restricted
deb-src http://security.ubuntu.com/ubuntu xenial-security multiverse main universe restricted
deb http://security.ubuntu.com/ubuntu xenial-security universe
deb http://security.ubuntu.com/ubuntu xenial-security multiverse
EOF

# running an update
apt-get update &&
apt-get -y dist-upgrade &&

# DO YOUR STUFF

# putting back the original sources.list
mv -v /etc/apt/sources.list /etc/apt/sources.list.tmp &&
cp -v /etc/apt/sources.list.orig /etc/apt/sources.list &&

# removing backup files
rm -rfv /etc/apt/sources.list.tmp &&
rm -rfv /etc/apt/sources.list.orig
share|improve this answer
    
What if I'm not on Xenial, but on Trusty/(Wily, Vivid, etc), or Precise? – DevNull May 8 '16 at 3:01
    
Well take your source file remove the lines with a # in front and replace the ones in my answer with them. – Videonauth May 8 '16 at 3:02
    
I could run a sed/bash regex easily enough to remove all leading # characters, but should I necessarily do that? Some of those sources in the list file enable sources that are either unsupported or bring licensing concerns into the fray. An enable-all approach seems a big hammer to throw at the problem. – DevNull May 8 '16 at 3:05
    
Youre aware of the last step i have in my script approach? i remove my temporary sources.list and copy back the one the user had. – Videonauth May 8 '16 at 3:08
    
Yes. You're upgrading to the latest release, when all I want is to enable the repo for source for the latest release currently installed on the system. – DevNull May 8 '16 at 3:16

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.