diff options
author | Lars Wirzenius <liw@iki.fi> | 2008-05-23 15:10:13 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@iki.fi> | 2008-05-23 15:10:13 +0300 |
commit | 3bd78bf5d56a32c5711dc16c2f7a0ec5e72d924c (patch) | |
tree | 8881f043365ab27c88d4223016da9e1c7bfcb133 /unpack-debian-sources | |
parent | ad8be09cb1a78451b0a6cc78a064c7b9585a3244 (diff) | |
download | extrautils-3bd78bf5d56a32c5711dc16c2f7a0ec5e72d924c.tar.gz |
Added unpack-debian-sources.
Diffstat (limited to 'unpack-debian-sources')
-rwxr-xr-x | unpack-debian-sources | 104 |
1 files changed, 104 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 |