summaryrefslogtreecommitdiffstats
path: root/private/refresh-virtual-packages-data
blob: d3013738870608b847c38f78e8aaa6516110a9d9 (plain)
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/sh
# refresh-virtual-packages-data -- Refresh data about font packages in Debian

# Copyright (C) 2008, 2009 Raphael Geissert <atomo64@gmail.com>
# Copyright (C) 2017 Chris Lamb <lamby@debian.org>
#
# This file 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 of the License, or
# (at your option) any later version.
#
# This file 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 file.  If not, see <http://www.gnu.org/licenses/>.

set -e

# Ensure the sort order is stable.
LC_ALL=C; export LC_ALL

if [ -z "$1" ]; then
    printf "Usage: %s <path-to-data> [<packages>]\n" "$(basename "$0")"
    cat <<INFO

If <packages> is specified, it should be the path to the Packages file
from the current unstable distribution.  It will be used to find all
font files already packaged for Debian and update the list of known
font files and the packages that contain them.  <path-to-data> should
be the path to the root of the Lintian data directory to update.

If the Packages file is not specified, the script will download the
following files from a mirror.  The mirror can be specified with the
DEB_MIRROR environment variable.  If it is not set, the default is
http://deb.debian.org/debian.

* main/binary-i386/Packages.gz

Any necessary special parameters for wget can be set via the
environment variable WGET_ARGS.  The default arguments are -nv.

To set additional virtual packages to be added to the list as Keep entries
list them in the VIRTUAL_PACKAGES environment variable.

INFO
    exit
fi

readonly lintian_data="$(readlink -f "$1")"
if [ -n "$2" ] ; then
    packages="$(readlink -f "$2")"
fi

[ -d "$lintian_data" ] || {
    printf "%s is not a directory, aborting" "$lintian_data" >&2
    exit 1
}

readonly workdir="$(mktemp -d)"

cleanup () {
    [ ! -d "$workdir" ] || rm -rf "$workdir"
}; trap cleanup EXIT

mirror="${DEB_MIRROR:=http://deb.debian.org/debian}"
WGET_ARGS="${WGET_ARGS:=-nv}"
wget() {
    echo wget "$mirror"/"$1"
    /usr/bin/wget $WGET_ARGS -O "$workdir/$(basename "$1")" "$mirror"/"$1"
}
mkdir -p "$lintian_data/fields"

cat > "$workdir/virtual-packages" <<EOF
# The list of virtual packages in Debian that are provided by two or more
# packages.
#
# Packages that should be listed but are not found by this script can be
# listed in a special comment in this file.  They will then be preserved when
# the list is regenerated.  Such packages must be listed in a comment line
# staring with "Keep:".  Multiple packages can be specified in the same line,
# separated by comma and/or white space. Multiple "Keep: " lines can be used
# as well.
#
# Last updated: $(date -u +'%Y-%m-%d')

EOF

[ -f "$lintian_data/fields/virtual-packages" ] && {
    grep -E '^#\s*Keep:\s*.+$' "$lintian_data/fields/virtual-packages" \
        >> "$workdir/virtual-packages" || true
}
[ -z "$VIRTUAL_PACKAGES" ] || {
    printf "# Keep: %s\n" "$VIRTUAL_PACKAGES" >> "$workdir/virtual-packages"
}

echo >> "$workdir/virtual-packages"

if [ -z "$packages" ] ; then
    wget dists/sid/main/binary-i386/Packages.gz
    packages="$workdir/Packages.gz"
fi

case "$packages" in
    *.gz)
        CAT=zcat
        ;;
    *)
        CAT=cat
        ;;
esac

# We have to repeat all the Keep packages twice, since we filter out any
# virtual packages that are only used once in the archive.
{ $CAT "$packages"
  sed -rn 's/^#\s*Keep:\s*/Provides: /;T;s/([^,:])\s+([^,])/\1, \2/g;p' \
        "$workdir/virtual-packages"
  sed -rn 's/^#\s*Keep:\s*/Provides: /;T;s/([^,:])\s+([^,])/\1, \2/g;p' \
        "$workdir/virtual-packages"
} |
    perl -w -E 'my (%seen, %pkgs);
                while (<>) {
                    chomp;
                    if (m/^Package:\s*(.+)$/) {
                        $pkgs{$1} = 1;
                        next;
                    }
                    next unless (s/^Provides:\s*//);
                    for my $pkg (split /\s*,\s*/) {
                        $seen{$pkg}++;
                    }
                }
                for my $pkg (keys %seen) {
                    print "$pkg\n"
                        unless ($seen{$pkg} == 1 or exists($pkgs{$pkg}));
                }' \
    | sort -u >> "$workdir/virtual-packages"

mv "$workdir/virtual-packages" "$lintian_data/fields/"


# Local Variables:
# indent-tabs-mode: nil
# End:
# vim: syntax=sh sw=4 sts=4 sr et