Codebase list debian-goodies / c5da1b5 dglob
c5da1b5

Tree @c5da1b5 (Download .tar.gz)

dglob @c5da1b5raw · history · blame

#!/bin/sh -e

# dglob - Expand package names matching a pattern and conditions

# Copyright (C) 2001 Matt Zimmerman <mdz@debian.org>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
#

ARGS=`getopt -o af0reiXv -n dglob -- "$@"`
eval set -- "$ARGS"


filter="grep-dctrl -FStatus ' installed'"
expand="cat"
grep_dctrl_options=""
all="no"

while true; do
    case "$1" in
        -a) filter="cat" ; all="yes" ; shift ;;
        -0) SEP=0 ; shift ;;
        -r|-e|-i|-X|-v) grep_dctrl_options="$grep_dctrl_options $1"; shift ;;
        -f) expand="xargs dpkg --listfiles | perl -nl${SEP}e 'print if -f'"
            if [ "$all" = "yes" ] ; then
                if [ -n "`which apt-file`" ]   ; then
# if we have apt-file use it instead
                    expand="while read pack; do apt-file show \$pack; done | perl -ple 's/^.*?: //'"
                else
                    echo "WARN: You requested information on files of all packages," >&2
                    echo "WARN: however, since the 'apt-file' package is not available, this" >&2
                    echo "WARN: information can only be provided for those packages currently installed." >&2
                fi
            fi
            shift
            ;;
        
        --) shift ; break ;;
    esac
done

# Does the package exist?
if [ "$all" = "no" ] ; then
    packages=`eval $filter /var/lib/dpkg/status | grep-dctrl -PnsPackage $grep_dctrl_options "$1"`
    if [ -z "$packages" ] ; then
    	exit 1
    fi
    eval $filter /var/lib/dpkg/status | grep-dctrl -PnsPackage $grep_dctrl_options "$1" | grep -v ^$ |
    (eval $expand)
else
    # Use grep-available as the status file does not include all available
    # packages
    grep-aptavail -PnsPackage $grep_dctrl_options "$1" | grep -v ^$ |
    (eval $expand)
fi