| 1 |
#! /bin/bash |
| 2 |
set -e |
| 3 |
|
| 4 |
# debman - read a man page from an uninstalled Debian package file (.deb) |
| 5 |
|
| 6 |
# Copyright (C) 2003 Colin Watson <[email protected]> |
| 7 |
|
| 8 |
# This program is free software; you can redistribute it and/or modify |
| 9 |
# it under the terms of the GNU General Public License as published by |
| 10 |
# the Free Software Foundation; either version 2, or (at your option) |
| 11 |
# any later version. |
| 12 |
|
| 13 |
# This program is distributed in the hope that it will be useful, |
| 14 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
# GNU General Public License for more details. |
| 17 |
|
| 18 |
# You should have received a copy of the GNU General Public License |
| 19 |
# along with this program; if not, write to the Free Software |
| 20 |
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 21 |
# 02111-1307, USA. |
| 22 |
|
| 23 |
usage () { |
| 24 |
if [ "$1" -eq 1 ]; then |
| 25 |
FD=2 |
| 26 |
else |
| 27 |
FD=1 |
| 28 |
fi |
| 29 |
cat >&$FD <<EOF |
| 30 |
Usage: debman [options] [-- man(1) options] <man page name> ... |
| 31 |
|
| 32 |
Options should be exactly one of: |
| 33 |
-f package.deb read pages from package.deb archive |
| 34 |
-p package download .deb for package and read pages |
| 35 |
from there |
| 36 |
EOF |
| 37 |
exit "$1" |
| 38 |
} |
| 39 |
|
| 40 |
ARGS=`getopt -l help,filename:,package: -o hf:p: -n debman -- "$@"` |
| 41 |
eval set -- "$ARGS" |
| 42 |
|
| 43 |
FILENAME= |
| 44 |
PACKAGE= |
| 45 |
|
| 46 |
while :; do |
| 47 |
case "$1" in |
| 48 |
-h|--help) |
| 49 |
usage 0 |
| 50 |
;; |
| 51 |
-f|--filename) |
| 52 |
FILENAME="$2" |
| 53 |
shift 2 |
| 54 |
;; |
| 55 |
-p|--package) |
| 56 |
PACKAGE="$2" |
| 57 |
shift 2 |
| 58 |
;; |
| 59 |
--) |
| 60 |
shift |
| 61 |
break |
| 62 |
;; |
| 63 |
*) |
| 64 |
echo "debman: Internal error in option parsing" >&2 |
| 65 |
exit 1 |
| 66 |
;; |
| 67 |
esac |
| 68 |
done |
| 69 |
|
| 70 |
if ( [ -n "$FILENAME" ] && [ -n "$PACKAGE" ] ) || \ |
| 71 |
( [ -z "$FILENAME" ] && [ -z "$PACKAGE" ] ); then |
| 72 |
usage 1 |
| 73 |
fi |
| 74 |
|
| 75 |
if test $# -lt 1; then |
| 76 |
usage 1 |
| 77 |
fi |
| 78 |
|
| 79 |
# Directory names are duplicated with and without ./ in order to cope with |
| 80 |
# old .debs whose data.tar.gz components had a slightly different format. |
| 81 |
MANDIRS='usr/share/man usr/X11R6/man ./usr/share/man ./usr/X11R6/man' |
| 82 |
|
| 83 |
TEMPDIR=`mktemp -dt debman.XXXXXXXXXX` |
| 84 |
trap 'rm -rf "$TEMPDIR"' EXIT ERR HUP INT QUIT TERM |
| 85 |
|
| 86 |
if [ -n "$PACKAGE" ]; then |
| 87 |
(cd "$TEMPDIR" && debget "$PACKAGE") |
| 88 |
# There should be at most one file in $TEMPDIR now. |
| 89 |
FILENAME="`find \"$TEMPDIR\" -name \*.deb -print`" |
| 90 |
if [ -z "$FILENAME" ]; then |
| 91 |
echo "Failed to fetch package $PACKAGE; exiting." >&2 |
| 92 |
exit 1 |
| 93 |
fi |
| 94 |
fi |
| 95 |
|
| 96 |
# Ignore errors from tar (though not dpkg). They'll generally just be of the |
| 97 |
# form "tar: usr/share/man: Not found in archive". If they're something |
| 98 |
# else, then man will fail to find the page anyway. |
| 99 |
|
| 100 |
dpkg --fsys-tarfile "$FILENAME" | \ |
| 101 |
(tar -C "$TEMPDIR" -xf - $MANDIRS 2>/dev/null || true) |
| 102 |
|
| 103 |
MANPATH="$TEMPDIR/usr/share/man:$TEMPDIR/usr/X11R6/man" man "$@" |
| 104 |
|
| 105 |
# vi: expandtab |