chiark / gitweb /
debman: Require '-f package.deb' to read a local .deb. Implement '-p
authorColin Watson <cjwatson@chiark.greenend.org.uk>
Mon, 6 Jan 2003 04:42:08 +0000 (04:42 +0000)
committerColin Watson <cjwatson@chiark.greenend.org.uk>
Mon, 6 Jan 2003 04:42:08 +0000 (04:42 +0000)
package' to download the named package and read from it. The idea for the
latter came from David B. Harris.

debman

diff --git a/debman b/debman
index 25a5f1ac44fcf091d0dcf531b2c14a0cc6075109..76c0b35593dd2780000f2a5959e2270bf817940d 100755 (executable)
--- a/debman
+++ b/debman
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 # 02111-1307, USA.
 
 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 # 02111-1307, USA.
 
-USAGE='Usage: debman <package.deb> [man options] <man page name> ...'
-
-case "$1" in
-    -h|--help)
-        echo "$USAGE"
-        exit 0
-        ;;
-esac
-
-if test $# -lt 2; then
-    echo "$USAGE" >&2
-    exit 1
+usage () {
+    if [ "$1" -eq 1 ]; then
+        FD=2
+    else
+        FD=1
+    fi
+    cat >&$FD <<EOF
+Usage: debman [options] [-- man options] <man page name> ...
+
+Options should be exactly one of:
+        -f package.deb          read pages from package.deb archive
+        -p package              download .deb for package and read pages
+                                from there
+EOF
+    exit "$1"
+}
+
+ARGS=`getopt -l help,filename:,package: -o hf:p: -n debman -- "$@"`
+eval set -- "$ARGS"
+
+FILENAME=
+PACKAGE=
+
+while :; do
+    case "$1" in
+        -h|--help)
+            usage 0
+            ;;
+        -f|--filename)
+            FILENAME="$2"
+            shift 2
+            ;;
+        -p|--package)
+            PACKAGE="$2"
+            shift 2
+            ;;
+        --)
+            shift
+            break
+            ;;
+        *)
+            echo "debman: Internal error in option parsing" >&2
+            exit 1
+            ;;
+    esac
+done
+
+if ( [ -n "$FILENAME" ] && [ -n "$PACKAGE" ] ) || \
+   ( [ -z "$FILENAME" ] && [ -z "$PACKAGE" ] ); then
+    usage 1
 fi
 fi
-    
+
+if test $# -lt 1; then
+    usage 1
+fi
+
 # Directory names are duplicated with and without ./ in order to cope with
 # old .debs whose data.tar.gz components had a slightly different format.
 MANDIRS='usr/share/man usr/X11R6/man ./usr/share/man ./usr/X11R6/man'
 # Directory names are duplicated with and without ./ in order to cope with
 # old .debs whose data.tar.gz components had a slightly different format.
 MANDIRS='usr/share/man usr/X11R6/man ./usr/share/man ./usr/X11R6/man'
@@ -40,13 +82,21 @@ MANDIRS='usr/share/man usr/X11R6/man ./usr/share/man ./usr/X11R6/man'
 TEMPDIR=`mktemp -dt debman.XXXXXXXXXX`
 trap 'rm -rf "$TEMPDIR"' EXIT ERR HUP INT QUIT TERM
 
 TEMPDIR=`mktemp -dt debman.XXXXXXXXXX`
 trap 'rm -rf "$TEMPDIR"' EXIT ERR HUP INT QUIT TERM
 
+if [ -n "$PACKAGE" ]; then
+    # This duplicates debget; if an option is added there to use an
+    # externally-specified filename then we can use it instead.
+    FILENAME="$TEMPDIR/$PACKAGE.deb"
+    wget -O "$FILENAME" \
+        $(apt-get -q2 --print-uris --reinstall install "$PACKAGE" | \
+          sed -ne "\$s/^'\([^']*\)'.*$/\1/p")
+fi
+
 # Ignore errors from tar (though not dpkg). They'll generally just be of the
 # form "tar: usr/share/man: Not found in archive". If they're something
 # else, then man will fail to find the page anyway.
 
 # Ignore errors from tar (though not dpkg). They'll generally just be of the
 # form "tar: usr/share/man: Not found in archive". If they're something
 # else, then man will fail to find the page anyway.
 
-dpkg --fsys-tarfile "$1" | \
+dpkg --fsys-tarfile "$FILENAME" | \
     (tar -C "$TEMPDIR" -xf - $MANDIRS 2>/dev/null || true)
     (tar -C "$TEMPDIR" -xf - $MANDIRS 2>/dev/null || true)
-shift
 
 MANPATH="$TEMPDIR/usr/share/man:$TEMPDIR/usr/X11R6/man" man "$@"
 
 
 MANPATH="$TEMPDIR/usr/share/man:$TEMPDIR/usr/X11R6/man" man "$@"