How to download the source packages for all installed packages?
772
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.)
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
it is recommended that you only use apt-get source as a regular user, because then you can edit files in the source package without needing root privileges.
There's a couple issues in the accepted answer and with the linked better answer in Unix Stack Exchange. Here's an improved and tested script with comments:
#!/bin/bash
# ${Source} doesn't always show the source package name, ${source:Package} does.
# Multiple packages can have the same source, sort -u eliminates duplicates.
dpkg-query -f '${source:Package}\n' -W | sort -u | while read p; do
mkdir -p $p
pushd $p
# -qq very quiet, pushd provides cleaner progress.
# -d download compressed sources only, do not extract.
apt-get -qq -d source $p
popd
done
Run as non-root user (_apt works). Note any errors as they may indicate packages with no sources available. You may want to run the script with 2>err.log to parse these manually later.
Try this..
Create a directory where you want the source for all installed packages to be downloaded, and enter it.
Create a file named getsource.sh
getsource.sh
Make it executable.
Execute it..
And go grab a cup of coffee :)
An alternative for you might be to just hand out the source CDs:
On Ubuntu refer to command:
it is recommended that you only use
apt-get source
as a regular user, because then you can edit files in the source package without needing root privileges.There's a couple issues in the accepted answer and with the linked better answer in Unix Stack Exchange. Here's an improved and tested script with comments:
Run as non-root user (
_apt
works). Note any errors as they may indicate packages with no sources available. You may want to run the script with2>err.log
to parse these manually later.