3 # debman - read a man page from an uninstalled Debian package file (.deb)
5 # Copyright (C) 2003 Colin Watson <cjwatson@debian.org>
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
23 if [ "$1" -eq 1 ]; then
29 Usage: debman [options] [-- man(1) options] <man page name> ...
31 Options should be exactly one of:
32 -f package.deb read pages from package.deb archive
33 -p package download .deb for package and read pages
39 ARGS=`getopt -l help,filename:,package: -o hf:p: -n debman -- "$@"`
63 echo "debman: Internal error in option parsing" >&2
69 if ( [ -n "$FILENAME" ] && [ -n "$PACKAGE" ] ) || \
70 ( [ -z "$FILENAME" ] && [ -z "$PACKAGE" ] ); then
74 if test $# -lt 1; then
78 # Directory names are duplicated with and without ./ in order to cope with
79 # old .debs whose data.tar.gz components had a slightly different format.
80 MANDIRS='usr/share/man usr/X11R6/man ./usr/share/man ./usr/X11R6/man'
82 TEMPDIR=`mktemp -dt debman.XXXXXXXXXX`
83 trap 'rm -rf "$TEMPDIR"' EXIT ERR HUP INT QUIT TERM
85 if [ -n "$PACKAGE" ]; then
86 (cd "$TEMPDIR" && debget "$PACKAGE")
87 # There should be at most one file in $TEMPDIR now.
88 FILENAME="`find \"$TEMPDIR\" -name \*.deb -print`"
89 if [ -z "$FILENAME" ]; then
90 echo "Failed to fetch package $PACKAGE; exiting." >&2
95 # Ignore errors from tar (though not dpkg). They'll generally just be of the
96 # form "tar: usr/share/man: Not found in archive". If they're something
97 # else, then man will fail to find the page anyway.
99 dpkg --fsys-tarfile "$FILENAME" | \
100 (tar -C "$TEMPDIR" -xf - $MANDIRS 2>/dev/null || true)
102 MANPATH="$TEMPDIR/usr/share/man:$TEMPDIR/usr/X11R6/man" man "$@"