summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xunpack-debian-sources104
-rw-r--r--unpack-debian-sources.161
2 files changed, 165 insertions, 0 deletions
diff --git a/unpack-debian-sources b/unpack-debian-sources
new file mode 100755
index 0000000..abd27a9
--- /dev/null
+++ b/unpack-debian-sources
@@ -0,0 +1,104 @@
+#!/bin/sh
+#
+# unpack-debian-sources - unpack all Debian packages in a Debian
+# repository
+#
+# Usage: unpack-debian-sources MIRROR SUITE [SECTION]...
+#
+# where MIRROR is the URL to a Debian mirror site, SUITE is the release,
+# and SECTION is a section within the release. For example:
+#
+# unpacke-debian-sources http://ftp.debian.org/debian etch main contrib
+#
+# If SECTION is missing, it defaults to "main contrib non-free"
+
+set -e
+
+die()
+{
+ echo "$@" 1>&2
+ exit 1
+}
+
+fetch()
+{
+ wget -q -O - "$1"
+}
+
+parse_sources()
+{
+ awk '
+ /^Directory:/ {
+ if (dir && paths) print dir, paths
+ dir = $2
+ paths = ""
+ }
+ /^Files:/ { infiles = 1; next }
+ infiles && /^ / { paths = paths " " $NF }
+ infiles && (NF == 0 || /^[^ ]/) { infiles = 0 }
+ '
+}
+
+showiferror()
+{
+ local temp="$(mktemp)"
+ if ! "$@" > "$temp" 2>&1
+ then
+ cat "$temp"
+ rm -f "$temp"
+ exit 1
+ fi
+ rm -f "$temp"
+}
+
+unpack_dsc()
+{
+ (
+ cd "$1"
+ dsc="$(ls *.dsc)"
+ showiferror dpkg-source -x *.dsc
+ )
+}
+
+[ "$2" = "" ] && die "Usage: $0 MIRROR SUITE [SECTION]..."
+
+mirror="$1"
+suite="$2"
+shift 2
+sections="$@"
+
+gpghome="$(mktemp -d)"
+export GNUPGHOME="$gpghome"
+
+for section in $sections
+do
+ sources="$mirror/dists/$suite/$section/source/Sources.bz2"
+ sources_tmp="$(mktemp)"
+ fetch "$sources" | bunzip2 > "$sources_tmp"
+
+ num_packages=$(parse_sources < "$sources_tmp" | wc -l)
+
+ n=0
+ parse_sources < "$sources_tmp" |
+ while read dir paths
+ do
+ n=$(expr $n + 1)
+ if [ ! -d "$dir" ]
+ then
+ printf "$n/$num_packages: $dir\n"
+ temp="$(mktemp -d)"
+ for path in $paths
+ do
+ fetch "$mirror/$dir/$path" > "$temp/$path"
+ done
+ unpack_dsc "$temp"
+ for path in $paths
+ do
+ rm "$temp/$path"
+ done
+ mkdir -p "$dir" # Create parent dirs
+ rmdir "$dir" # Remove tail dir
+ mv "$temp"/* "$dir" # Move the _single_ dir, which has the src
+ fi
+ done
+done
diff --git a/unpack-debian-sources.1 b/unpack-debian-sources.1
new file mode 100644
index 0000000..87aa3bd
--- /dev/null
+++ b/unpack-debian-sources.1
@@ -0,0 +1,61 @@
+.\" unpack-debian-sources.1 - manual page for unpack-debian-sources
+.\" Copyright (C) 2008 Lars Wirzenius
+.\"
+.\" This program is free software: you can redistribute it and/or modify
+.\" it under the terms of the GNU General Public License as published by
+.\" the Free Software Foundation, either version 3 of the License, or
+.\" (at your option) any later version.
+.\"
+.\" This program is distributed in the hope that it will be useful,
+.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
+.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+.\" GNU General Public License for more details.
+.\"
+.\" You should have received a copy of the GNU General Public License
+.\" along with this program. If not, see <http://www.gnu.org/licenses/>.
+.\"
+.TH UNPACK-DEBIAN-SOURCES 1
+.SH NAME
+unpack-debian-sources \- unpack Debian source packages in a repository
+.SH SYNOPSIS
+.B unpack-debian-sources
+.I mirror
+.I release
+.RI [ component ...]
+.SH DESCRIPTION
+.B unpack-debian-sources
+finds all Debian source packages in an apt repository, downloads them,
+and unpacks them.
+.PP
+The
+.I mirror
+argument is an http url to the mirror.
+For example,
+.IR http://www.debian.org/debian .
+.PP
+The
+.I release
+argument specifies the release to download,
+such as
+.IR etch ,
+or
+.IR intrepid .
+.PP
+The optional
+.I component
+arguments specify the components within a release,
+such as
+.IR main ,
+or
+.IR contrib .
+If you don't specify any componentes, the default list of
+.I "main contrib non-free"
+is used.
+.PP
+The result of
+.B unpack-debian-sources
+is a directory tree mimicking the apt archive.
+If a source package is in the apt archive at
+.I pool/main/f/foo/foobar_1.2-3.dsc
+the unpacked source package is at
+.IR pool/main/f/foo .