manpage_extraction

#!/bin/bash
set -e

DESTDIR="$1"
shift
if [ ! -d "$DESTDIR" ]; then
        echo "Extract documentation to which directory?" >&2
        exit 1
fi

TEMPDIR=`mktemp -d -t doc-XXXXXX`

while [ -f "$1" ];
do
        DEB="$1"
        shift

        echo "Checking $DEB ..."
        dpkg-deb -c "$DEB" | egrep ' \./usr/share/man/man.' >/dev/null || {
                echo "Skipping $DEB (no man pages)"
                continue
        }
        echo "Extracting $DEB ..."
        dpkg-deb -x "$DEB" "$TEMPDIR"
        (cd "$TEMPDIR"/usr/share/man && find . | cpio -pumd "$DESTDIR")
        echo "Cleaning up $DEB ..."
        (cd "$TEMPDIR" && rm -rf *)
done

rm -rf "$TEMPDIR"

This can be used to extract manpages from a Debian file repository. For example:

find /mirrors/ubuntu/pool -name '*_i386.deb' -o -name '*_all.deb' | xargs bin/yank-docs /home/kees/all-man