| 1 |
#!/bin/sh |
| 2 |
set -e |
| 3 |
|
| 4 |
# dglob - Expand package names matching a pattern and conditions |
| 5 |
|
| 6 |
# Copyright (C) 2001 Matt Zimmerman <[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 |
|
| 24 |
ARGS=$(getopt -o af0reinXvA -n dglob -- "$@") |
| 25 |
eval set -- "$ARGS" |
| 26 |
|
| 27 |
|
| 28 |
filter="grep-dctrl -FStatus installed" |
| 29 |
archfilter="cat" |
| 30 |
expand="cat" |
| 31 |
grep_dctrl_options="" |
| 32 |
all="no" |
| 33 |
|
| 34 |
dglob_not() { |
| 35 |
# List packages that are available but not installed |
| 36 |
{ dglob $* ; dglob -a $* ; } | sort | uniq -u ; |
| 37 |
} |
| 38 |
|
| 39 |
while true; do |
| 40 |
case "$1" in |
| 41 |
-n) shift; ARGS=$(echo $@ | sed -e 's/--/ /'); dglob_not $ARGS; exit 0;; |
| 42 |
-a) filter="cat" ; all="yes" ; shift ;; |
| 43 |
-0) SEP=0 ; shift ;; |
| 44 |
-r|-e|-i|-X|-v) grep_dctrl_options="$grep_dctrl_options $1"; shift ;; |
| 45 |
-A) expand="awk -F: '{print \$1}'"; shift ;; |
| 46 |
-f) expand="xargs dpkg --listfiles | perl -nl${SEP}e 'print if -f'" |
| 47 |
if [ "$all" = "yes" ] ; then |
| 48 |
if [ -n "$(which apt-file)" ] ; then |
| 49 |
# if we have apt-file use it instead |
| 50 |
expand="while read pack; do apt-file show \$pack; done | perl -ple 's/^.*?: //'" |
| 51 |
else |
| 52 |
echo "WARN: You requested information on files of all packages," >&2 |
| 53 |
echo "WARN: however, since the 'apt-file' package is not available, this" >&2 |
| 54 |
echo "WARN: information can only be provided for those packages currently installed." >&2 |
| 55 |
fi |
| 56 |
fi |
| 57 |
shift |
| 58 |
;; |
| 59 |
|
| 60 |
--) shift ; break ;; |
| 61 |
esac |
| 62 |
done |
| 63 |
|
| 64 |
pattern="$1" |
| 65 |
if echo "$pattern" | grep -Fq ":"; then |
| 66 |
package=$(echo "$pattern" | awk -F: '{print $1}') |
| 67 |
arch=$(echo "$pattern" | awk -F: '{print $2}') |
| 68 |
archfilter="grep-dctrl -FArchitecture $arch" |
| 69 |
if [ -z "$arch" ]; then |
| 70 |
echo "Empty architecture (but colon) not allowed" 1>&2 |
| 71 |
exit 2 |
| 72 |
fi |
| 73 |
else |
| 74 |
package="$pattern" |
| 75 |
fi |
| 76 |
|
| 77 |
|
| 78 |
packages=$( |
| 79 |
if [ "$all" = "no" ] ; then |
| 80 |
$filter /var/lib/dpkg/status |
| 81 |
else |
| 82 |
# Use grep-available as the status file does not include all available |
| 83 |
# packages |
| 84 |
apt-cache dumpavail |
| 85 |
fi | \ |
| 86 |
$archfilter | \ |
| 87 |
grep-dctrl -PnsPackage,Architecture $grep_dctrl_options "$package" | \ |
| 88 |
sed -ze 's/\n/:/g;s/::/\n/g' | \ |
| 89 |
grep -v ^$ |
| 90 |
) |
| 91 |
|
| 92 |
# Does a package exist which matches the query? |
| 93 |
if [ -z "$packages" ] ; then |
| 94 |
exit 1 |
| 95 |
fi |
| 96 |
|
| 97 |
echo "$packages" | (eval $expand) |