How to download the source packages for all installed packages?

What apt incantations do I need to use to download the source packages for all the installed packages into a directory? (The use case is GPL compliance when giving an installed Ubuntu system to another person along with a computer.)


Solution 1:

Try this..

Create a directory where you want the source for all installed packages to be downloaded, and enter it.

mkdir source; cd source

Create a file named getsource.sh

getsource.sh

#!/bin/bash
dpkg --get-selections | while read line
do
        package=`echo $line | awk '{print $1}'`
        mkdir $package
        cd $package
        apt-get -q source $package
        cd ..
done

Make it executable.

chmod a+x getsource.sh

Execute it..

./getsource.sh

And go grab a cup of coffee :)

Solution 2:

An alternative for you might be to just hand out the source CDs:

  • http://cdimage.ubuntu.com/releases/11.10/release/source/