blob: c30baf31b4187d8e86597286645a1ecf4171fdcd [file] [log] [blame]
Eric Andersen4bfb6b72000-11-29 21:39:02 +00001#!/bin/sh
2#
Eric Andersen5ec241d2000-12-12 16:49:12 +00003# This should work with the GNU version of tar and gzip!
4# This should work with the bash or ash shell!
5# Requires the programs (ar, tar, gzip, and the pager more or less).
6#
Eric Andersen4bfb6b72000-11-29 21:39:02 +00007usage() {
Mike Frysingeree22fe82016-04-04 01:35:34 -04008 cat <<EOF
9Usage: undeb -c package.deb <Print control file info>
10 undeb -l package.deb <List contents of deb package>
11 undeb -x package.deb /foo/boo <Extract deb package to this directory,
12 put . for current directory>
13EOF
14 exit
Eric Andersen4bfb6b72000-11-29 21:39:02 +000015}
16
17deb=$2
Eric Andersenc7bda1c2004-03-15 08:29:22 +000018
Eric Andersen4bfb6b72000-11-29 21:39:02 +000019exist() {
Mike Frysingeree22fe82016-04-04 01:35:34 -040020 if [ -z "${deb}" ]; then
21 usage
22 elif [ ! -s "${deb}" ]; then
23 echo "Can't find ${deb}!"
24 exit 1
25 fi
Eric Andersen4bfb6b72000-11-29 21:39:02 +000026}
27
Mike Frysingeree22fe82016-04-04 01:35:34 -040028if [ -z "$1" ]; then
29 usage
Eric Andersen4bfb6b72000-11-29 21:39:02 +000030elif [ "$1" = "-l" ]; then
Mike Frysingeree22fe82016-04-04 01:35:34 -040031 exist
32 type more >/dev/null 2>&1 && pager=more
33 type less >/dev/null 2>&1 && pager=less
34 [ -z "${pager}" ] && echo "No pager found!" && exit 1
35 (
36 ar -p "${deb}" control.tar.gz | tar -xzO *control
37 printf "\nPress enter to scroll, q to Quit!\n\n"
38 ar -p "${deb}" data.tar.gz | tar -tzv
39 ) | ${pager}
40 exit
Eric Andersen4bfb6b72000-11-29 21:39:02 +000041elif [ "$1" = "-c" ]; then
Mike Frysingeree22fe82016-04-04 01:35:34 -040042 exist
43 ar -p "${deb}" control.tar.gz | tar -xzO *control
44 exit
Eric Andersen4bfb6b72000-11-29 21:39:02 +000045elif [ "$1" = "-x" ]; then
Mike Frysingeree22fe82016-04-04 01:35:34 -040046 exist
47 if [ -z "$3" ]; then
48 usage
49 elif [ ! -d "$3" ]; then
50 echo "No such directory $3!"
51 exit 1
52 fi
53 ar -p "${deb}" data.tar.gz | tar -xzvpf - -C "$3" || exit
54 echo
55 echo "Extracted ${deb} to $3!"
56 exit
Eric Andersen4bfb6b72000-11-29 21:39:02 +000057else
Mike Frysingeree22fe82016-04-04 01:35:34 -040058 usage
Eric Andersen4bfb6b72000-11-29 21:39:02 +000059fi