This file is indexed.

/usr/bin/debtags-hardware is in debtags 2.0.1ubuntu6.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

  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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#!/usr/bin/python3

# debtags-hardware: detect what hardware tags apply to the current system
#
# Copyright (C) 2012  Enrico Zini <enrico@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 of the License, 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

import pwd
import os
import sys
import hashlib
import urllib
import urllib2
import json
import logging

log = logging.getLogger(sys.argv[0])

def list_packages(opts):
    from debtagshw import debtagshw
    hw = debtagshw.DebtagsAvailableHW()

    from debian import debtags
    import apt
    cache = apt.Cache()

    db = debtags.DB()
    with open("/var/lib/debtags/package-tags", "r") as fd:
        db.read(fd)

    for status, tags in hw.generate_tag_expressions():
        if opts.incompatible:
            if status != debtagshw.HardwareSupported.NO: continue
        else:
            if status != debtagshw.HardwareSupported.YES: continue
        pkgsets = [db.packages_of_tag(t) for t in tags]
        res = set(pkgsets[0])
        for s in pkgsets[1:]:
            res &= s
        if not res: continue
        print "#"
        print "# Packages for %s:" % ",".join(sorted(tags))
        print "#"
        for pkg in sorted(res):
            try:
                # FIXME: I wish I had cache.get(pkg, None)
                p = cache[pkg]
            except KeyError:
                continue
            if opts.installed and not p.is_installed: continue
            if opts.uninstalled and p.is_installed: continue
            ver = p.candidate
            print p.name, "-", ver.summary

def pkgreport(opts):
    from debtagshw import debtagshw
    hw = debtagshw.DebtagsAvailableHW()

    from debian import debtags
    import apt
    cache = apt.Cache()

    db = debtags.DB()
    with open("/var/lib/debtags/package-tags", "r") as fd:
        db.read(fd)

    class Pkginfo(object):
        def __init__(self, name):
            self.pkg = cache[name]
            self.rules = []

    pkgs = dict()
    seen_tags = set()

    for status, tags in hw.generate_tag_expressions():
        seen_tags.update(tags)
        pkgsets = [db.packages_of_tag(t) for t in tags]
        res = set(pkgsets[0])
        for s in pkgsets[1:]:
            res &= s
        if not res: continue
        for name in res:
            info = pkgs.get(name, None)
            if info is None:
                try:
                    info = Pkginfo(name)
                except KeyError:
                    continue
                pkgs[name] = info
            info.rules.append((status, tags))

    for name, info in sorted(pkgs.iteritems()):
        print info.pkg.name, "-", info.pkg.candidate.summary
        print " ", ", ".join(sorted(t for t in db.tags_of_package(name) if t in seen_tags))
        # Use the following line instead if you want to see all tags of package
        # print " ", ", ".join(sorted(db.tags_of_package(name)))
        for status, tags in info.rules:
            print " ", status, ", ".join(sorted(tags))
        print

if __name__ == "__main__":
    from optparse import OptionParser
    import sys

    VERSION="1.8"

    class Parser(OptionParser):
        def error(self, msg):
            sys.stderr.write("%s: error: %s\n\n" % (self.get_prog_name(), msg))
            self.print_help(sys.stderr)
            sys.exit(2)

    parser = Parser(usage="usage: %prog [options]",
                    version="%prog "+ VERSION,
                    description="Detects what tag combinations make sense for the current system.")
    parser.add_option("-q", "--quiet", action="store_true",
                      help="quiet mode: only output errors.")
    parser.add_option("-v", "--verbose", action="store_true",
                      help="verbose mode: output progress and non-essential information.")
    parser.add_option("-d", "--debug", action="store_true",
                      help="debug mode: output debug informationn.")
    parser.add_option("--packages", action="store_true",
                      help="show packages for all tags found.")
    parser.add_option("--incompatible", action="store_true",
                      help="show packages that would not work instead of those that would work.")
    parser.add_option("--installed", action="store_true",
                      help="show only installed packages.")
    parser.add_option("--uninstalled", action="store_true",
                      help="show only uninstalled packages.")
    parser.add_option("--pkgreport", action="store_true",
                      help="show a details reports of what packages match what rules and why.")
    (opts, args) = parser.parse_args()

    #FORMAT = "%(asctime)-15s %(levelname)s %(message)s"
    FORMAT = "%(message)s"
    if opts.quiet:
        logging.basicConfig(level=logging.ERROR, stream=sys.stderr, format=FORMAT)
    elif not opts.verbose:
        logging.basicConfig(level=logging.WARNING, stream=sys.stderr, format=FORMAT)
    elif opts.debug:
        logging.basicConfig(level=logging.DEBUG, stream=sys.stderr, format=FORMAT)       
    else:
        logging.basicConfig(level=logging.INFO, stream=sys.stderr, format=FORMAT)

    if opts.packages:
        list_packages(opts)
    elif opts.pkgreport:
        pkgreport(opts)
    else:
        from debtagshw import debtagshw
        hw = debtagshw.DebtagsAvailableHW()

        for status, tag in hw.generate_tag_expressions():
            print status, tag