chiark / gitweb /
debman: New script to read man pages straight out of .debs.
[bin.git] / debman
1 #! /bin/sh -e
2
3 # debman - read a man page from an uninstalled Debian package file (.deb)
4
5 # Copyright (C) 2003 Colin Watson <cjwatson@debian.org>
6
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)
10 # any later version.
11
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.
16
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
20 # 02111-1307, USA.
21
22 USAGE='Usage: debman <package.deb> [man options] <man page name> ...'
23
24 case "$1" in
25     -h|--help)
26         echo "$USAGE"
27         exit 0
28         ;;
29 esac
30
31 if test $# -lt 2; then
32     echo "$USAGE" >&2
33     exit 1
34 fi
35     
36 # Directory names are duplicated with and without ./ in order to cope with
37 # old .debs whose data.tar.gz components had a slightly different format.
38 MANDIRS='usr/share/man usr/X11R6/man ./usr/share/man ./usr/X11R6/man'
39
40 TEMPDIR=`mktemp -dt debman.XXXXXXXXXX`
41 trap 'rm -rf "$TEMPDIR"' EXIT ERR HUP INT QUIT TERM
42
43 # Ignore errors from tar (though not dpkg). They'll generally just be of the
44 # form "tar: usr/share/man: Not found in archive". If they're something
45 # else, then man will fail to find the page anyway.
46
47 dpkg --fsys-tarfile "$1" | \
48     (tar -C "$TEMPDIR" -xf - $MANDIRS 2>/dev/null || true)
49 shift
50
51 MANPATH="$TEMPDIR/usr/share/man:$TEMPDIR/usr/X11R6/man" man "$@"
52
53 # vi: expandtab