File: dglob

package info (click to toggle)
debian-goodies 0.84
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 376 kB
  • sloc: sh: 875; python: 769; perl: 565; makefile: 14
file content (97 lines) | stat: -rwxr-xr-x 3,059 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/bin/sh
set -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 af0reinXvA -n dglob -- "$@")
eval set -- "$ARGS"


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

dglob_not() {
# List packages that are available but not installed
    { dglob $* ; dglob -a $* ; } | sort | uniq -u ;
}

while true; do
    case "$1" in
        -n) shift; ARGS=$(echo $@ | sed -e 's/--/ /'); dglob_not $ARGS; exit 0;;
        -a) filter="cat" ; all="yes" ; shift ;;
        -0) SEP=0 ; shift ;;
        -r|-e|-i|-X|-v) grep_dctrl_options="$grep_dctrl_options $1"; shift ;;
        -A) expand="awk -F: '{print \$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

pattern="$1"
if echo "$pattern" | fgrep -q ":"; then
    package=$(echo "$pattern" | awk -F: '{print $1}')
    arch=$(echo "$pattern" | awk -F: '{print $2}')
    archfilter="grep-dctrl -FArchitecture $arch"
    if [ -z "$arch" ]; then
        echo "Empty architecture (but colon) not allowed" 1>&2
        exit 2
    fi
else
    package="$pattern"
fi


packages=$(
    if [ "$all" = "no" ] ; then
        $filter /var/lib/dpkg/status
    else
        # Use grep-available as the status file does not include all available
        # packages
        apt-cache dumpavail
    fi | \
        $archfilter | \
        grep-dctrl -PnsPackage,Architecture $grep_dctrl_options "$package" | \
        sed -ze 's/\n/:/g;s/::/\n/g' | \
        grep -v ^$
        )

# Does a package exist which matches the query?
if [ -z "$packages" ] ; then
    exit 1
fi

echo "$packages" | (eval $expand)